IR remote button code reader
Point any old TV or fan remote at an infrared receiver and print the code of each button on the serial monitor, then light an LED only for one chosen button. You learn how a remote sends numbers as flashes of invisible light.
Build it step by step
0 of 7 doneCheck your receiver's pin order
OUT, GND and VCC, from the datasheet.
Wire it to D2, GND and 5V
Wire the LED on D8 with 220 ohms.
Install the IRremote library
Version 4 from the Library Manager.
Upload and open the serial monitor at 9600
The prompt line appears.
Press each remote button
A protocol and command appear.
Choose one command
Put it into TARGET_COMMAND and upload again.
Press that button
The LED toggles each time.
How do you build an IR remote button code reader?
Point any old TV or fan remote at an infrared receiver and print the code of each button on the serial monitor, then light an LED only for one chosen button. You learn how a remote sends numbers as flashes of invisible light. You need Arduino Nano, IR receiver VS1838B, LED 5 mm red, Resistor 220 Ω, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 60 minutes.
- Level
- Beginner
- Time
- About 60 min
- Parts
- 6
Parts list
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- SemiconductorsBuyLED 5 mm red × 1
- PassivesBuyResistor 220 Ω × 1
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| IR receiver OUT | Nano D2 | The decoded pulse output |
| IR receiver GND | Nano GND | Common ground |
| IR receiver VCC | Nano 5V | Power |
| LED long leg | Nano D8 through a 220 ohm resistor | Indicator output |
| LED short leg | Nano GND | Return path |
Code
An infrared remote sends a short burst of flashes, too fast and too dim in colour for you to see, that spell out a number. The receiver module filters out room light and hands the Nano a clean pulse train, which the IRremote library decodes into a protocol name and a command number. Press each button on an old TV, fan or set-top remote and write down its command in a table. Then put the number for one button into the sketch in place of the 0x00 placeholder and upload again, so the LED toggles only on that button. Holding a button sends repeat codes, which the sketch ignores. Check the pin order of your own receiver against its datasheet, because the three pins are not always in the same order, and a wrong power connection can damage it. The receiver also reacts to very bright sunlight and some low-energy lamps, so test indoors.
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> // library "IRremote" version 4
const uint8_t IR_PIN = 2;
const uint8_t LED_PIN = 8;
const uint16_t TARGET_COMMAND = 0x00; // put the command of your chosen button here
bool ledOn = false;
void setup() {
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT);
IrReceiver.begin(IR_PIN);
Serial.println("Point a remote at the receiver and press a button.");
}
void loop() {
if (IrReceiver.decode()) {
bool repeat = IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT;
if (!repeat) {
Serial.print("Protocol ");
Serial.print(getProtocolString(IrReceiver.decodedIRData.protocol));
Serial.print(" command 0x");
Serial.println(IrReceiver.decodedIRData.command, HEX);
if (IrReceiver.decodedIRData.command == TARGET_COMMAND) {
ledOn = !ledOn; // toggle on the chosen button
digitalWrite(LED_PIN, ledOn);
}
}
IrReceiver.resume();
}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Any button press | A protocol and command print |
| Same button twice | The same command each time |
| Different buttons | Different commands |
| Chosen button | LED toggles on and off |
| Other buttons | LED does not change |
If it does not work
Nothing prints
Check the pin order and that the remote has working batteries.
Garbled commands
Check the receiver is on 5V and the wires are firm.
Library errors
Install IRremote version 4 and use the .hpp include.
LED does not toggle
Check the command number matches exactly.
Works only very close
Aim the remote straight at the dome.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the IR remote button code reader?
Arduino Nano, IR receiver VS1838B, LED 5 mm red, Resistor 220 Ω, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the IR remote button code reader take to build?
About 60 minutes for a beginner maker, in 7 steps.
How do I know the IR remote button code reader works?
Any button press: A protocol and command print. Same button twice: The same command each time. Different buttons: Different commands.
Nothing prints: what should I check?
Check the pin order and that the remote has working batteries.
Garbled commands: what should I check?
Check the receiver is on 5V and the wires are firm.
Library errors: what should I check?
Install IRremote version 4 and use the .hpp include.
LED does not toggle: what should I check?
Check the command number matches exactly.
