Infrared remote control with ESP8266 for ioBroker via MQTT

With a NodeMCU ESP8266, an infrared LED and an IR receiver, we can build an MQTT-connected remote that learns a signal from a handheld remote and sends it again on request. We tested it with a TV and an air conditioner on real hardware. In this guide, we will wire up the two-way IR bridge, configure it and try it step by step.

Difficulty: Intermediate

Technically reviewed: October 2026

Board used: NodeMCU ESP8266

One remote, two directions

When we ask it to learn, the ESP8266 listens to the handheld remote through its IR receiver and sends the recognized code to the MQTT broker. Later, it can transmit a command in the same format through its IR LED. The ESP8266 does not yet give codes names or store them permanently. Checking, naming and saving them can become the ioBroker side of a later project.

  • Learning: handheld remote → IR receiver → ESP8266 → irReceive MQTT topic.
  • Sending: irSend MQTT topic → ESP8266 → IR LED → target device.

We tried both directions with a TV and an air conditioner: the bridge learned their remotes’ signals and, when it sent them back, both devices responded. Those two tests were successful; they do not mean that every remote or IR protocol will automatically work.

What we need

  • a NodeMCU ESP8266 board, USB cable and Arduino IDE;
  • an infrared LED and a 220 Ω series resistor;
  • a demodulating IR receiver whose supply voltage and output level are suitable for the ESP8266’s 3.3 V input;
  • a local Wi-Fi network, an MQTT broker and two configured ioBroker MQTT data points;
  • a handheld remote and the device we want to control.

Our tested software setup used ESP8266 Arduino core 3.1.2, IRremoteESP8266 2.9.0 and PubSubClient 2.8. In the Arduino IDE, we selected the NodeMCU v2/ESP-12E board. Check the sources of IRremoteESP8266 and PubSubClient by name: similarly named IR libraries can have different APIs.

Wiring

ComponentNodeMCUNote
IR LED anodeD2 / GPIO4Put the 220 Ω series resistor between D2 and the anode.
IR LED cathodeGNDCommon ground for the transmitter.
IR receiver OUTD5 / GPIO14The receiver’s signal wire.
IR receiver GNDGNDA common ground is required.
IR receiver VCC3V3, if this receiver supports itCheck the exact pin order and supply voltage in the module’s datasheet.

The series resistor limits current through the IR LED, protecting both the LED and the ESP8266 output. Always check the datasheets for your particular LED and receiver module: 220 Ω is the value used in our tested circuit, not a universal choice for every part. Never feed a signal higher than 3.3 V into an ESP8266 input.

Check before connecting power: VCC, GND and OUT are not always in the same order on different IR receivers and modules. Use the markings or datasheet for your own part rather than another receiver’s photo.

NodeMCU ESP8266 with an IR LED on D2 through a 220-ohm series resistor and an IR receiver on D5
Wiring the ESP8266 IR transmitter and receiver; check the pinout of your particular receiver in its datasheet

Preparing the Arduino sketch

The download contains the complete esp8266-ir-mqtt-bridge.ino sketch and an unfilled secrets.example.h configuration template. The sketch works the same way for either language; the ZIP below is the tested package also used by the Hungarian page.

  1. Extract the ZIP and open the sketch in the Arduino IDE.
  2. In the sketch folder, copy secrets.example.h to a new file named secrets.h.
  3. In your copy, enter the Wi-Fi and MQTT connection details and the actual topic names for irSend and irReceive. The test/... names in the template are only examples.
  4. Install the library versions listed above, select the NodeMCU board, then compile and upload the sketch.
  5. Open Serial Monitor at 115200 baud.

Passwords and network safety: do not upload, include in the ZIP or share your filled-in secrets.h file. This example uses unencrypted MQTT. Try it only on a trusted, isolated local network; do not expose it directly to the internet.

Understanding the MQTT messages

The sketch uses two topics. We send commands to irSend; the learned signal comes back on irReceive. These are descriptive names, not mandatory ioBroker identifiers. Enter the MQTT topic names actually used by your setup in secrets.h.

