Infrared Record And Playback With Puck.js

Made by Espruino

About the project

This video shows you how to control Infrared devices using Puck.js.

Project info

Difficulty:

Categories:

Sensors

Platforms:

Espruino

Estimated time:

3 hours

Published:

16th April 2018

Items used in this project


Hardware components

Infrared Remote Control Receiver Module

http://www.espruino.com/IRReceiver

x 1

Software app and online services

Puck.js

http://www.espruino.com/Puck.js

Story



Recording

The code used in the video is:

  1. digitalWrite(D2,0);
  2. pinMode(D1,"input_pullup");
  3. var d = [];
  4. setWatch(function(e) {
  5. d.push(1000*(e.time-e.lastTime));
  6. }, D1, {edge:"both",repeat:true});

You can use the following to output the contents of the d array rounded to 1 decimal place (which is much more readable):

  1. console.log(d.map(a=>a.toFixed(1)).toString())

In fact adding the following code will automatically print the received Infrared code as soon as you have sent it:

  1. var lastLen = 0;
  2. setInterval(function() {
  3. if (d.length && d.length==lastLen) {
  4. d.shift(); // remove first element
  5. console.log(d.map(a=>a.toFixed(1)).toString());
  6. d=[];
  7. }
  8. lastLen = d.length;
  9. },200);

For the particular light bulb used in the video, the codes are as follows:


  1. var commands = {
  2. off:[8.9,4.5,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,1.7,0.5,1.8,0.5,1.7,0.5,1.7,0.5,1.8,0.5,1.7,0.5,1.7,0.5,1.8,0.5,0.6,0.5,1.7,0.5,1.7,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,1.7,0.5,0.6,0.5,0.6,0.5,1.8,0.5,1.7,0.5,1.7,0.5,1.8,0.5,1.7,0.5,39.9,8.9,2.3,0.5,96.2,8.9,2.3,0],
  3. on:[8.9,4.5,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,1.7,0.5,1.8,0.5,1.7,0.5,1.7,0.5,1.7,0.5,1.7,0.5,1.7,0.5,1.8,0.5,1.7,0.5,1.7,0.5,1.7,0.5,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.4,1.8,0.5,1.7,0.5,1.7,0.5,1.8,0.5,1.7,0.5,1.7,0.5,1.8,0.5,1.7,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,1.7,0.5,1.8,0.5,1.8,0.5,1.7,0.5,39.9,8.9,2.3,0.4],
  11. fade:[8.9,4.8,0.8,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,1.7,0.5,1.7,0.5,1.8,0.5,1.7,0.5,1.7,0.5,1.8,0.5,1.7,0.5,1.7,0.5,1.8,0.5,1.8,0.5,0.6,0.5,0.6,0.5,1.8,0.5,0.5,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,1.7,0.5,1.8,0.5,0.6,0.5,1.7,0.5,1.7,0.5,1.7,0.5,39.9,8.9,2.3,0.5,106.8,0.4]
  12. };


Playback

All you need to do to play back is to pass an array into Puck.IR. For example if you have a lightbulb like the one I used, simply typing Puck.IR(commands.on) will turn it on.

You can also use Web Bluetooth to send data from a webpage to any Puck - it doesn't have to be pre-programmed as the Web Page can send the code and data at once.


Buying

You can buy the IR remote control lights like the ones I used from eBay. They are also available in strip form.

Note: while some of these lights look identical, they often use a different set of control codes. About the only way to be sure is to record your own codes.

Credits


Espruino

Espruino is a JavaScript Interpreter for Microcontrollers that is designed to make development quick and easy. The Espruino interpreter is firmware that runs on a variety of different microcontrollers, but we also make Espruino Boards that come with the interpreter pre-installed and are the easiest devices to get started with. However Espruino itself isn't just the interpreter firmware or hardware - there's also the Web IDE, command-line tools, documentation, tutorials, and modules which form a complete solution for embedded software development.


Leave your feedback...