Control any IR remote capable device by wire with an Arduino

Recently I was faced with the problem of controlling three identical Personal Media Players with Arduino. Emulating the remote might have been an option but they were too close to each other, so it was hard to control them independently. A command sent for one device sometimes could be registered by the neighboring device. So here’s the hackish solution I found:

All devices with remote control has a built in IR receiver chip. They are usually dark red and have a cylindical or hemispherical window and three pins. Those pins are Ground, VCC and data. It is the data pin we are intrested in. Infrared control signals consist of high frequency pulses of light, and the length of pulses and gaps determine the data. Fortunately for us the carrier frequency is filtered inside the IR receiver chip, so there is only clear +5/0 volt pulses on the data pin. We can send the same messages as the remote commander to this pin and trick the device into thinking it is getting the pulses from the original remote.

But there is a problem. How do we know how the commands are coded? This is where LIRC comes into play. LIRC allows you to record and decode the signals sent from a remote controller. You should have some kind of infrared receiver connected to your computer, but fortunately many of the receiver designs are very easy to build. If you just need it for this project I would suggest using the sound card input method. It uses only an IR receiver chip and a 5V power source. Actually you could just wire the data and ground pins of the IR receiver on the device you wish to control, to the sound card mic input and you’ll be good to go.

Set up Lirc following the documentation on its website and test it with mode2 command. If you are getting the signal from remote and everything seems ok, now is time to record the commands from our remote commander. Once again you can consult the LIRC documentation on how to do that, but on my ubuntu system this command works:

Code:
irrecord -f -d /dev/lirc0 ~/pmp.lirc

Do not forget the -f flag. It forces irrecord to save the output in raw format. We are going to need a raw format file to convert it to arduino code. The program will instruct you to press keys and record them to the file specified (“~/pmp.lirc” in this case”). If you feel curious you can take a peek at the file for a text editor. You’ll see many numbers after “name [key_name]” statements. Those numbers represent times in microseconds. For example:

Code:
9182 432 688

means first the remote send a 9182 µS pulse, followed by a 432 µS gap and another 688 µS pulse. Now we need to translate these numbers into an integer array in arduino’s memory. Since our ram is very small (512 bytes for Atmega168) we will be using the program memory to store these arrays. I wrote a little php script to convert the lirc data file to an arduino header file you can use right away. You can use the script online here, or download the script to use it locally here.

Once we convert the data files it now comes to this: Connect any digital pin on the arduino to IR receiver data pin. Download the arduino example code from here. Write it on the Arduino’s memory and fire away.

Have fun!

Popularity: unranked [?]

  1. Great project. I am so doing this. What a great April Fools Joke. My son turns off all the lights when he plays video games. This year on April 1st, turning the light off will also turn off the TV.On a side note, for people who don’t have an o-scope. You can use Audacity and a solar cell plugged into your microphone jack to do the same thing.

    • rim
    • July 17th, 2011

    Hi!
    Can you correct online script. I get an error:
    Warning: Invalid argument supplied for foreach() in /var/www/symbolengine.com/http/lirctoc/index.php on line 31

    lirc file:http://lirc.sourceforge.net/remotes/canon/WL-DC100
    and
    http://lirc.sourceforge.net/remotes/minolta/RC3

    Thanks!

    • Tim
    • February 7th, 2012

    A great project. I now have a MythBuntu to Satellite IR blaster up and running – it was really simple. The hardest thing was to find out where to put the IR code.

  2. Those lirc files don’t seem to be in the RAW format that the script requires. You’ll need to do a raw recording (with the -f flag) of a working remote.

    • Pranav
    • April 19th, 2012

    The LIRC library i have is in the similar format as pointed out by “rim”. But i really need to extract data from the files and obtain a C header file.

  1. No trackbacks yet.