22. Infrared Remote Control
Decode modulated infrared commands and map them to actions.
Learning outcomes
- Explain carrier modulation and protocols
- Verify receiver pinout
- Use IRremote 4.x
- Capture rather than assume remote commands
Parts and preparation
Uno, 38 kHz IR receiver module, compatible remote, and IRremote by shirriff / z3t0 / ArminJo (see Libraries box).
Before power: inspect wiring, confirm supply voltage and ensure all connected circuits share GND.
Libraries for this lesson
In Arduino IDE 2 open Tools → Manage Libraries…. Search by the Library Manager name and install the package by the exact author below. Similar names from other authors can use different APIs and will break the example.
| Include | Library Manager name | Author | Install note |
|---|---|---|---|
IRremote.hpp | IRremote | shirriff, z3t0, ArminJo | Install IRremote 4.x via Library Manager (maintainer Armin Joachimsmeyer). Older forks or 2.x examples use a different API. |
Infrared link
A remote flashes an infrared carrier in timed patterns. The receiver demodulates it into logic pulses. Protocols such as NEC define address and command formats.
Pinout caution
Receiver package pin order varies. Use the module labels or datasheet before applying power.
Versioned API
This course uses IRremote 4.x (Library Manager: IRremote by shirriff, z3t0, ArminJo) with IRremote.hpp and IrReceiver. Older online examples may use a different API.
Capture workflow
First print protocol/address/command from your own remote. Then map those captured command values to actions.
Wiring and safe build sequence

- Receiver VCC -> module-rated supply (commonly 5 V)
- GND -> GND
- OUT -> D2
Worked sketch
Download .ino sketch#include <IRremote.hpp>
const byte receivePin = 2;
void setup() {
Serial.begin(9600);
IrReceiver.begin(receivePin, ENABLE_LED_FEEDBACK);
}
void loop() {
if (IrReceiver.decode()) {
Serial.print("Protocol=");
Serial.print(getProtocolString(IrReceiver.decodedIRData.protocol));
Serial.print(" Command=0x");
Serial.println(IrReceiver.decodedIRData.command, HEX);
IrReceiver.resume();
}
}How the code works
- Command values are easier to map than copying arbitrary example raw codes.
- resume prepares the receiver for the next frame.
Test and record evidence
Practical evidence checklist
Common faults and checks
- Verify receiver pin order.
- Avoid direct sunlight or fluorescent interference.
- Confirm installed IRremote major version.
Check your understanding
Q1. Why capture your own codes?
Show answer
Commands vary between remote models.
Q2. What does IrReceiver.resume do?
Show answer
Re-arms reception for the next message.