Differences

This shows you the differences between two versions of the page.

Link to this comparison view

iothings:proiecte:2025sric:esp32-ir-hub [2025/04/24 02:27]
petru.zincenco [YS-IRTM Module Details]
iothings:proiecte:2025sric:esp32-ir-hub [2025/05/21 03:03] (current)
petru.zincenco [Images]
Line 4: Line 4:
   * **Author**: Petru Zincenco  ​   * **Author**: Petru Zincenco  ​
   * **Master**: IA  ​   * **Master**: IA  ​
 +  * **Date Completed**:​ 21 May 2025  ​
  
 ===== Introduction ===== ===== Introduction =====
-I am creating this project ​because I already have a Home Assistant ​server running ​on 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.+This project ​extends an existing ​Home Assistant ​setup (on Raspberry Pi 4) to control ​IR‐only devices ​via an ESP32 acting as an IR transceiver, ​and to monitor indoor temperature and humidity. We use the YS-IRTM module to sniff and replay ​NECprotocol commands, and a DHT11 sensor to read environment ​data every 30 minutes. All IR commands and sensor readings are exposed in Home Assistant ​as entities.
  
 ===== General Description ===== ===== General Description =====
 ==== Block Diagram ==== ==== Block Diagram ====
-{{ :​iothings:​proiecte:​2025sric:​logicaldiagram.png?​nolink&​600 |}}+{{ :​iothings:​proiecte:​2025sric:​diagrama_2_.png?​nolink&​700 |}}
  
 ==== Modules and Interactions ==== ==== Modules and Interactions ====
