Tuesday, October 11, 2011

InduinoX: IR receiver

From my previous post, you probably understood how IR remotes work in general. Now lets take a look at how we can read the signals coming from various remotes that you might have.

Fortunately for us the InduinoX board comes with an IR receiver. And the good news is that some one already wrote the code to read IR signal from arduino! Just copy the code from http://www.arduino.cc/playground/Code/InfraredReceivers, replace the value of IRpin from 2 to A1, because on InduinoX, the IR receiver is connected to analog pin 1. Compile and upload the code to InduinoX.

The code basically sets up the serial port to 115200 baud rate, then sets up timers (read this excellent tutorial on PWMs on arduino), finally the code waits on the IR receive pin for the signal to change (the signal changes when a button on a remote is pressed pointing to the IR receiver). Then the code keeps track of the time it takes for the signal to change from high to low and low to high. At the end of the signal transitions the code prints the timing information. The output looks like

0 0
2476 0
2476 1
3000 1
3000 0
3664 0
3664 1
4204 1
4204 0
5472 0
5472 1
:

Save the output to a file. The output can be used by gnuplot to display the graph of the signal. Make sure you have gnuplot installed on your machine. I used these commands

$ gnuplot
set yrange [-1:2]
plot  "/home/chandanp/temp/vol_up.txt" with lines title 'signal'

And my output looks like this


Notice how the signal repeats itself 2 times and then there is a partial signal at the end. If you happen to have an oscilloscope, you can use the probe on the IR receiver data out pin to see the output on the scope. I have a picoscope 2205 (perhaps a blog post on that later) and the output on the scope looks like this


Since the signal repeats itself every 45ms, here is a closer look at the signal.


Notice that the signal is inverted. Knowing that 0 is represented by 600ms of high and 600 ms of low and a 1 is represented by 1200ms of high and 600ms of low signal (see my previous blog post if you don't know how I arrived at these numbers), the code for volume up on my remote control is 0x490 (0100 1001 0000). In my next blog post, I will show you how I was able to change the volume on my TV by sending the signal 0x490 from InduinoX and pointing it at my TV!
Post a Comment