Unit D - Sensors & Buses

22. Infrared Remote Control

Decode modulated infrared commands and map them to actions.

Estimated time 3 hours

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.

IncludeLibrary Manager nameAuthorInstall note
IRremote.hppIRremoteshirriff, z3t0, ArminJoInstall IRremote 4.x via Library Manager (maintainer Armin Joachimsmeyer). Older forks or 2.x examples use a different API.
Infrared Remote Control instructional connection diagram
Open the diagram for a larger view. Trace every connection before building.

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

Breadboard wiring for lesson 22: Infrared Remote Control
Breadboard layout for this lesson. Match colours and pins before powering the circuit. Click the image for a larger view.
  1. Receiver VCC -> module-rated supply (commonly 5 V)
  2. GND -> GND
  3. OUT -> D2
Power rule: switch off before moving wires. Arduino I/O pins are control signals; high-current loads require a driver and suitable external supply.
#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

  1. Command values are easier to map than copying arbitrary example raw codes.
  2. resume prepares the receiver for the next frame.

Test and record evidence

Expected result: Each remote press prints its protocol and command value.

Practical evidence checklist

Common faults and checks
  • Verify receiver pin order.
  • Avoid direct sunlight or fluorescent interference.
  • Confirm installed IRremote major version.
Extension challenge: Capture three commands and use them to set an RGB LED to three colors.

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.