A ₹20 IR receiver turns any old TV remote into a wireless keypad for the Nano. The receiver’s OUT pin goes to D2; it is powered from 5V like everything else on the Nano.
Press keys and note the command codes; then use them in a switch to toggle relays or LEDs. The on-board LED flickers on every frame received, which makes wiring problems easy to spot.
Wiring
| Arduino Nano | VS1838B IR receiver (38 kHz) | Wire | Notes |
|---|---|---|---|
| D2 | OUT | yellow | |
| GND | GND | black | |
| 5V | VCC | red |
2.7–5.5 V part, 5 V board. Power it from your board's logic voltage; OUT is an active-LOW signal at VCC level.
Board quirks
- Bare VS1838B pin order, looking at the dome: OUT, GND, VCC. Module boards often reorder them — follow the print.
- IRremote uses Timer2 on the Nano, so
tone()andanalogWrite()on D3 and D11 stop working. Servo (Timer1) andmillis()(Timer0) are unaffected. - Most Indian set-top box and TV remotes use the NEC protocol; AC remotes send long frames that IRremote shows as “UNKNOWN” or as several packets.
- Sunlight and CFL/LED tube lights add noise. Shade the dome and add a 100 nF capacitor across VCC/GND close to the receiver.
Code
// VS1838B IR receiver on an Arduino Nano: prints protocol, address and command of any remote.
// OUT → D2, GND → GND, VCC → 5V. IRremote uses Timer2 on the ATmega328P, so tone() and
// analogWrite() on D3/D11 stop working while it runs.
#include <IRremote.hpp>
const uint8_t IR_PIN = 2;
void setup() {
Serial.begin(115200);
IrReceiver.begin(IR_PIN, ENABLE_LED_FEEDBACK); // the on-board LED flickers on each frame
Serial.println(F("Point a remote at the receiver and press a key"));
}
void loop() {
if (IrReceiver.decode()) {
if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT) {
Serial.println(F("(repeat)"));
} else {
Serial.print(F("Protocol: "));
Serial.print(getProtocolString(IrReceiver.decodedIRData.protocol));
Serial.print(F(" Address: 0x"));
Serial.print(IrReceiver.decodedIRData.address, HEX);
Serial.print(F(" Command: 0x"));
Serial.println(IrReceiver.decodedIRData.command, HEX);
}
IrReceiver.resume();
}
}// VS1838B IR receiver on an Arduino Nano: prints protocol, address and command of any remote.
// OUT → D2, GND → GND, VCC → 5V. IRremote uses Timer2 on the ATmega328P, so tone() and
// analogWrite() on D3/D11 stop working while it runs.
#include <IRremote.hpp>
const uint8_t IR_PIN = 2;
void setup() {
Serial.begin(115200);
IrReceiver.begin(IR_PIN, ENABLE_LED_FEEDBACK); // the on-board LED flickers on each frame
Serial.println(F("Point a remote at the receiver and press a key"));
}
void loop() {
if (IrReceiver.decode()) {
if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT) {
Serial.println(F("(repeat)"));
} else {
Serial.print(F("Protocol: "));
Serial.print(getProtocolString(IrReceiver.decodedIRData.protocol));
Serial.print(F(" Address: 0x"));
Serial.print(IrReceiver.decodedIRData.address, HEX);
Serial.print(F(" Command: 0x"));
Serial.println(IrReceiver.decodedIRData.command, HEX);
}
IrReceiver.resume();
}
}Library: IRremote (Armin Joachimsmeyer (shirriff, z3t0)) — compiled with IRremote 4.7.1.
Expected serial output
Point a remote at the receiver and press a key
Protocol: NEC Address: 0x0 Command: 0x45
(repeat)
Protocol: NEC Address: 0x0 Command: 0x46Point a remote at the receiver and press a key Protocol: NEC Address: 0x0 Command: 0x45 (repeat) Protocol: NEC Address: 0x0 Command: 0x46
Common errors
IRremote.h: old example code does not compile
IRremote 4.x replaced irrecv.decode(&results) with IrReceiver.decode() and IrReceiver.decodedIRData. Use the sketch on this page.
Nothing is printed
Wrong pin order (the bare part gets hot if VCC/GND are swapped) or a 56 kHz remote. Check with a phone camera that the remote LED flashes.