38kHz IR Remote & Receiver Wireless Decoder
Demodulate 38kHz infrared remote control packets using a VS1838B/KY-022 receiver to trigger wireless actions.
Add effortless wireless control to any Arduino project using a handheld IR remote and 38kHz demodulator module. Decode NEC protocol command bytes cleanly with IRremote v4, map remote keys to toggle LEDs or relays, and filter key-repeat frames.
Key Learning Objectives & Robotics Concepts
By building and programming this project, you will master the following core engineering skills:
Power Architecture & Voltage Staging
5V / 3.3V Regulated PowerThe VS1838B IR demodulator draws under 1.5mA from the Arduino Uno 5V rail. An optional status LED on D8 draws ~14mA through a 220Ω series resistor. Internal 38kHz bandpass filter rejects sunlight and room lamps; keep receiver pin out of direct incandescent glare.
Bill of Materials (BOM) & Hardware Components
| Component | Specifications & Alternative | Qty | Approx Cost |
|---|---|---|---|
| Arduino Uno R3 | ATmega328P @ 16MHz | 1 | $8.00 |
| VS1838B / KY-022 38kHz IR Receiver | 38kHz carrier demodulator, 8–12m range | 1 | $1.20 |
| NEC Infrared Remote Control | 17-key or 21-key CR2025 battery remote | 1 | $2.00 |
| 5mm LED + 220Ω Resistor | Wireless switched load indicator | 1 | $0.15 |
Electrical & System Architecture
Connect IR Receiver VCC (+) to 5V, GND (-) to GND, and OUT (S) to Arduino D2. Wire a controlled LED (+220Ω) to D8 for wireless toggle demonstration.
Autonomous Behavior & Finite State Machine (FSM)
Deterministic Arduino loop handling VS1838B / KY-022 38kHz IR Receiver + Remote acquisition, filtering, and real-time output updates.
Step-by-Step Physical Assembly & Wiring Tutorial
Follow each of the 5 sequential milestone stages with technical photos, wiring checks, and pre-flight tests.
Remove Battery Pull-Tab & Verify Receiver Pinout
Pull the clear plastic insulator out of the IR remote battery tray and inspect receiver pins.
- Pull out the plastic battery tab on the bottom of the remote control.
- Point the remote at a smartphone camera and press a button—you should see a faint violet glow on screen.
- Verify KY-022 / VS1838B pins (bare VS1838B dome facing you: OUT, GND, VCC).
Wire IR Receiver to D2 & Indicator LED to D8
Connect power, ground, receiver data to D2, and the target LED to D8.
- Wire IR Receiver VCC → 5V, GND → GND, and OUT → D2.
- Wire D8 → 220Ω resistor → LED anode → cathode to GND.
- Aim the black IR dome unobstructed toward your testing position.
Install IRremote v4 Library
Install "IRremote" by shiriff / ArminJo via Library Manager.
- Open Arduino IDE Library Manager and search "IRremote".
- Install the latest IRremote v4.x library.
- Note that v4 uses IrReceiver.begin() and IrReceiver.decodedIRData.command.
Capture Your Remote's Command Hex Codes
Upload the decoder sketch, press buttons on your remote, and observe exact hex commands.
- Upload the production sketch and open Serial Monitor at 115200 baud.
- Press keys 1, 2, OK, and Power on your remote and note their Hex Command values.
- Verify key 1 (0x45 or 0x0C) and key 2 (0x46 or 0x18) update to match your remote.
Test Wireless Range & Repeat Filtering
Verify crisp single-press toggling across the room without repeat-frame chatter.
- Press and hold a toggle button—confirm it triggers only once per press.
- Test line-of-sight range up to 5 meters and bounce signals off a white ceiling.
- Record command hex codes for all keys you plan to automate.
Subsystem Benchtop Verification Scripts
Test each hardware subsystem independently before deploying the full autonomous firmware.
1Bench Diagnostic: VS1838B / KY-022 38kHz IR Receiver + Remote Hardware Check
Subsystem DiagnosticMinimal standalone sketch to verify pin wiring and signal response for VS1838B / KY-022 38kHz IR Receiver + Remote before running the full project firmware.
// Diagnostic: Print Every Decoded IR Protocol & Hex Command
#include <IRremote.hpp>
void setup() {
Serial.begin(115200);
IrReceiver.begin(2, ENABLE_LED_FEEDBACK);
}
void loop() {
if (IrReceiver.decode()) {
Serial.print("Protocol="); Serial.print(getProtocolString(IrReceiver.decodedIRData.protocol));
Serial.print(" | Cmd=0x"); Serial.println(IrReceiver.decodedIRData.command, HEX);
IrReceiver.resume();
}
}Complete Production Firmware
Full working C++ source code with pin mappings, non-blocking timers, and FSM avoidance routines.
/**
* Project 12: 38kHz IR Remote Wireless Controller (IRremote v4)
* Board: Arduino Uno R3 | Pins: D2 (IR OUT), D8 (LED)
* Library: IRremote by ArminJo (v4.x)
*/
#include <IRremote.hpp>
const uint8_t IR_PIN = 2;
const uint8_t LED_PIN = 8;
bool ledState = false;
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
IrReceiver.begin(IR_PIN, ENABLE_LED_FEEDBACK);
Serial.println(F("IR Remote Decoder Ready. Press any key..."));
}
void loop() {
if (!IrReceiver.decode()) return;
// Ignore NEC repeat frames when button is held down
if (!(IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT)) {
uint16_t cmd = IrReceiver.decodedIRData.command;
Serial.print(F("Key Command: 0x"));
Serial.println(cmd, HEX);
// Common NEC starter-kit codes (adjust from Serial printout if needed)
if (cmd == 0x45 || cmd == 0x0C) { // Key '1' -> LED ON
ledState = true;
} else if (cmd == 0x46 || cmd == 0x18) { // Key '2' -> LED OFF
ledState = false;
} else if (cmd == 0x1C || cmd == 0x40) { // Key 'OK' -> Toggle
ledState = !ledState;
}
digitalWrite(LED_PIN, ledState ? HIGH : LOW);
}
IrReceiver.resume();
}Firmware Architecture Explanation:
- Uses modern IRremote v4 (IRremote.hpp) with onboard LED feedback on pin 13.
- Filters out IRDATA_FLAGS_IS_REPEAT packets so holding a remote button causes only one clean action.
- Prints every received command byte in hex so any brand of IR remote can be mapped in seconds.
Operational Verification & Pin State Matrix
Input Signal vs. System Output Truth Table:
| Input / State | Pin / Signal | Detected Condition | Expected Output |
|---|---|---|---|
| Key 1 (0x45) | D2 NEC Frame | Turn ON Command | D8 LED = HIGH |
| Key 2 (0x46) | D2 NEC Frame | Turn OFF Command | D8 LED = LOW |
| Key OK (0x1C) | D2 NEC Frame | Toggle Command | Invert D8 LED State |
Engineering Troubleshooting Matrix
| Problem | Likely Cause | Diagnostic Check | Engineering Solution |
|---|---|---|---|
| Nothing prints in Serial Monitor when pressing keys | Dead remote battery, plastic tab still inserted, or reversed receiver power | View remote LED through smartphone camera while pressing | Remove battery tab / replace CR2025 cell and verify receiver pinout. |
| Prints 0x0 or UNKNOWN protocol | Loose signal jumper or ambient sunlight flooding receiver | Shade the receiver dome and retest at 30cm distance | Shield receiver from direct sunlight and check D2 connection. |
| Compilation error about IRrecv / decode_results | Mixing IRremote v2 syntax with v4 library | Check installed library version in IDE | Use IrReceiver.begin() and IrReceiver.decode() as shown above. |
Engineering Challenges & Upgrades
Take your build to the next level with these progressive engineering upgrades:
Map Volume + / Volume - keys to step a PWM LED on D9 up and down in 10% increments.
Require pressing keys 1-2-3-4 within 10 seconds to unlock a Green LED or SG90 servo.
Map keys 1–6 to switch Project 11 RGB LED between Red, Green, Blue, Cyan, Amber, and Rainbow.