IR control is a BINARY communications system
- It uses a series of "0" and "1" (off or on) to convey a value from a transmitter to a receiver
- The "Transmitter" is an IR LED and the "Receiver is a photosensitive element that responds to IR light"
- However... just being able to "see" if the IR LED is lit doesn't allow us to communicate.
- We need to have a "protocol" that defines how long a "control sequence" is and how to read it.- In other words, I need to know when the sequence starts, and when it ends.
We're going to use the "IRremote" library which understands most of the POPULAR protocols
#include // This is the library we need to speak IR protocols
#define IR_PIN 2 // The digital pin to which the IR Reciever is connected
IRrecv irrecv(IR_PIN); // Turn on the reciever
decode_results ircode; // Create a structure called "IRcode"
void setup()
{
Serial.begin(9600); // Start the Serial Port (for debug)
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
if (irrecv.decode(&ircode)) // IF the IR reciever has received a code, THEN run the following:
{
Serial.println(ircode.value, HEX); // Print the received code to the Serial Port (for Debug)
irrecv.resume(); // Wait for the next IR code
}
}