Building a Web Based Infrared Remote Control

This little project was born out of a wish to control a DAB tuner from other rooms of the house and a couple of hours on a Sunday afternoon made it reality. A Nanode (an original Nanode 5 in this case) is plugged into my ethernet network and an infrared emitter is connected to digital pin 3, on visiting the ip address of the Nanode using a web browser you will see a series of buttons (shown on my phone in the screenshot on the right, click to see it full size) and selecting the various options makes the Nanode transmit the relevant infrared code to operate the DAB tuner.

The hard work here is done by the IR Remote library by Ken Shirriff available here. This infrared library has direct support for several common IR protocols (NEC, Sony SIRC and Philips RC5 and RC6) but not the one that my DAB tuner uses, fortunately this isn’t a problem as the library also makes it easy to read and transmit using the raw infrared codes (mark and space intervals) from any remote control.
NB. If you are using Arduino IDE 1.0 note the comment on the library page about changing WProgram.h for Arduino.h – that’s the only change required for 1.0

Getting the codes from the original remote control

The first step is to use an IR receiver connected to the Nanode to read the codes from the original remote control. An IR receiver is basically a photocell that is tuned to the infrared spectrum along with a demodulator that gives an inverted logic level output. I used a Vishay TSOP31238 IR sensor (63p +VAT from Farnell) and connected it to the Nanode as shown on the left.

To read the codes load the IRrecvDump example sketch that is included with the IR library onto the Nanode, open the serial monitor and point the remote control you want to get the codes from at the sensor, for supported protocols it will output the protocol, a hex value, the number of bits and the raw code as each button is pressed, for an unsupported protocol it will return “Could not decode message” and output the raw code only.

Press each button in turn and save the codes in a safe place. Once all the necessary codes have been gathered the IR receiver is no longer required for this project but has lots of potential for future use.

Sending the codes from the Nanode

To transmit the IR codes you need an infrared emitter – a type of LED that emits infrared light. I used a Vishay TSAL7400 2.6V IR emitter (18p +VAT from Farnell) connected via a 27 Ohm resistor (as I’m using a 5V Nanode 5) to pin 3 of the Nanode as shown on the right.

The codes are transmitted by the library using pulse width modulation so a PWM pin must be used on the Nanode, the library is configured to use pin 3 which is convenient as it is free for use on a Nanode 5 (and on a Nanode Classic or RF provided you aren’t using an MCP7941x RTC).

Supported protocol codes

To send a code using one of the supported protocols you just need to use to use the relevant irsend command with the hex value and the number of bits, for example to send an NEC protocol command that IRrecvDump reported as “Decoded NEC: A10C800F (32 bits)” you would use:

irsend.sendNEC(A10C800F, 32)

Change sendNEC to sendSony, sendRC5 or sendRC6 depending on the protocol that IRrecvDump reported.

Raw Codes

For raw codes we first need to modify the output from the IRrecvDump sketch slightly, just remove the first group of digits and make all the numbers positive, then add commas between each group and put it into an array.

eg. The code received from the IRrecvDump sketch:

-14368 4500 -4500 600 -500 600 -1650 600 -550 550 -550 600 -500 600 -550 600 -500 600 -1650 600 -550 550 -1700 550 -550 600 -550 550 -550 600 -500 600 -550 600 -1600 600 -1650 600 -550 550 -550 600 -550 550 -550 600 -550 550 -550 600 -550 550 -550 600 -1650 600 -1600 600 -1650 600 -1650 600 -1650 600 -1650 600 -1650 600 

becomes

unsigned int rawCode[68] = {4500, 4500, 600, 500, 600, 1650, 600, 550, 550, 550, 600, 500, 600, 550, 600, 500, 600, 1650, 600, 550, 550, 1700, 550, 550, 600, 550, 550, 550, 600, 500, 600, 550, 600, 1600, 600, 1650, 600, 550, 550, 550, 600, 550, 550, 550, 600, 550, 550, 550, 600, 550, 550, 550, 600, 1650, 600, 1600, 600, 1650, 600, 1650, 600, 1650, 600, 1650, 600, 1650, 600};

