ESP8266 IR Transmitter Sensor Project

The ESP8266 IR Transmitter Sensor project demonstrates how to use an ESP8266 microcontroller with an IR LED to transmit infrared signals. This setup allows the ESP8266 to send commands to devices that are controlled via IR, such as TVs, air conditioners, and other consumer electronics. By encoding and emitting IR signals, the ESP8266 can replicate remote control functionality.

How It Works

An infrared transmitter module such as the KY-005 carries a 940 nm IR LED. It is the sending half of the remote-control link that every television uses, and on the ESP8266 (NodeMCU) it lets a project imitate a remote handset.

Consumer IR does not simply switch the LED on and off. The data is modulated onto a 38 kHz carrier: a logical mark is a burst of 38 kHz flashes, a space is darkness. Receivers are tuned to that carrier and ignore anything else, which is how a remote works in a sunlit room. Because sunlight and fluorescent lamps carry no 38 kHz component, they are filtered out.

On top of the carrier sits a protocol that defines how long marks and spaces encode bits. NEC is the most common: a 9 ms leading burst, a 4.5 ms space, then 32 bits where a one and a zero differ by space length. Sony SIRC, RC5 and Samsung variants all differ in timing, which is why libraries ask which protocol to send.

Components Needed

  • ESP8266 (NodeMCU)
  • IR LED
  • Jumper Wires
  • Power Supply

Wiring to the ESP8266 (NodeMCU)

Connect S to D5, the middle pin to the 3.3 V rail and − to GND. The IRremote library takes over a hardware timer to generate the 38 kHz carrier, and that timer dictates which pin can be used — on the ESP8266 (NodeMCU) the library's default output pin is the safe choice.

The KY-005 includes a series resistor sized for roughly 20 mA, giving a useful range of two to three metres. For longer range, drive the LED through a transistor at higher current; IR LEDs tolerate large pulsed currents because the duty cycle is low.

Aim matters more than power. IR LEDs have a beam angle of about 20–30°, so pointing the emitter at the receiver gains more range than increasing current.

Module pinESP8266 (NodeMCU) pinFunction
S (signal)D5Carrier output — must be a PWM-capable pin
Middle3V3Supply
− (GND)GNDCommon ground

Example Code

Sending an NEC remote code with the IRremote library. Upload it with the board set to ESP8266 (NodeMCU) and open the Serial Monitor at 115200 baud.

Sending an NEC remote code with the IRremote library
#include <IRremote.hpp>

const int IR_SEND_PIN = 5;

void setup() {
  Serial.begin(115200);
  IrSender.begin(IR_SEND_PIN);
  Serial.println("IR transmitter ready");
}

void loop() {
  // NEC: 16-bit address, 8-bit command, no repeats
  IrSender.sendNEC(0x0102, 0x34, 0);
  Serial.println("sent NEC 0x0102 / 0x34");
  delay(2000);
}

Applications

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

  • Replacing a lost remote control for a television, projector or air conditioner
  • Scheduling appliances — turning a projector off automatically at a set time
  • Short-range one-way data links between two microcontrollers
  • Home-automation bridges that convert WiFi commands into IR commands
  • Line-of-sight triggers for cameras and lighting rigs

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 happens — capture the original remote first with a receiver module; guessing the protocol rarely works.
  • Range is under a metre — the LED is current-starved, or the emitter is not aimed at the target.
  • It works at 20 cm but not across the room — drive the LED through a transistor rather than straight from a GPIO.
  • The code sends but the appliance ignores it — many devices need the frame repeated two or three times.
  • IR LEDs emit no visible light. To confirm the LED is firing, view it through a phone camera, which sees 940 nm as a faint purple flicker.
  • 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

Always capture before you transmit. Point the original remote at a VS1838B receiver, record the protocol and value the library reports, then replay exactly that. This turns guesswork into a two-minute job.

On a 3.3 V board the LED current is lower than on a 5 V Arduino for the same resistor, so expect shorter range. A transistor driver fed from 5 V restores it.