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)
  • `uart` component on TX/RX pins at 9600 baud to interface with the YS-IRTM’s TTL serial
  • `text_sensor` (custom lambda) for buffering and parsing incoming 3-byte payloads into HA events
  • `remote_transmitter` declared (IR modulation offloaded to module’s 38 kHz carrier engine)

Implemented Algorithms and Structures

Receive Handling

  • YS-IRTM demodulates 38 kHz IR, decodes NEC frames internally, then emits three data bytes (User Code High, User Code Low, Command) over UART upon each valid command
  • ESPHome listens on UART, accumulates up to three bytes in a small buffer, then fires an MQTT/state update and resets the buffer
  • NEC repeat frames are suppressed by the module; ESPHome can apply further debouncing or grouping if needed

Transmit Handling

  • To transmit, ESP32 sends a five-byte payload via `uart.write`:
    1. Address byte (default `0xA1`)
    2. Command byte `F1` (`0xF1`, trigger TX)
    3. Data byte 1 (NEC User Code High)
    4. Data byte 2 (NEC User Code Low)
    5. Data byte 3 (NEC Command)
  • The module appends the inverse of the command byte automatically and generates a full NEC frame with a 9 ms leading mark, 4.5 ms space, 562 µs mark/space per bit, and final mark at 38 kHz
  • On success, YS-IRTM replies over UART with the command byte (`0xF1`); silence indicates a bad payload
  • ESPHome waits (e.g. 1000 ms) for the ack and can retry transmission if no response arrives

Results

Conclusions

Download

Journal

Bibliography/Resources

iothings/proiecte/2025sric/esp32-ir-hub.1745452819.txt.gz · Last modified: 2025/04/24 03:00 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