and then to send it we use the sendRaw command with the array name, array length and the frequency (38kHz):

irsend.sendRaw(rawCode,68,38);

Turning all this into a functional web based remote control

So now I have all the relevant codes for my target device and can send them from the Nanode to control it, the next step was to build a simple web server on the Nanode to allow easy selection of the various codes.

I based this on the Ethercard version of RESTduino by Andrew D Lindsay (itself based on the original by Jason Gullickson) modifying it to transmit IR codes instead of controlling the I/O pins and adding the menu. The only problem I ran into here was due to all the arrays for the raw codes eating up the RAM in the ATmega 328 but storing them in flash using PROGMEM instead solved that. I’m not sure the way I’m reading them back is the most elegant but it works!

My code for this is available on GitHub here and it would be simple to modify for other IR controlled devices. There is also an optional css file there to prettify the basic HTML output, due to the lack of RAM this would need to go on a separate web server. Another option would be to build a full fat web interface on another server and just call the Nanode’s URLs to send each command, eg. “http://192.168.0.188/4” to send the command for preset 4.

Other uses for infrared

The IR library along with the IR receiver makes it easy to use an arbitrary infra red remote control to control the Nanode (or any other Arduino compatible for that matter). It’s as simple as building a conditional structure in the loop to do what you want on reception of the relevant code, this could be used to turn outputs on and off or trigger events over the network or RF.

One thought on “Building a Web Based Infrared Remote Control

  1. Hello,

    Your site is quite good ! thanks

    I have a mitsibushi air cooler with a IR Remote control.
    I would like to manage the on/off of the air cooler device remotly with aduino.
    I can dump read the IR on code from the remote (see below)

    E1CC9186
    Unknown encoding: E1CC9186 (32 bits)
    Raw (100): 12064 3400 -1700 450 -1250 500 -1200 450 -400 450 -450 400 -450 500 -1200 500 -350 450 -400 500 -1200 450 -1300 500 -350 500 -1200 500 -350 450 -400 450 -1250 550 -1200 450 -400 450 -1250 450 -1250 450 -450 400 -450 400 -1300 450 -400 450 -400 450 -1250 450 -400 550 -350 400 -450 500 -350 500 -350 500 -350 500 -350 500 -400 500 -350 500 -350 500 -350 500 -400 450 -400 450 -400 500 -350 500 -350 500 -350 500 -350 500 -400 450 -400 500 -350 500 -350 500 -350 500

    The first issue is that the protocol seems not to be ‘known’ –> Unknown encoding,

    -Is there a library IRLib to manage mitsubishi air cooler ?
    -How do i have to manage my code in order to reproduce it ?
    -like this ?

    unsigned int rawCode[68] = {12064, 3400, 1700, 450, 1250, 500, 1200, 450, 400, 450, 450 400, 450, 500, 1200, 500, 350, 450, 400, 500, 1200, 450, 1300, 500, 350, 500, 1200, 500, 350, 450, 400, 450, 1250, 550, 1200, 450, 400, 450, 1250, 450, 1250, 450, 450, 400, 450, 400, 1300, 450, 400, 450 ,400, 450, 1250, 450, 400, 550, 350, 400, 450, 500, 350, 500, 350 500, 350, 500, 350, 500, 400, 500, 350, 500, 350, 500, 350, 500, 400, 450, 400, 450, 400, 500, 350, 500, 350, 500, 350, 500, 350, 500, 400, 450, 400, 500, 350, 500, 350, 500, 350 500};

    irsend.sendRaw(rawCode,100,38);

    -How can i be sure that my IRLed is working?
    -How can i know the frequency 38KHz?

    A lot of question …
    Thanks in advance

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.