IR Sensors Explained: How Infrared Transmitters and Receivers Work

What Infrared Light Is and Why It’s Used for Communication

Infrared light sits just below visible red light on the electromagnetic spectrum, with wavelengths typically between 700 nm and 1 mm. The human eye can’t see it, but the physics are identical to visible light — it travels in straight lines, reflects off surfaces, and can be focused with lenses. That invisibility is precisely what makes it useful for communication: an IR remote control can flash thousands of times per second without producing any visible flicker.

IR communication is also cheap, reliable, and well-understood. The components involved — an IR LED on the transmitting side and a photodiode or phototransistor on the receiving side — cost pennies and require no radio frequency licensing. This combination makes IR the dominant technology for short-range, line-of-sight communication in consumer electronics: TV remotes, air conditioner controllers, camera triggers, robot sensors, and more all rely on the same fundamental principle.

The main limitation is that limitation is also a feature: IR communication requires a clear line of sight between transmitter and receiver. It doesn’t pass through walls or around corners, which means IR signals from one room don’t interfere with another room. In robotics and automation, this directionality is exploited deliberately — obstacle avoidance sensors emit IR and detect the reflection from nearby objects, and the signal only returns if something is physically in front of the sensor.

The 38 kHz Carrier Frequency — Why Modulation Matters

Here is the problem: the world is full of infrared light. Sunlight, incandescent bulbs, and fluorescent tubes all emit IR radiation continuously. If a receiver simply listened for any IR light, it would trigger constantly from ambient sources and be completely useless as a communication device.

The solution is modulation. Rather than shining the IR LED continuously, the transmitter switches it on and off at a specific frequency — typically 38 kHz (38,000 times per second). The receiver is tuned with a bandpass filter to respond only to IR light pulsing at that exact frequency. Steady-state ambient IR light produces no output. Only a genuine 38 kHz signal gets through.

This is the same principle used in radio communication — a carrier wave at a known frequency carries the actual data signal. In IR systems, the 38 kHz carrier is turned on and off in patterns that encode binary data. When the carrier is on (the LED is pulsing at 38 kHz), the receiver outputs LOW. When the carrier is off, the receiver outputs HIGH. The data is encoded in the timing of these on/off bursts, not in the raw light intensity.

38 kHz is the industry-standard choice because it represents a practical sweet spot: high enough to be easily filtered from DC ambient noise, low enough to be generated efficiently by a microcontroller without demanding excessive processing overhead. Some systems use 36 kHz or 40 kHz, but 38 kHz receivers will still respond adequately to signals within a few kHz either side.

The Transmitter Side — How an IR LED Encodes Data

An IR transmitter is fundamentally an LED — it just emits light at 940 nm (near-infrared) rather than in the visible spectrum. The IR transmitter module packages this LED with a current-limiting resistor and sometimes a driver transistor, making it straightforward to connect directly to a microcontroller output pin.

To transmit data, the microcontroller performs two tasks simultaneously:

  • Carrier generation: It toggles the IR LED pin at 38 kHz, producing the carrier frequency the receiver is tuned to detect.
  • Data encoding: It turns the carrier on and off in timing patterns that represent binary 0s and 1s according to whichever IR protocol is being used.

The result is a signal where “bursts” of 38 kHz pulses are separated by gaps of silence. The duration of each burst and each gap encodes the data. This is why IR communication is often described as pulse-distance or pulse-width encoding — the actual data is carried by time, not by amplitude or frequency variation.

On an oscilloscope, a transmitted IR signal looks like groups of rapid pulses (the carrier bursts) with varying-length quiet periods between them. The LED itself is switching on and off 38,000 times per second during each burst, but this happens so fast it appears as a solid block at normal oscilloscope time scales.

The Receiver Side — How a TSOP-Type Receiver Decodes It

The IR receiver module uses a TSOP-series (or equivalent) integrated circuit that combines a photodiode, amplifier, bandpass filter, demodulator, and output stage in a single three-pin package. This is not just a bare photodiode — it’s a complete signal processing chain in a tiny housing.

Here is what happens inside the receiver when an IR signal arrives:

  • Detection: The internal photodiode converts incoming IR photons into a small electrical current.
  • Amplification: A transimpedance amplifier boosts this tiny current to a measurable voltage.
  • Bandpass filtering: An internal filter passes only signals near 38 kHz, rejecting ambient IR and electrical noise at other frequencies.
  • Demodulation: The filtered signal is demodulated — the 38 kHz carrier is stripped away, leaving only the on/off pattern of the bursts.
  • Output: The output pin goes LOW during a carrier burst and HIGH during silence. This is the inverted, demodulated signal your microcontroller reads.