-  * **Home Assistant Server** (Raspberry Pi 3)   +  * **Home Assistant Server** (Raspberry Pi 4)   
-    - Connected to local Wi-Fi. ​  +    - Runs ESPHome ​add-on ​for firmware management, API, MQTT and OTA.   
-    - Hosts ESPHome for firmware management. ​  +    - Receives IR command events and sensor data from ESP32, exposes them as switches and sensors.   
-    - Manages the 3 lights directly.   +  * **ESP32 IR & Sensor ​Hub**   
-  * **ESP32 IR Hub**   +    - Connects over Wi-Fi (static IPto Home Assistant via ESPHome native API.   
-    - Connects ​back to Home Assistant ​over Wi-Fi (API/MQTT).   +    - Interfaces via UART (irSerial.begin at 9600, SERIAL_8N1) on GPIO 22 (RX) and GPIO 23 (TX) with YS-IRTM.   
-    - Controls the YS-IRTM ​module via UART.  ​+    - Reads DHT11 sensor on GPIO 21 every 30 minutes.  ​
   * **YS-IRTM IR Emitter/​Receiver Module**  ​   * **YS-IRTM IR Emitter/​Receiver Module**  ​
-    - 38 kHz carrier, NEC-protocol.   +    - 38 kHz carrier, ​hardware-decode for NEC frames only.   
-    - Controls the Air Conditioner ​and Audio System via infrared signals  ​+    ​Outputs 3-byte payloads on receive; accepts 5-byte payloads to transmit  
 +  * **DHT11 Temperature & Humidity Sensor** ​  
 +    - Reads temperature ​and humidity on GPIO 21; data logged every 30 minutes.
  
 ===== Hardware Design ===== ===== Hardware Design =====
 ==== Parts List ==== ==== Parts List ====
- +  ​ESP32 development board – 46 RON 
-  ​4-channel 3.3 V ↔ 5 V level-shifter ​– 11 RON   +{{ :​iothings:​proiecte:​2025sric:​esp32.png?​nolink&​150 |}}   
-  * YS-IRTM IR emitter/​receiver module (38 kHz) – 22 RON   +  * YS-IRTM IR emitter/​receiver module (38 kHz, NEC) – 22 RON 
-  * ESP32 development board – 46 RON  ​+{{ :​iothings:​proiecte:​2025sric:​ys-irtm.png?​nolink&​150 |}} 
 +  * DHT11 sensor module – 15 RON 
 +{{ :​iothings:​proiecte:​2025sric:​dht11.png?​nolink&​150 |}}   
 +  * 4-channel 3.3 V ↔ 5 V level shifter ​– 11 RON 
 +{{ :​iothings:​proiecte:​2025sric:​lvconvertor.png?​nolink&​150 |}}  
   * Jumper wires and breadboard  ​   * Jumper wires and breadboard  ​
 +**Total cost:** ≈ 94 RON  ​
  
-**Total cost:** 79 RON +==== Connections and Wiring ==== 
- +  * **YS-IRTM Module**   
-==== Schematics and Signal Diagrams ==== +    - LVCC → 3.3 V (ESP32) ​  
- +    ​- ​HVCC → 5 V (ESP32) ​  
-{{ :​iothings:​proiecte:​2025sric:​diagramaelectrica.png?​nolink&​600 |}} +    ​- ​GND → ESP32 GND   
- +    - TXD → level shifter → ESP32 GPIO 22 (RX)   
-==== Connections and Wiring ​Diagram ​==== +    - RXD ← level shifter ← ESP32 GPIO 23 (TX)   
- +  * **DHT11 Sensor**   
-  * **LVCC** → 3.3 V   +    - VCC → 5 V (ESP32  
-  * **HVCC** → 5 V   +    - GND → ESP32 GND   
-  * **GND** → ESP32 GND   +    - DATA → ESP32 GPIO 21   
-  * **TXD** (module) → level shifter ​→ ESP32 RX   +  * **IR LED & Driver**   
-  * **RXD** (module) ​← level shifter ← ESP32 TX  +    - IR LED anode → 5 V via resistor → transistor → ESP32 GPIO (configured by module) ​  
 +    - Common GND for all devices ​ 
  
 ===== Software Design ===== ===== Software Design =====
 +==== Environment & Components ====
 +  * **ESPHome** (YAML-based) for Wi-Fi, API, MQTT, OTA.  ​
 +  * **`uart`** on GPIO 22/23 at 9600 baud, SERIAL_8N1.  ​
 +  * **`remote_receiver`** + **`remote_transmitter`** for YS-IRTM NEC frames.  ​
 +  * **`dht`** sensor component on GPIO 21, update_interval:​ 1800 s.  ​
 +  * **Custom `text_sensor`** lambda to parse 3-byte NEC payloads into HA events.
  
-==== Development Environment and Libraries ​====+==== Receive Handling ​==== 
 +  1. YS-IRTM decodes NEC IR and emits 3 bytes over UART.   
 +  2. ESPHome buffers 3 bytes, then publishes an MQTT/state update (`ir_hub/​last_command`). ​  
 +  3. Home Assistant sensor template splits into user-code and command.
  
-  * **ESPHome** (YAML-based configurationOTA updatesHome Assistant integration)   +==== Transmit Handling ==== 
-  ​* **Micropython-YS-IRTM** examples for UART-based ​NEC IR transceiving ​  +  1. HA invokes `switch.ir_send_<​device>​_<​cmd>​`. ​  
-  ​* `uart` component ​on TX/RX GPIOs for communicating with the YS-IRTM module ​  +  2. ESPHome ​writes 5-byte payload ​(Addr: 0xA1, F1: 0xF1, UC HighUC LowCmdto UART.   
-  * `remote_receiver` component for decoding NEC pulses into codes   +  ​3. YS-IRTM ​emits NEC frame (9 ms mark, 4.5 ms space, data bits 562 µs @38 kHz).   
-  * `remote_transmitter` component for keying a 38 kHz carrier according to NEC timing  ​+  ​4. Module replies 0xF1 on success; ESPHome retries once after 1 s if no ack.
  
-==== YS-IRTM Module Details ​====+==== Sensor Handling ​==== 
 +  * DHT11 on GPIO 21 is read every 30 minutes. ​  
 +  * Temperature and humidity values are published to Home Assistant as `sensor.inside_temperature` and `sensor.inside_humidity`.  ​
  
-{{ :​iothings:​proiecte:​2025sric:​ys-irtm.png?​nolink&​300 ​|}}+===== Known IR Codes ===== 
 +^ Function ​      ^ NEC Code    ^ 
 +| Power On/​Off ​   | 01 FE 04     | 
 +| Mute            | 01 FE 09     | 
 +| Volume Down     | 01 FE 05     | 
 +| Volume Up       | 01 FE 06     |
  
-  * Integrated dual 38 kHz 940 nm IR LED emitter and TSOP-style demodulator receiver with onboard MCU handling modulation/​demodulation and UART.   +===== Images ===== 
-  * 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. ​  +===== Images ===== 
-  * 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. ​  +Hardware setupESP32, YS-IRTM module ​and DHT11 sensor wired on the breadboard and powered on
- +{{ :iothings:​proiecte:​2025sric:fizic.jpeg?​nolink&​700 |}} 
-==== Transmit Protocol ​==== +ESP32 in Home Assistant UIThe ESP32 entity and exposed IR switches and sensor values displayed on the HA dashboard
- +{{ :​iothings:​proiecte:​2025sric:esp_ha.png?​nolink&​700 |}} 
-  * **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  +Inside Temperature GraphLogged DHT11 readings showing temperature variations over time
-  * **NEC Framing:**   +{{ :iothings:proiecte:​2025sric:​temperatura.png?​nolink&​700 |}} 
-    * **Leader:** 9 ms carrier-ON, 4.5 ms carrier-OFF  ​ +Inside Humidity GraphLogged DHT11 readings showing humidity fluctuations ​over time
-    * **Data:** 32 bits LSB first, each bit = 562.5 µs carrier + 562.5 µs space (0) or 1.6875 ms space (1)  ​ +{{ :​iothings:​proiecte:​2025sric:​umiditate.png?​nolink&​700 |}} 
-    * **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:**   +
-    - `remote_receiver` measures incoming demodulated pulse lengths to reconstruct NEC codes (address + ¬address + command + ¬command)  +
-    - On complete frame, publishes three data bytes (address, command, data) via UART.   +
-  * **Transmit Path:**   +
-    - `remote_transmitter` configures a hardware PWM at 38 kHz and keys it on/off per NEC timing based on bytes received ​over UART  +
-    - Splits longer payloads into 3-byte chunks with address headers, resending on NACK or timeout +
  
 ===== Results ===== ===== Results =====
 +All NEC remotes in the stereo system are learned and replayed via Home Assistant. Indoor temperature and humidity are logged every 30 minutes and available in HA dashboards. OTA updates allow wireless firmware management.
  
-===== Conclusions ​=====+===== Future Improvements (Brief) ​===== 
 +  * Add direct IR raw capture and transmit to support non-NEC devices.
  
 ===== Download ===== ===== Download =====
 <​html><​a class="​media mediafile mf_pdf"​ href="?​do=export_pdf">​Download PDF</​a></​html>​ <​html><​a class="​media mediafile mf_pdf"​ href="?​do=export_pdf">​Download PDF</​a></​html>​
- 
-===== Journal ===== 
- 
-===== Bibliography/​Resources ===== 
  
iothings/proiecte/2025sric/esp32-ir-hub.1745450850.txt.gz · Last modified: 2025/04/24 02:27 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