An IR remote control is a handheld wireless transmitter that uses modulated pulses of infrared light to send digital command codes to a receiver circuit. When you press a button on the remote, you aren't just closing a simple electrical switch; you are triggering an onboard microcontroller to generate a specific serial bitstream, modulating it at a high frequency, and firing it through a 940nm photodiode. This article breaks down the exact protocol theory, the math behind the pulses, and how to interface these signals with modern microcontrollers like the ESP32.

The Anatomy of an IR Command: Carrier vs. Data

If you point an IR remote at a digital camera or smartphone lens and press a button, you will see the LED flashing. However, to the naked eye, it appears completely dark. This is because the LED emits light at a 940nm wavelength, which sits just outside the visible spectrum. But the real engineering trick isn't the invisibility; it is the modulation.

Think of modulation like rapidly chopping a flashlight beam on and off. If you just turned an IR LED on and off to represent 1s and 0s (baseband signaling), ambient sunlight or incandescent bulbs would easily drown out your signal with their own broadband infrared noise. To solve this, the remote flashes the LED at a specific carrier frequency—almost universally 38kHz in consumer electronics. The receiver is tuned with a bandpass filter to ignore everything except light pulsing at exactly 38,000 times per second.

A Worked Numeric Example: The NEC Protocol

The carrier frequency is just the transport mechanism. The actual command is encoded in the envelope of those pulses using a protocol like NEC, RC5, or Sony SIRC. Let us look at the exact timing math for the ubiquitous NEC IR Protocol, which uses pulse-distance encoding.

  • Leader Code (Sync): A 9ms pulse followed by a 4.5ms space. This wakes up the receiver's automatic gain control (AGC).
  • Logical '0': A 562.5µs pulse followed by a 562.5µs space (1.125ms total bit time).
  • Logical '1': A 562.5µs pulse followed by a 1687.5µs space (2.25ms total bit time).

A standard NEC frame consists of an 8-bit address, an 8-bit logical inverse of the address (for error checking), an 8-bit command, and an 8-bit inverse command. That is 32 bits of data. If you transmit a logical '1', the microcontroller must hold the 38kHz carrier burst for exactly 562.5 microseconds, turn the LED off for 1687.5 microseconds, and then proceed to the next bit.

Where You Meet This In Practice

In a real circuit or installation, an IR system changes a direct, hardwired mechanical switch matrix into an optically isolated serial data link. Instead of routing physical copper wires from a wall switch to a relay, the transmitter converts the button press into a demodulated digital bitstream. The receiver module handles the heavy lifting of stripping away the 38kHz carrier.

The most common receiver you will encounter on the bench is the Vishay TSOP38238. This tiny three-pin module contains a PIN photodiode, a preamplifier, and an internal bandpass filter. When it detects the 38kHz carrier, its output pin pulls LOW. When the carrier stops (the "space" in the protocol), the output pin pulls HIGH via an internal pull-up resistor.

Bench Tip: The output of a standard IR receiver module is inverted. A physical burst of IR light results in a logic LOW on the receiver's data pin. If you are feeding this into a microcontroller's UART RX pin or setting up a GPIO interrupt, you must configure your firmware to trigger on the FALLING edge, or invert the signal in software.

You will meet this technology in HVAC mini-split systems, consumer AV racks, motorized projector screens, and DIY home automation builds where running a physical control wire through drywall is impractical.

Real-World Scenario: Cloning a Mini-Split AC Remote

TV remotes are easy, but air conditioner remotes are notoriously difficult to clone. Unlike a TV remote that sends a short 32-bit command every time you press "Volume Up," an AC remote transmits the entire state of the unit (temperature, fan speed, swing mode, power state) in a massive 64-bit to 100+ bit payload every time you press any button.

The Setup

I needed to automate a Daikin mini-split AC using an ESP32 DevKit v1 and a TSOP38238 receiver. Because AC payloads are so long (often taking 300ms+ to transmit), standard software-based pulse-timing libraries often fail due to Wi-Fi interrupt latency dropping pulses. Instead, I used the ESP32's hardware RMT (Remote Control Transceiver) peripheral.