The output is active-low and logic-level compatible, meaning it can connect directly to any digital input pin on an Arduino or similar microcontroller. No additional amplification or level shifting is required. This is why TSOP-type receivers are so popular — a single chip does everything, and decoding the signal is purely a software task on the microcontroller side.

The NEC Protocol Explained

IR communication requires both sides to agree on a protocol — a set of rules for how bits are encoded, how a message starts and ends, and how the receiver knows when a valid signal has arrived. Many protocols exist (Sony SIRC, Philips RC-5, Samsung, Panasonic), but NEC is the most common in hobbyist electronics and is the default used by most Arduino remote controls you’ll encounter.

NEC Message Structure

An NEC transmission consists of the following elements in order:

  • Leader pulse: A 9 ms burst of 38 kHz carrier, followed by a 4.5 ms silence. This header allows the receiver to lock on and AGC (auto gain control) to stabilise before data begins.
  • 32 data bits: Transmitted in four 8-bit bytes: address, inverted address, command, inverted command. The inverted bytes are used for error checking — if address and ~address don’t sum to 0xFF, the message is discarded.
  • Stop bit: A final 562.5 µs burst to mark the end of the message.

How NEC Encodes 0s and 1s

NEC uses pulse distance encoding. Every bit starts with a 562.5 µs carrier burst. What follows determines the bit value:

  • Logic 0: 562.5 µs burst + 562.5 µs silence (total ~1.125 ms)
  • Logic 1: 562.5 µs burst + 1,687.5 µs silence (total ~2.25 ms)

A 1 takes three times as long as a 0. The receiving microcontroller measures the duration of each silence period after a burst and decides whether it received a 0 or 1. This is straightforward to implement in software and robust against slight timing variations.

Repeat Codes

When you hold down a button on a remote, the device shouldn’t receive 50 separate command transmissions. NEC handles this with a repeat code: after the initial full message, a 9 ms burst + 2.25 ms silence + stop bit is sent every ~108 ms for as long as the button is held. The receiving device interprets this as “continue the last command” without re-processing a full 32-bit frame.

Wiring the Transmitter and Receiver to Arduino

Both modules use a standard three-pin interface: VCC, GND, and signal. An Arduino Uno R3 provides the 5 V supply and digital I/O needed to drive both.

IR Transmitter Wiring

  • VCC → Arduino 5V
  • GND → Arduino GND
  • Signal → Arduino Digital Pin 3 (required by IRremote library for PWM output)

IR Receiver Wiring

  • VCC → Arduino 5V
  • GND → Arduino GND
  • Signal (OUT) → Arduino Digital Pin 11

Pin 3 is specified for the transmitter because the IRremote library uses Timer 2 on the Arduino Uno to generate the 38 kHz carrier via hardware PWM — this cannot be done on arbitrary pins. Pin 11 is also a Timer 2 pin; if you use a different receiver pin, update the library configuration accordingly. Check the IRremote documentation for pin assignments on other Arduino variants (Mega, Leonardo, Nano).

Add a 100 nF decoupling capacitor between VCC and GND on the receiver module if you experience erratic behaviour — TSOP receivers are sensitive to supply noise, and a small bypass capacitor close to the module significantly improves reliability.

Sending IR Signals with the IRremote Library

The IRremote library abstracts away all the timing and protocol complexity, letting you send and receive IR signals with a few lines of code. Install it via the Arduino Library Manager: go to Sketch → Include Library → Manage Libraries, search for IRremote by Armin Joachimsmeyer, and install the latest version.

Sending a NEC Code

#include <IRremote.hpp>

const int IR_SEND_PIN = 3;

void setup() {
  IrSender.begin(IR_SEND_PIN);
  Serial.begin(115200);
}

void loop() {
  // Send NEC code: address 0x00, command 0x45
  IrSender.sendNEC(0x00, 0x45, 0); // address, command, repeats
  Serial.println("Sent NEC: address 0x00, command 0x45");
  delay(2000);
}

The third argument to sendNEC() is the number of repeat frames to append — use 0 for a single transmission. To simulate holding a button, pass a positive number or call the function in a loop.

