ESP8266 IR Receiver Module Project

The ESP8266 IR Receiver Module project showcases how to integrate an IR receiver module with an ESP8266 microcontroller to decode and interpret infrared signals from remote controls or other IR sources. The IR receiver captures incoming infrared signals, decodes them, and outputs the decoded information including the IR code, protocol, and bit details to the Serial Monitor.

How It Works

An IR receiver module such as the VS1838B — sold on carriers as the KY-022 — is far more than a photodiode. Inside the three-pin black package sits a photodiode, an amplifier, a 38 kHz band-pass filter, a demodulator and a comparator with automatic gain control.

That filter chain is the whole point. Sunlight, incandescent bulbs and fluorescent tubes all flood a room with infrared, and a bare photodiode would be saturated by it. By responding only to light flickering at 38 kHz, the module ignores every steady or mains-frequency source. What appears on the output pin is the demodulated bitstream: the carrier has already been stripped away.

The output idles HIGH and pulls LOW during a burst. Decoding means measuring the durations of those LOW and HIGH periods and matching them against a protocol such as NEC, Sony SIRC or RC5 — which is exactly what the IRremote library does.

Components Needed

  • ESP8266 (NodeMCU)
  • IR Receiver Module (e.g., TSOP38238)
  • Jumper Wires
  • Power Supply

Wiring to the ESP8266 (NodeMCU)

Connect OUT to D5, VCC to the 3.3 V rail and GND to ground. The VS1838B runs anywhere from 2.7 V to 5.5 V, so it is one of the few modules equally at home on 3.3 V and 5 V boards.

Pin order is the usual trap. Facing the domed front of the package with the legs downward, the order is typically OUT, GND, VCC — but carriers vary and some reverse it. Reversing VCC and GND will overheat the part, so check the silkscreen before powering up.

A 100 nF capacitor across VCC and GND close to the module suppresses supply noise, which otherwise shows up as spurious decodes when a motor or relay switches.

Module pinESP8266 (NodeMCU) pinFunction
OUT / SD5Demodulated data, idles HIGH
VCC3V3Supply (2.7–5.5 V)
GNDGNDCommon ground

Build and Upload

Aim an IR remote control towards the IR receiver module.

Press buttons on the remote to send IR signals.

Observe the Serial Monitor for the decoded IR code, protocol type, and bit details.

Example Code

Capturing and identifying remote codes with the IRremote library. Upload it with the board set to ESP8266 (NodeMCU) and open the Serial Monitor at 115200 baud.

Capturing and identifying remote codes with the IRremote library
#include <IRremote.hpp>

const int IR_RECEIVE_PIN = 5;

void setup() {
  Serial.begin(115200);
  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
  Serial.println("Point a remote at the receiver and press a key");
}

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

    IrReceiver.resume();   // ready for the next frame
  }
}

Applications

A infrared receiver module turns up in a wide range of projects. These are the uses where it is the right choice rather than a compromise:

  • Remote control for robots, lighting and motorised blinds
  • Capturing an existing remote so a project can replay its codes
  • Universal remote hubs bridging WiFi or Bluetooth to IR appliances
  • Menu navigation on projects that have a display but no buttons
  • Presence detection in combination with an IR emitter across a doorway

Working with the ESP8266 (NodeMCU)

The ESP8266 (NodeMCU) is built around the ESP8266 and runs on 3.3 V logic with roughly 80 KB usable of SRAM and 4 MB on most NodeMCU boards of program flash. These details change how this circuit is wired and what the sketch can do, so they are worth stating plainly before you build.

The ESP8266 is a 3.3 V part and is not 5 V tolerant — feeding a 5 V sensor output straight into a GPIO can damage the chip. Use a divider or level shifter.

There is only one ADC channel, so reading several analog sensors needs an external multiplexer such as a CD4051 or an ADS1115.

D3 (GPIO0), D4 (GPIO2) and D8 (GPIO15) are strapping pins sampled at boot; holding them at the wrong level stops the board starting.

Built-in WiFi means the same sketch can publish readings to a dashboard without extra hardware.

ESP8266 (NodeMCU) characteristicValueWhy it matters here
Logic voltage3.3 VSensor outputs above this level need a divider or level shifter
ADC resolution10-bit (0–1023)Sets how finely an analog reading can be resolved
Analog inputsa single analog channel, A0Determines how many analog sensors can share the board
PWM outputsany GPIO via software PWMNeeded for brightness, speed and tone control
I²C pinsD2 (SDA, GPIO4) and D1 (SCL, GPIO5) by defaultFixed by hardware — wiring copied from another board may not match
Interrupt pinsany GPIO except D0 (GPIO16)Required for counting fast or asynchronous events
Serialone hardware UART plus a transmit-only second portMonitor runs at 115200 baud by default

Troubleshooting

Most problems with this module fall into a handful of categories. Work through these before suspecting the part itself:

  • Nothing decodes — VCC and GND are probably swapped; check the module is not getting warm.
  • The first press decodes but repeats come out as 0x0 — that is the NEC repeat frame, which is normal. Treat it as "same key still held".
  • Codes arrive only within a few centimetres — the remote battery is weak, or a bright lamp is desensitising the AGC.
  • Random codes appear with no remote present — a switching power supply or PWM-driven LED nearby is modulating near 38 kHz.
  • Decoding works but is unreliable while motors run — add the 100 nF decoupling capacitor and keep motor wiring away from the signal lead.
  • The sketch compiles but the board resets or behaves erratically — a 5 V module output is being driven into a 3.3 V pin. Measure the signal before connecting it.
  • Readings differ from an Arduino tutorial for the same part — the 10-bit ADC returns 0–1023, not 0–1023, so any constant copied from an Uno example needs rescaling.

Taking It Further on the ESP8266 (NodeMCU)

Once the basic reading works, where you go next depends very much on which board you are using. These are the directions that suit the ESP8266 (NodeMCU) specifically:

The obvious extension on an ESP8266 is to stop printing to Serial and publish instead. A few lines using ESP8266WiFi and an HTTP client will push each reading to a dashboard such as ThingSpeak, or to an MQTT broker for home automation.

Running an onboard web server turns the board into its own display: serve a small HTML page that fetches the latest reading over AJAX, and any phone on the network becomes the instrument panel.

For battery operation, deep sleep is essential — the ESP8266 draws around 70 mA with WiFi active but under 20 µA asleep. Wire D0 (GPIO16) to RST so the board can wake itself, take a reading, publish and sleep again.

Notes and Practical Limits

The module output is already demodulated, so it must be read as a digital signal — connecting it to an analog pin and calling analogRead() is a common and fruitless mistake.

Any GPIO on this board can serve as the receive pin, since all of them support interrupts.