How to wire an IR receiver to an Arduino Uno
To wire an IR receiver to an Arduino Uno, connect VCC to 5V, GND to GND and OUT to pin 2. The receiver runs from 5 V and its output idles at 5 V, which the Arduino Uno reads directly. The sketch below uses the IRremote (IRremote.hpp) library. It decodes the buttons of an NEC remote and prints each command code.
- 5 V logic
- Library: IRremote.hpp
- 3 wires, 1 helper parts
IR receiver to Arduino Uno wiring table
Every wire in the circuit above, with the part’s pin names and the board’s own labels. The wire colors are the ones the circuit uses; on a real bench any colors work.
| IR receiver pin | Arduino Uno pin | Wire color | Why |
|---|---|---|---|
| VCC | 5V | red | The VS1838B-style receiver runs from 2.7 to 5.5 V. |
| GND | GND | blue | Ground. |
| OUT | pin 2 | amber | Low while a 38 kHz burst arrives, high otherwise: the demodulated code. |
| IR (light) | The remote | n/a | In the editor the infrared light path is drawn as a gray wire from the remote. |
Helper parts
The extra parts in the circuit above, and where their wires go:
| From | To | Wire color |
|---|---|---|
| RM1 pin IR | IR | gray |
Power and logic levels for IR receiver and Arduino Uno
Logic level
The Arduino Uno’s pins are 5 V logic. A 5 V part can drive them directly; a part whose signal pins are limited to 3.3 V needs a level shifter.
Supply
The IR receiver takes 5 V from 5V. That is the Arduino Uno’s 5 V rail, so the part shares the current the board can supply.
This pair
The receiver runs from the Arduino Uno’s 5V pin and its output idles at 5 V, which the board reads directly.
Pins to leave alone
Pins 0 and 1 are the USB serial port on a real Uno, so anything wired there fights the upload and the serial monitor. Pin 13 carries the onboard LED.
The working code for the Arduino Uno
Library: IRremote (IRremote.hpp). This is the sketch the circuit above runs.
#include <IRremote.hpp>
const int IR_PIN = 2; // OUT, pin 2
void setup() {
Serial.begin(9600);
IrReceiver.begin(IR_PIN);
Serial.println("Point the remote and press a button");
}
void loop() {
if (IrReceiver.decode()) {
if (!(IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT)) {
Serial.print("Command: 0x");
Serial.println(IrReceiver.decodedIRData.command, HEX);
}
IrReceiver.resume(); // ready for the next one
}
}
What you should see
Open the serial monitor at 9600 baud. The sketch prints Point the remote and press a button, and then a Command line in hexadecimal for each button press on the remote in the circuit.
A receiver that never prints anything is usually on the wrong pin, or the remote uses a protocol other than NEC.
The serial monitor prints this, recorded from the circuit above with one remote button pressed after 300 ms:
Point the remote and press a button
Command: 0x47Common mistakes wiring an IR receiver to an Arduino Uno
Old IRremote code
Sketches written for IRremote 2.x use IRrecv irrecv(pin), irrecv.enableIRIn() and results.value. Version 3 and later use IrReceiver and decodedIRData, as here. Mixing the two is the most common reason an IR sketch will not compile.
Forgetting resume()
After decode() returns true, the library holds the code until resume() is called. Leave it out and the first button press is the only one you ever see.
Using pins 0 and 1
Pins 0 and 1 carry the USB serial port on a real Uno. the receiver output wired there fights every upload and every Serial.print(). Start at pin 2.
Build your own IR receiver project
Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.