Arduino IRremote Library Decoder: Wiring, Code and Simulator
To build this Arduino IRremote Library Decoder project you need an Arduino Uno and an IR receiver and an IR remote. The IRremote library decodes NEC codes from the IR receiver on pin 2. Make the 3 connections in the wiring table, upload the Arduino C++ code, and click keys on the remote while it runs and watch the command codes.
Open this circuit in the free Arduino Uno simulator
Parts list
| Qty | Part | What it does |
|---|---|---|
| 1 | Arduino Uno | the microcontroller board |
| 1 | IR receiver | A 38 kHz receiver: DAT idles HIGH and pulses LOW with each NEC frame from the IR remote. VCC, GND, DAT to a pin. |
| 1 | IR remote | Press a key while running: every IR receiver in the circuit gets its NEC code (address 0). |
Wiring
| # | From | To |
|---|---|---|
| 1 | Arduino Uno 5V | IR receiver VCC |
| 2 | Arduino Uno GND | IR receiver GND |
| 3 | Arduino Uno pin 2 | IR receiver DAT |
Step by step
- Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
- Add the parts. Add an IR receiver and an IR remote from the parts palette.
- Wire 1. Connect Arduino Uno 5V to IR receiver VCC.
- Wire 2. Connect Arduino Uno GND to IR receiver GND.
- Wire 3. Connect Arduino Uno pin 2 to IR receiver DAT.
- Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
- Run it. Press Run. Click keys on the remote while it runs and watch the command codes.
Arduino C++ code
// IRremote: decode the NEC codes from an IR remote on pin 2.
// Press a key on the remote while the sketch runs.
#include <IRremote.hpp>
void setup() {
Serial.begin(9600);
IrReceiver.begin(2, DISABLE_LED_FEEDBACK);
Serial.println("Ready for the remote.");
}
void loop() {
if (IrReceiver.decode()) {
// A key pressed again within ~110 ms arrives as NEC2 (a full repeat frame).
if (IrReceiver.decodedIRData.protocol != UNKNOWN) {
Serial.print("Command: 0x");
Serial.println(IrReceiver.decodedIRData.command, HEX);
}
IrReceiver.resume();
}
}
What to try
Click keys on the remote while it runs and watch the command codes.
Frequently asked questions
How do I wire the IRremote Library Decoder project on an Arduino Uno?
Make 3 connections: Arduino Uno 5V to IR receiver VCC; Arduino Uno GND to IR receiver GND; Arduino Uno pin 2 to IR receiver DAT.
What parts do I need for this Arduino project?
An Arduino Uno and an IR receiver and an IR remote.
Can I simulate this Arduino project online for free?
Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.
What does the code do?
The IRremote library decodes NEC codes from the IR receiver on pin 2.
More Arduino Uno projects
- Arduino LED Blink: Wiring, Code and Simulator
- Arduino LDR Light Sensor: Wiring, Code and Simulator
- Arduino NTC Thermistor Thermometer: Wiring, Code and Simulator
- Arduino PWM to Analog RC Filter: Wiring, Code and Simulator
- Arduino Capacitance Meter: Wiring, Code and Simulator
- Arduino DC Motor PWM Speed Control with MOSFET: Wiring, Code and Simulator