An IR receiver is a specialized optoelectronic module that detects modulated infrared light pulses, filters out ambient noise, and demodulates the signal into a clean digital logic output for a microcontroller. In a real circuit, this component fundamentally changes a chaotic, ambient-flooded analog photon stream into a crisp 3.3V or 5V digital square wave, completely offloading the need for software-based bandpass filtering from your microcontroller's CPU. The most common mistake hobbyists make is confusing a 3-pin demodulating IR receiver module with a raw 2-pin IR photodiode; the former outputs decoded logic pulses ready for an Arduino or ESP32, while the latter just passes raw analog current that requires complex external amplification and comparator circuits.
The Anatomy of a Demodulating IR Receiver
When you buy a standard 3-pin IR receiver (like the ubiquitous black epoxy teardrop packages), you are not just buying a light sensor. You are buying a highly integrated analog-to-digital signal processing chain packed into a single silicon die. Understanding this chain explains why these modules behave the way they do on the bench.
1. PIN Photodiode: Converts 940nm infrared photons into a tiny analog current.
2. Preamplifier & AGC (Automatic Gain Control): Boosts the weak signal. If a remote is held too close, the AGC drops the gain to prevent saturation; if it is far away, it boosts it.
3. Bandpass Filter: A hardware filter tuned strictly to a specific carrier frequency (usually 38kHz), rejecting 50/60Hz mains hum and DC sunlight.
4. Demodulator & Integrator: Strips away the high-frequency carrier, leaving only the baseband data envelope.
5. Output Transistor: An open-collector or push-pull stage that pulls the data pin to ground when a burst is detected.
Because of the AGC and bandpass filter, a demodulating IR receiver expects pulsed light. If you shine a continuous, unmodulated 940nm LED directly at it, the receiver's AGC will interpret the massive signal as ambient noise, ramp down its gain, and output nothing. It requires a carrier frequency to function.
The Math Behind the 38kHz Carrier and NEC Protocol
To understand how an IR receiver talks to a microcontroller, we have to look at the math of the carrier frequency and the data protocol. The vast majority of consumer remotes use a 38kHz carrier frequency paired with the NEC protocol.
Here is the worked numeric example of what the receiver actually sees when you press a button:
- The Carrier: The remote's LED blinks on and off 38,000 times per second. The period of one single wave cycle is
1 / 38,000 = 26.31µs. - The Data Burst: Under the NEC protocol, a logical '0' is transmitted as a 562.5µs burst of light, followed by a 562.5µs space (darkness).
- The Cycle Count: During that 562.5µs burst, the receiver's internal bandpass filter counts the incoming waves.
562.5µs / 26.31µs = 21.38 cycles.
The receiver's demodulator sees roughly 21 carrier cycles, recognizes this as a valid burst (and not random noise), and pulls its output pin LOW for exactly 562.5µs. When the light stops, the pin returns HIGH. Your microcontroller simply measures the length of the LOW and HIGH states using an interrupt or a library like IRremoteESP8266 to reconstruct the binary data.
Where You Meet IR Receivers in Practice
While we mostly associate IR receivers with living room televisions, they show up across a wide variety of DIY and commercial installations:
- DIY HVAC Control: Ductless mini-split systems (like Mitsubishi and Daikin) use IR receivers mounted on the indoor blower head. Hobbyists frequently use an ESP32 with an IR receiver to reverse-engineer these protocols for Home Assistant integration.
- Media Center PCs & Amplifiers: Custom audio racks use 38kHz receivers wired to a Raspberry Pi running LIRC (Linux Infrared Remote Control) to trigger volume macros.
- IR Break-Beams (With a Catch): While raw photodiodes are better for high-speed industrial counting, demodulating IR receivers are sometimes used for slow-speed security tripwires because the 38kHz modulation completely ignores sunlight and room lighting changes.
Decision Tree: Selecting Your Exact IR Receiver Part
Not all IR receivers are identical. They vary by carrier frequency, logic voltage, and minimum burst length. Use this decision matrix to pick the exact part number for your workbench.
| Application / Target Remote | MCU Logic Level | Carrier Freq | Recommended Part Number |
|---|---|---|---|
| Standard TV/Audio (NEC, RC5, RC6) | 5V (Arduino Uno/Mega) | 38kHz | Vishay TSOP38238 |
| Standard TV/Audio (NEC, RC5, RC6) | 3.3V (ESP32, Pi Pico) | 38kHz | Vishay TSOP4838 |
| Sony SIRC Remotes | 5V or 3.3V | 40kHz | Vishay TSOP38240 |
| Some older Air Conditioners | 5V | 56kHz | Vishay TSOP38256 |
| Budget/Prototyping (Amazon/eBay kits) | 3.3V - 5V | 38kHz | VS1838B (Generic clone) |
Wiring the TSOP38238: Decoupling and Hardware Gotchas
The most frequent cause of 'failing' IR circuits on the bench is ignoring the manufacturer's power supply decoupling requirements. Microcontrollers like the ESP32 and ATmega328P draw spiky, transient current when switching GPIO pins or transmitting WiFi. This creates high-frequency ripple on the 5V or 3.3V rail.
Because the IR receiver's internal preamplifier has massive gain, it amplifies this power rail ripple, mistakes it for an incoming optical signal, and triggers its AGC to mute the sensor. The result is a receiver that works perfectly when powered by a clean bench supply, but fails randomly when wired directly to an Arduino's 5V pin.
The Mandatory RC Filter:
According to the Vishay datasheet, you must isolate the receiver's VCC pin from the microcontroller's noisy rail:
- Place a 100Ω to 220Ω resistor in series between the MCU's VCC and the IR Receiver's VCC pin.
- Place a 4.7µF to 10µF electrolytic capacitor directly between the IR Receiver's VCC pin and GND.
- Keep the capacitor leads as short as possible, physically touching the receiver pins if prototyping on a breadboard.
Troubleshooting FAQ: Why Your IR Signal is Dropping
My remote works on the TV, but the Arduino serial monitor shows no data.
Cause: Logic level mismatch or inverted signal expectations.
Fix: Verify your receiver's VCC rating. If you are using a TSOP38238 (rated for 4.5V-5.5V) on a 3.3V ESP32, it will brown out and fail to decode. Switch to a TSOP4838. Additionally, remember that Vishay receivers output HIGH when idle and pull LOW on a burst. Ensure your attachInterrupt() is set to FALLING or CHANGE, not RISING.
The receiver works indoors, but fails completely near a window.
Cause: Sunlight saturation. Direct sunlight contains massive amounts of broadband infrared radiation. While the 38kHz bandpass filter blocks the DC component of sunlight, the sheer intensity can physically saturate the PIN photodiode's junction capacitance, blinding it.
Fix: Ensure you are using a 940nm IR LED on your transmitter, not an 850nm LED (850nm is closer to visible light and more heavily present in solar radiation). Add a physical optical filter (a piece of dark red/black acrylic) over the receiver lens, or recess the receiver deep inside a 3D-printed shroud to limit its field of view to the direct line of sight.
I am getting random, garbage hex codes in my serial output.
Cause: Fluorescent or CFL lighting interference. Electronic ballasts in older fluorescent tubes switch at frequencies that can generate harmonics near 38kHz.
Fix: Use a receiver with integrated AGC suppression for continuous noise, such as the Vishay TSOP series (avoid unbranded 'VS1838' clones from cheap kits, which often lack proper AGC tuning). Shielding the signal wire between the receiver and the MCU with a grounded braided shield also prevents the wire from acting as an antenna for EMI.