irSend valueWhat does the ESP8266 do?
READYAllows new commands after a connection.
LEARNListens for up to 30 seconds and forwards the first complete, recognized, non-repeat IR frame to the MQTT broker.
CANCELCancels learning.
IR1,PROTOCOL,BITS,HEXTransmits the specified supported IR command.

An IR1 record can look like this: IR1,COOLIX,24,B2BF50. With the air-conditioner remote used in our test, B2BF50 meant power on/cooling at 23 °C, while B27BE0 meant power off. These are examples from that particular remote, not universal air-conditioner codes. For the TV, too, use the record learned from your own remote instead of guessing its HEX value.

For a long air-conditioner message, the HEX field is not necessarily one number of 64 bits or less: it can contain the bytes of a state array supplied by the library. The sketch builds this format for us. Do not send a raw timing sequence copied from Serial Monitor or another IR library as an IR1 record.

Let’s learn and send a signal

  1. After startup, wait for Wi-Fi and MQTT to connect. Even after Serial Monitor reports the subscription, the bridge is still waiting for READY.
  2. Send a fresh READY message to the irSend topic, followed by LEARN. Do not mark these commands as retained MQTT messages.
  3. Point the handheld remote at the receiver and briefly press the chosen button once. An IR1,... record should appear on irReceive.
  4. Note which button and device the record belongs to. After checking it, send that same record to irSend.
  5. Watch the actual device. A successful MQTT message alone does not prove that the TV or air conditioner performed the command.

During our tests, this complete sequence worked with both the TV and the air conditioner: the bridge recognized and forwarded each remote’s signal, and the target devices responded when it sent the codes back. Some air-conditioner remotes send their entire desired state with every button press. Temperature, mode and fan setting may therefore change together; always check the full effect on the device before saving a code.

The learned IR1 record in the ioBroker irReceive data point
The first complete, recognized IR signal has reached the MQTT broker

What does the program do behind the scenes?

At startup, the ESP8266 initializes its IR receiver and IR LED transmitter, then connects to Wi-Fi and the MQTT broker. If the connection drops, it retries. After reconnecting, it requires a fresh READY command so that an older stored irSend value does not immediately trigger an action.

LEARN remains active for at most 30 seconds. The program discards overflowed, unknown and repeat frames, then converts only the first acceptable signal into an IR1 record. While transmitting, it briefly disables its own receiver so that it does not “learn” the signal from its own LED.

The learned signal is held only temporarily in the ESP8266’s memory. The sketch tries to publish it to irReceive, but it does not build a code library of its own. MQTT’s send result alone does not confirm that ioBroker processed the message, so check the actual data point as well. In a future teachable-remote project, ioBroker can validate, name and save the codes.

If something does not work

  • No Wi-Fi or MQTT connection: check the details in secrets.h, the broker address and the topic names. Send a fresh READY again after reconnecting.
  • No code after LEARN: check the receiver’s pinout, 3.3 V compatibility and D5 signal wire. Try bringing the handheld remote closer, but avoid placing it almost against the receiver.
  • “Unknown”, repeat or overflow: this sketch will not save that frame. Try a different button and a short press. Some long, complex air-conditioner signals may need different receiver settings or more memory.
  • A code was learned, but the device does not respond: check the IR LED’s polarity, the 220 Ω resistor and where the LED is pointing. A flash seen through a phone camera is only a clue; it does not prove that the protocol or carrier frequency is correct.
  • The learned code disappears after a restart: that is expected in this version. We will build persistent code storage on the server side later.

Where can we take it next?

We now have a working two-way foundation. A separate next project is the ioBroker side of a teachable remote: checking an incoming signal, assigning it a useful name, storing it safely and sending it back through irSend later. We could also build an ioBroker VIS 2 interface or a web app. That would let us add other remotes alongside the TV and air conditioner, but we should save only codes we have actually checked.


← More Arduino / ESP Examples and Projects