STEP 1

Make a directory inside your “tessel-code” folder called “ir”, change directory into that folder, and initialize a tessel project:

mkdir ir; cd ir; t2 init

STEP 2

Plug the IR module into Tessel port A with the hexagon/icon side down and the electrical components on the top, then plug Tessel into your computer via USB.

STEP 3

Install by typing npm install ir-attx4 into the command line.

STEP 4

Rename “index.js” to “ir.js” and replace the file’s contents with the following:

// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/

/*********************************************
This infrared module example transmits the
power signal sequence of an Insignia brand
television every three seconds, while also
listening for (and logging) any incoming
infrared data.
*********************************************/

var tessel = require('tessel');
var infraredlib = require('ir-attx4');
var infrared = infraredlib.use(tessel.port['A']);

// When we're connected
infrared.on('ready', function() {
  console.log("Connected to IR!");
  // Start sending a signal every three seconds
  setInterval(function () {
    // Make a buffer of on/off durations (each duration is 16 bits)
    var powerBuffer = new Buffer([0x22,0xc4,0xee,0xd0,0x2,0x58,0xfe,0xc,0x2,0x8a,0xf9,0xf2,0x2,0x8a,0xf9,0xc0,0x2,0x58,0xfe,0xc,0x2,0x58,0xfe,0xc,0x2,0x8a,0xfe,0x3e,0x2,0x8a,0xfe,0x3e,0x2,0x8a,0xf9,0xc0,0x2,0x58,0xf9,0xc0,0x2,0x8a,0xfe,0x3e,0x2,0x8a,0xf9,0xc0,0x2,0x58,0xfe,0xc,0x2,0x58,0xfe,0xc,0x2,0x58,0xfe,0xc,0x2,0x58,0xfe,0xc,0x2,0x8a,0xfe,0x3e,0x2,0x8a,0xf9,0xc0,0x2,0x58,0xf9,0xc0,0x2,0x8a,0xf9,0xf2,0x2,0x8a,0xf9,0xc0,0x2,0x58,0xfe,0xc,0x2,0x58,0xfe,0xc,0x2,0x8a,0xfe,0x3e,0x2,0x8a,0xfe,0x3e,0x2,0x8a,0xfe,0xc,0x2,0x58,0xfe,0xc,0x2,0x58,0xfe,0xc,0x2,0x58,0xfe,0xc,0x2,0x58,0xf9,0xc0,0x2,0x8a,0xf9,0xc0,0x2,0x58,0xf9,0xc0,0x2,0x58,0xf9,0xc0,0x2,0x58]);
    // Send the signal at 38 kHz
    infrared.sendRawSignal(38, powerBuffer, function(err) {
      if (err) {
        console.log("Unable to send signal: ", err);
      } else {
        console.log("Signal sent!");
      }
    });
  }, 3000); // Every 3 seconds
});

// If we get data, print it out
infrared.on('data', function(data) {
  console.log("Received RX Data: ", data);
});

Save the file.

STEP 5

In your command line, t2 run ir.js Try turning on your TV! Look at the IR LED through a camera.

Bonus: Change the code to turn on a different device.

STEP 6

What else can you do with a IR module? Try a community-created project.