If you want to clone an existing remote, you first need to capture the address and command bytes from the original remote using the receiver sketch below. Once you have those values, you can retransmit them exactly, and the target device can’t distinguish your Arduino from the original remote.

Receiving and Decoding Remote Signals

The receiver sketch listens for incoming IR signals, decodes the protocol and data bytes, and prints the results to the Serial Monitor. This is the essential first step for any project involving an existing remote control.

#include <IRremote.hpp>

const int IR_RECEIVE_PIN = 11;

void setup() {
  Serial.begin(115200);
  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
  Serial.println("IR Receiver ready. Point a remote and press a button.");
}

void loop() {
  if (IrReceiver.decode()) {
    Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX);
    Serial.print("Protocol : ");
    Serial.println(IrReceiver.decodedIRData.protocol);
    Serial.print("Address  : 0x");
    Serial.println(IrReceiver.decodedIRData.address, HEX);
    Serial.print("Command  : 0x");
    Serial.println(IrReceiver.decodedIRData.command, HEX);
    Serial.println();

    IrReceiver.resume(); // Ready for next signal
  }
}

Point any IR remote at the receiver and press a button. The Serial Monitor will display the protocol (NEC, Sony, Samsung, etc.), the address byte, and the command byte. Record these values — they’re what you’ll pass into sendNEC() or the equivalent send function for your protocol when building a clone remote.

Decoding Multiple Buttons

To make a remote-controlled device respond differently to different buttons, use a switch statement on the command byte:

if (IrReceiver.decode()) {
  if (IrReceiver.decodedIRData.protocol == NEC) {
    switch (IrReceiver.decodedIRData.command) {
      case 0x45:
        Serial.println("Power button pressed");
        // Toggle an output, relay, LED, etc.
        break;
      case 0x46:
        Serial.println("Volume up");
        break;
      case 0x47:
        Serial.println("Volume down");
        break;
      default:
        Serial.println("Unknown command");
        break;
    }
  }
  IrReceiver.resume();
}

Replace the Serial.println calls with whatever actions you want — toggling a relay, adjusting a motor speed, changing an LED colour, or sending data over serial to another device.

Project Ideas

Once you have reliable transmit and receive working, a wide range of projects become accessible. Here are three that cover different use cases and difficulty levels.

Universal Remote Clone

Capture the address and command bytes from every button on one or more existing remotes using the receiver sketch. Store them in arrays in your Arduino sketch. Add a small keypad or a set of push buttons, and map each button to a stored IR code. The result is a programmable universal remote that can control any device whose codes you’ve captured — TVs, air conditioners, projectors, smart plugs, and anything else that uses IR.

IR-Controlled Robot

Pair an IR receiver on a mobile robot with a cheap TV remote. Map the directional buttons (up, down, left, right on the remote’s navigation cluster) to motor forward, reverse, left turn, and right turn commands. Add volume buttons for speed control. This approach costs far less than a dedicated RF remote system and requires no pairing or frequency configuration — point and control.

Beam-Break Alarm or Trip Wire

Mount the IR transmitter on one side of a doorway or corridor and the receiver directly opposite. The transmitter continuously sends a 38 kHz signal; the receiver outputs LOW while the beam is intact. When someone walks through and breaks the beam, the receiver output goes HIGH and the Arduino can trigger an alarm, start a timer, increment a counter, or send a notification. Unlike passive IR (PIR) motion sensors, a beam-break sensor has a precisely defined trigger zone and responds instantly — it’s ideal for counting objects on a production line, timing laps on a race track, or securing a specific entry point.

Going Further with IR Sensors

IR transmitter and receiver pairs are among the most versatile components in the Arduino ecosystem — cheap, well-documented, and applicable to a remarkable breadth of projects. The IR transmitter module and IR receiver module cover both sides of the communication link, and together with an Arduino Uno, you have everything needed to capture, decode, and retransmit IR signals from any remote control.

From here, natural next steps include exploring other IR protocols (Sony SIRC, Philips RC-5) to understand how protocol design tradeoffs work, combining IR control with other modules (motor drivers, relay boards, LCD displays) to build more complete systems, and using the beam-break technique with multiple transmitter/receiver pairs to create 2D sensing grids. The physics are simple; the applications are not.

Leave a Reply

Your email address will not be published. Required fields are marked *