Read an IR Remote (Arduino)
Decode button presses from any infrared remote and print their codes. The first step to remote-controlling anything.
Beginner20 min
What you need
Wiring
Hover a pin or a wire to trace the connection.
Code
ir_remote.ino
// Print the code of each IR remote button.
// Install "IRremote" by shirriff/Armin Joachimsmeyer (v3+).
#include <IRremote.h>
const int recvPin = 2;
void setup() {
Serial.begin(9600);
IrReceiver.begin(recvPin);
}
void loop() {
if (IrReceiver.decode()) {
Serial.print("Button code: 0x");
Serial.println(IrReceiver.decodedIRData.command, HEX);
IrReceiver.resume(); // ready for the next press
}
}
Steps
- Check your module's pin order on the silkscreen, then wire OUT to D2, VCC to 5V, GND to GND.
- Install the "IRremote" library (v3+).
- Upload, open the Serial Monitor, and press remote buttons to see each code.
- Use those codes in if-statements to trigger your own actions.