This is an old revision of the document!


ESP32 Infrared Remote

Metadata

  • Author: Petru Zincenco
  • Master: IA

Introduction

I am creating this project because I already have a Home Assistant server running on a Raspberry Pi 3, and I want to extend its capabilities to control my stereo system and air conditioner via IR. By turning an ESP32 into an IR transceiver, I can sniff existing NEC-protocol remote commands, replay them, and even send arbitrary data over IR directly from my phone through Home Assistant.

General Description

Block Diagram

Modules and Interactions

  • Home Assistant Server (Raspberry Pi 3)
    1. Connected to local Wi-Fi.
    2. Hosts ESPHome for firmware management.
    3. Manages the 3 lights directly.
  • ESP32 IR Hub
    1. Connects back to Home Assistant over Wi-Fi (API/MQTT).
    2. Controls the YS-IRTM module via UART.
  • YS-IRTM IR Emitter/Receiver Module
    1. 38 kHz carrier, NEC-protocol.
    2. Controls the Air Conditioner and Audio System via infrared signals

Hardware Design

Parts List

  • 4-channel 3.3 V ↔ 5 V level-shifter – 11 RON
  • YS-IRTM IR emitter/receiver module (38 kHz) – 22 RON
  • ESP32 development board – 46 RON
  • Jumper wires and breadboard

Total cost: 79 RON

Schematics and Signal Diagrams

Connections and Wiring Diagram

  • LVCC → 3.3 V
  • HVCC → 5 V
  • GND → ESP32 GND
  • TXD (module) → level shifter → ESP32 RX
  • RXD (module) ← level shifter ← ESP32 TX

Software Design

Development Environment and Libraries

  • ESPHome (YAML-based configuration, OTA updates, Home Assistant integration)
  • Micropython-YS-IRTM examples for UART-based NEC IR transceiving
  • `uart` component on TX/RX GPIOs for communicating with the YS-IRTM module
  • `remote_receiver` component for decoding NEC pulses into codes
  • `remote_transmitter` component for keying a 38 kHz carrier according to NEC timing

YS-IRTM Module Details

  • Integrated dual 38 kHz 940 nm IR LED emitter and TSOP-style demodulator receiver with onboard MCU handling modulation/demodulation and UART.
  • On receive, the module outputs TTL-level pulses over TXD representing NEC-encoded bursts (9 ms leader + 32 bits) which the ESP32 times to reconstruct address/command words.
  • On transmit, the module accepts a UART frame of five bytes and generates a keyed 38 kHz IR carrier: a 9 ms AGC burst, 4.5 ms space, 32 bits of 562.5 µs bursts with 562.5 µs (0) or 1.6875 ms (1) spaces, plus a final 562.5 µs burst.

Transmit Protocol

  • Payload Structure: Five-byte UART frame: (Address, Command, Data 1, Data 2, Data 3). The module automatically appends the inverse of the Command as the fourth byte in the IR frame.
  • NEC Framing:
    • Leader: 9 ms carrier-ON, 4.5 ms carrier-OFF
    • Data: 32 bits LSB first, each bit = 562.5 µs carrier + 562.5 µs space (0) or 1.6875 ms space (1)
    • Trailer: 562.5 µs burst to mark end-of-frame
    • Repeat: on long key-press, a 9 ms burst + 2.25 ms space + 562.5 µs burst every ~108 ms
  • UART Confirmation: Module echoes back the Command byte on successful IR send; no reply indicates invalid payload

Implemented Algorithms and Structures

  • Receive Path:
    1. `remote_receiver` measures incoming demodulated pulse lengths to reconstruct NEC codes (address + ¬address + command + ¬command).
    2. On complete frame, publishes three data bytes (address, command, data) via UART.
  • Transmit Path:
    1. `remote_transmitter` configures a hardware PWM at 38 kHz and keys it on/off per NEC timing based on bytes received over UART.
    2. Splits longer payloads into 3-byte chunks with address headers, resending on NACK or timeout.

Results

Conclusions

Download

Journal

Bibliography/Resources

iothings/proiecte/2025sric/esp32-ir-hub.1745450764.txt.gz · Last modified: 2025/04/24 02:26 by petru.zincenco
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0