Build it step by step
0 of 8 doneWire the receiver
OUT to D11, GND to GND, VCC to 5V.
Upload the sketch
Serial monitor shows a ready message.
Press a button on a remote
The protocol, address and command print.
Press the same button again
The same command appears.
Hold a button down
Repeat codes are ignored.
Write the codes of five buttons
Make a table.
Try a second remote
Compare protocols.
Point it away
Distance and angle affect reception.
How do you build a remote control code reader?
An IR receiver reads the codes from any remote and prints them so you can use them in your own projects. You need Arduino Nano, IR receiver VS1838B, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 8 steps and about 90 minutes.
- Level
- Beginner
- Time
- About 90 min
- Parts
- 4
Parts list
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| VS1838B pin 1 (OUT) | Nano D11 | Demodulated signal, dome facing you, pin 1 on the left |
| VS1838B pin 2 (GND) | Nano GND | Ground |
| VS1838B pin 3 (VCC) | Nano 5V | Power |
Code
Most remotes send a short burst of infrared light flashing on and off at about 38 kilohertz, with the pattern of gaps carrying the code. The VS1838B receiver filters out that carrier and ambient light and outputs a clean pulse train, which the IRremote library measures with a timer and decodes into a protocol name, an address and a command number. NEC is the commonest protocol, used by many cheap remotes; Sony and Samsung are also supported. A held button sends short repeat codes, which the sketch ignores so each press prints once. Write down the command numbers of the buttons you want and use them in your own sketch with an if or switch statement to control lamps, motors or menus. If a remote shows as unknown, it may use a rarer protocol; the raw timing printout lets you compare patterns. A phone camera shows the remote's infrared light as a faint purple flicker, which is a quick way to check the remote's battery. Sunlight and some energy-saving lamps can interfere with reception.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
#include <IRremote.hpp>
const int IR_PIN = 11;
void setup() {
Serial.begin(9600);
IrReceiver.begin(IR_PIN, ENABLE_LED_FEEDBACK); // the on-board LED blinks on each code
Serial.println("Point a remote at the receiver and press a button");
}
void loop() {
if (IrReceiver.decode()) {
if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
Serial.println("Unknown protocol, raw data:");
IrReceiver.printIRResultRawFormatted(&Serial, true);
} else if (!(IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT)) {
Serial.print("Protocol ");
Serial.print(getProtocolString(IrReceiver.decodedIRData.protocol));
Serial.print(" address 0x");
Serial.print(IrReceiver.decodedIRData.address, HEX);
Serial.print(" command 0x");
Serial.println(IrReceiver.decodedIRData.command, HEX);
}
IrReceiver.resume(); // get ready for the next code
}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Press power on a TV remote | A command code prints |
| Same button again | Same code |
| Another button | Different code |
| Hold a button | One line only |
| Aim away from the sensor | Nothing prints |
If it does not work
Nothing prints
Check pin order, the dome faces you and OUT is on the left.
Always unknown
Try another remote or move closer.
Codes change each press
Some remotes use a rolling code, use another.
Compile error on IrReceiver
Install IRremote version 4 or later.
Noisy prints
Bright lamps nearby can interfere, shade the receiver.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the remote control code reader?
Arduino Nano, IR receiver VS1838B, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the remote control code reader take to build?
About 90 minutes for a beginner maker, in 8 steps.
How do I know the remote control code reader works?
Press power on a TV remote: A command code prints. Same button again: Same code. Another button: Different code.
Nothing prints: what should I check?
Check pin order, the dome faces you and OUT is on the left.
Always unknown: what should I check?
Try another remote or move closer.
Codes change each press: what should I check?
Some remotes use a rolling code, use another.
Compile error on IrReceiver: what should I check?
Install IRremote version 4 or later.
