IR Communication
Receiving IR Example
IR remote controls are as ubiquitous as their appliance counterparts. What if you could put all of those old remote controls to use in your next project? This example will show you how to read IR remote codes from any IR remote using the TSOP382 IR receiver and an Arduino. Once you can receive codes from individual button presses, your remote control and Arduino become a general purpose, short range, communication interface!
Assuming that you have the IR library, go to your Arduino project directory: Arduino/libraries/IRremote/examples/IRrecvDemo and open the IRrecvDemo.ino. Upload the sketch to your Arduino.
The sketch will automatically decode the type of remote you are using and identify which button on your remote is pressed. Open the serial port in the Arduino IDE at 9600 bps and hit different buttons on your remote.
When specific buttons are pressed, you can use the incoming values to do something else in your code, for example turn on and off a motor or LED.
The results from each button press can be found by calling the value() method:
language:c
results.value
You can print the values to the terminal window:
language:c
Serial.println(results.value, HEX); //prints the hex value a a button press
Or you might need read the values to run a conditional statement:
language:c
if(irrecv.decode(&results)) //this checks to see if a code has been received
{
if(results.value == 0xC284) //if the button press equals the hex value 0xC284
{
//do something useful here
}
irrecv.resume(); //receive the next value
}