-
Notifications
You must be signed in to change notification settings - Fork 0
Receiving with the IRremote library
This page gives some simple examples of how to receive IR codes with the IRremote Arduino library.
The following sketch will receive codes and print them to the serial port. This sketch is very useful for testing IR receiving, and for determining what code values to use in your code. A slightly more complex version is in the examples directory as IRrecvDump.
This sketch also illustrates how to perform an action while a button is pressed. In this example, the action is writing to the serial port.
#include <IRremote.h>
IRrecv irrecv(11); // Receive on pin 11
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Continue receiving
}
}This sketch illustrates how to perform an action when a button is pressed, and another action when a button is released. Note that an IR remote repeatedly sends a code while a button is pressed, so the code uses a timer to determine if the button has been released (i.e. no code has been received for a little while).
In this example, the LED is turned on when the button is pressed, and off when the button is released.
This sketch illustrates how to use a button on the remote as a toggle. Press a button once to turn the LED on, and press again to turn the LED off. As in the previous sketch, a timer is used to determine if the button is held down, or has been released.