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

QtyPartWhat it does
1Arduino Unothe microcontroller board
1IR receiverA 38 kHz receiver: DAT idles HIGH and pulses LOW with each NEC frame from the IR remote. VCC, GND, DAT to a pin.
1IR remotePress a key while running: every IR receiver in the circuit gets its NEC code (address 0).

Wiring

#FromTo
1Arduino Uno 5VIR receiver VCC
2Arduino Uno GNDIR receiver GND
3Arduino Uno pin 2IR receiver DAT

Step by step

  1. Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
  2. Add the parts. Add an IR receiver and an IR remote from the parts palette.
  3. Wire 1. Connect Arduino Uno 5V to IR receiver VCC.
  4. Wire 2. Connect Arduino Uno GND to IR receiver GND.
  5. Wire 3. Connect Arduino Uno pin 2 to IR receiver DAT.
  6. Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
  7. 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