
In this lesson, we will use the ubiquitous Infrared Receiver and remote control to send signals to our Arduino Uno.
When we get a signal we will blink an LED and output the signal code to the serial monitor so we can record it for later interpretation.
Code
/*
Read an IR remote and print the code for each button.
IR receiver: signal to pin 2, plus 5V and GND.
Written for version 4 of the IRremote library
(install it from the Library Manager).
*/
#include <IRremote.hpp>
#define RECV_PIN 2
void setup()
{
Serial.begin(115200);
// Start the receiver. ENABLE_LED_FEEDBACK flashes
// the built-in LED (pin 13) whenever a signal arrives.
IrReceiver.begin(RECV_PIN, ENABLE_LED_FEEDBACK);
Serial.println("Ready: point a remote at the receiver and press a button");
}
void loop()
{
if (IrReceiver.decode())
{
// One line per signal: protocol, address and command
IrReceiver.printIRResultShort(&Serial);
// The command is the short code we use to recognise
// each button in the remote control lesson
Serial.print("Command: 0x");
Serial.println(IrReceiver.decodedIRData.command, HEX);
// Get ready for the next signal
IrReceiver.resume();
}
}


