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:
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:
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.
Popularity: unranked [?]