The Numbers

  1. The ESP32 RMT peripheral is clocked at 80MHz, giving a tick resolution of 12.5ns.
  2. I configured the RMT receiver channel to trigger on both rising and falling edges, capturing the exact microsecond duration of every pulse and space into a hardware FIFO buffer.
  3. The captured Daikin frame consisted of 142 individual pulse/space pairs, totaling roughly 315ms of transmission time.

The Outcome and What Went Wrong

The capture phase worked perfectly. I mapped the raw RMT buffer into an array and wrote a replay script. However, when I transmitted the signal back through a standard 5mm 940nm IR LED, the AC unit ignored it completely.

What went wrong: I had wired the IR LED directly to the ESP32's GPIO pin with a 100Ω current-limiting resistor. An IR LED has a forward voltage of about 1.2V and requires 100mA to 200mA of peak current to achieve the range needed to cross a living room. The ESP32 GPIO can only safely source about 40mA. The heavy current draw caused the GPIO voltage to sag, which distorted the 38kHz square wave into a messy, rounded triangle wave. The AC's strict receiver AGC rejected the noisy carrier.

The Fix: I added a 2N2222 NPN transistor. The ESP32 GPIO drove the base of the transistor through a 1kΩ resistor, and the transistor switched the IR LED directly from the 5V rail with a 22Ω collector resistor, delivering a clean 150mA peak pulse. The AC unit responded instantly.

IR vs. RF and Bluetooth: Clearing Up Common Confusion

People commonly confuse IR with RF (Radio Frequency) and Bluetooth remotes, assuming all "wireless" remotes operate on the same physics. They also frequently confuse the 38kHz carrier frequency with the actual data baud rate (which in the NEC protocol is roughly 1.2 kilobaud). Here is how they actually compare in a real installation.

FeatureIR (Infrared)RF (433MHz / 2.4GHz)Bluetooth (BLE)
Line of SightStrictly required (bounces off walls poorly)Not required (passes through drywall)Not required (passes through walls)
InterferenceHigh from direct sunlight / incandescent bulbsHigh from neighboring garage doors / Wi-FiLow (uses adaptive frequency hopping)
Power Draw (Tx)Very High (100mA+ LED pulses)Moderate (10-30mA RF PA)Low (sleep-heavy BLE advertising)
Typical Use CaseLine-of-sight AV, HVAC, cheap toysGarage doors, ceiling fans, smart blindsHigh-security locks, complex smart home hubs

If you are wiring a ceiling fan in a room where the receiver will be hidden inside a metal canopy, IR will fail because the metal blocks the light. You must use RF or BLE in that scenario.

Frequently Asked Questions

Can I use a standard 940nm IR LED as a receiver?

Technically, yes. A photodiode and an LED share similar semiconductor physics, and an IR LED will generate a tiny microvolt current when hit by IR light. However, without the integrated preamplifier and 38kHz bandpass filter found in a dedicated module like the TSOP38238, the signal-to-noise ratio is abysmal. You will spend more time writing complex DSP filtering code than it costs to just buy a $0.50 dedicated receiver module.

Why does my TV remote work through a mirror but not a window?

Standard glass windows are often treated with low-emissivity (Low-E) coatings or tinting designed specifically to block infrared light to keep heat out of your house. A mirror, on the other hand, reflects the 940nm wavelength almost perfectly. You can use a mirror to bounce an IR signal around a corner, effectively creating a poor man's IR blaster extender.

What happens if two IR remotes are pressed at the exact same time?

The 38kHz carrier waves will physically collide in the air, causing phase interference and garbling the pulse-distance timing envelopes. The receiver's internal AGC will become confused by the overlapping leader codes, and the microcontroller will fail the checksum validation (like the 8-bit logical inverse check in the NEC protocol). The command will simply be dropped, which is why you sometimes have to press a button twice in a crowded living room.