[Solution] ESP32 Infrared WiFi Module (ESP32E-N4 Infrared Transmitter Receiver) - Correct Pinout for ESPHome

Hi everyone,

I wanted to share the correct configuration for a common “Generic ESP32 IR Shield” (often sold as ESP32E-N4 Infrared Transmitter Receiver NEC or similar on AliExpress).

Most online documentations and even some silk-screen prints on the PCB are incorrect regarding the IR Receiver pin.

After some troubleshooting and multimeter testing, here is the working pinout for this specific board revision (WROOM-32E):

  • IR Receiver: GPIO14 (Inverted) – Note: Many guides say GPIO5, which is wrong for this board
  • IR Transmitter: GPIO4
  • Hardware Power: GPIO21 (Crucial: This pin must be HIGH to provide power to the IR components)

Working ESPHome Configuration:

# Hardware Power Management (Necessary for this board to power IR LEDs/Receiver)
switch:
  - platform: gpio
    pin: GPIO21
    id: ir_power_21
    name: "IR System Power"
    restore_mode: ALWAYS_ON

remote_transmitter:
  pin: GPIO4
  carrier_duty_percent: 50%

remote_receiver:
  pin:
    number: GPIO14
    inverted: true
  dump: all

# Optional: Setup as a Proxy for Home Assistant
infrared:
  - platform: ir_rf_proxy
    name: "IR Proxy Transmitter"
    remote_transmitter_id: ir_tx
  - platform: ir_rf_proxy
    name: "IR Proxy Receiver"
    remote_receiver_id: ir_rx

Hi @balu79,

I have the same board, but I’m having trouble connecting to it.
Can you give a brief rundown on how you connected to the board to flash esphome to it?

Thanks.

Steve…

Yes, that was another problem which I was fighting in the beginning. Couldn’t get the connection via USB working, ended up connecting it to my Wifi and then uploaded the firmware via Wifi connection (with the help of Home Assistant and ESPHome Device Builder)

Just for curiosity, how you orient it to get good rx/tx since it has fixed components at 90deg…?

Yes, I think that could be a problem, but for my own setup that didn’t really matter (sender and receiver are pretty close and for that it didn’t matter too much). Not sure how that would behave in other scenarios and what the best orientation and solution to that would be.

Stupid design to my opinion, they could have left the component legs out for orientation.

Hi @balu79,

thanks for your guide on this IR module! I am struggling with the same issue regarding the initial flash. You mentioned that you ended up connecting it to your Wi-Fi and then uploaded the firmware via Wi-Fi.

When I try to upload my ESPHome .bin file through the device's web portal, I keep getting an 'Update Failed: Wrong Magic Byte' error. Did you use a specific configuration in your YAML (like a specific board or framework) to make the binary compatible with the original web portal, or did you bypass the portal in some other way?

Thanks for your help!

Hi Nils,
I don't fully remember anymore but I think I haven't used any webportal for flashing the firmware but instead used the ESPHome Device Builder for that after connecting the board to Wifi. The board type I defined as esp32dev and framework as esp-idf. I can share with you my full yaml code from ESPHome Device Builder if needed / helpful.

Good luck,
Bastian

Hello,
I also thought that I was supposed to build up a config in ESPHOME and export it as a “factory image” bin file, which was supposed to be uploaded via the boards built in webui server.
Of course, this gave me the same error as @ngehlich mentioned: ‘Update Failed: Wrong Magic Byte’.
The idea is @balu79, after I connect the board to WIFI, my home assistant/ESPHOME never shows it as a “discovered” item; thus, I’m not sure how to apply the way you did it ("instead used the ESPHome Device Builder for that after connecting the board to Wifi") in my case.
Lastly, now that it has an IP, which I’ve identified and I’m able to ping, can I reach any config UI on it? Or if i want to have the initial management (config wifi via 192.168.4.1), is there a way to reset the board to factory settings?
Thank you, Mihai.

I think the key part for me was to add wifi details into my ESPHome Device Builder config as the following:

wifi:
ssid: “your-ssid”
password: “your-password”
use_address: your-esp-ip-adress

hey, just got one of these as well. can you share any details about how to ota over wifi? it’s connected to my network and has an ip address but i can’t find any open ports on it to upload the firmware nor does my esphome dashboard recognize it. i’m really confused and the aliexpress listing is not much help either.

update: also tried the “update” feature on a second device which i didn’t connect to my wifi and getting the “wrong magic byte” error too

Sharing my esphome config which allowed my esphome device builder to recognize the board and to upload this config. Make sure to change SSID, password and IP in this config and to connect the ESP device to Wifi first.

esphome:
  name: ir-proxy-esp32e-n4
  friendly_name: IR Proxy ESP32E-N4
  name_add_mac_suffix: true

esp32:
  board: esp32dev
  framework:
    type: esp-idf

# To be able to get logs from the device via serial and api.
logger:

# API is a requirement of the dashboard import.
api:
  id: api_id

ota:
  - platform: esphome
    id: ota_esphome

wifi:
  ssid: "YourWifiName"
  password: "YourWifiPassword"
  use_address: TheIPofYourESP
  # Set up a wifi access point using the device name above
  ap:

# In combination with the `ap` this allows the user
# to provision wifi credentials to the device.
captive_portal:

network:
  enable_ipv6: true

# Hardware Power Management (necessary for this board)
switch:
  - platform: gpio
    pin: GPIO21
    id: ir_power_21
    name: "IR System Power"
    restore_mode: ALWAYS_ON

remote_transmitter:
  pin: GPIO4
  carrier_duty_percent: 50%
  id: ir_tx
  rmt_symbols: 256

remote_receiver:
  id: ir_rx
  pin:
    number: GPIO14
    inverted: true
  rmt_symbols: 256
  dump: all
  
infrared:
  # IR transmitter instance
  - platform: ir_rf_proxy
    name: "IR Proxy Transmitter"
    id: ir_proxy_tx
    remote_transmitter_id: ir_tx
  # IR receiver instance
  - platform: ir_rf_proxy
    name: "IR Proxy Receiver"
    id: ir_proxy_rx
    remote_receiver_id: ir_rx

Sharing some of my experiences with the same ESP32 version of this module.

  • The “stock” firmware is not ESPHome based and its some odd custom firmware that isn’t very intuitive.
  • It will start and broadcast its IR-WIFI AP. If you connect to it (suggest with a desktop), you can access its webbrowser at 19.168.4.1. The webserver allows you to enter your own WiFi credentials - DO NOT DO THIS.
  • If you set your own WiFi within the stock firmware config, it will reboot and connect but no webserver will be listening so you can’t connect to it or change anything.
  • To reset the stock firmware, apply power with a jumper between the RX and TX pins connected. This will reset it back to stock and will broadcast the IR_WIFI SSID again.

Create your ESPHome firmware. I used this script which is similar to others above but I enabled the local webserver to make debugging easier. Set your WiFi credentials and then save.

esphome:
  name: ir-proxy-esp32e-n4
  friendly_name: IR Proxy ESP32E-N4
  name_add_mac_suffix: false

esp32:
  board: esp32dev
  framework:
    type: esp-idf

# To be able to get logs from the device via serial and api.
logger:

# API is a requirement of the dashboard import.
api:
  id: api_id

ota:
  - platform: esphome
    id: ota_esphome
  - platform: web_server

wifi:
  ssid: YourWiFiSSID
  password: yourpassword
  # Set up a wifi access point using the device name above
  ap:

# In combination with the `ap` this allows the user
# to provision wifi credentials to the device.
captive_portal:

web_server:
  port: 80
  
network:
  enable_ipv6: true

# Hardware Power Management (necessary for this board)
switch:
  - platform: gpio
    pin: GPIO21
    id: ir_power_21
    name: "IR System Power"
    restore_mode: ALWAYS_ON

remote_transmitter:
  pin: GPIO4
  carrier_duty_percent: 50%
  id: ir_tx
  rmt_symbols: 256

remote_receiver:
  id: ir_rx
  pin:
    number: GPIO14
    inverted: true
  rmt_symbols: 256
  dump: all
  
infrared:
  # IR transmitter instance
  - platform: ir_rf_proxy
    name: "IR Proxy Transmitter"
    id: ir_proxy_tx
    remote_transmitter_id: ir_tx
  # IR receiver instance
  - platform: ir_rf_proxy
    name: "IR Proxy Receiver"
    id: ir_proxy_rx
    remote_receiver_id: ir_rx

Now to create the first working firmware to flash onto the stock firmware, click Install → Advanced Options → Download firmware binary.

After it compiles, then choose the “OTA Update” version to download to your PC. This version is required to flash onto the stock IR_WIFI. If you try the “Factory Image” option you’ll get the “incorrect magic byte” error.

Once its downloaded, then you can use your PC to attach to IR_WIFI. Browse to 192.168.4.1. Go to the “update” option and upload the firmware file you downloaded above. The stock firmware should apply the new image and reboot.

You now should have a real ESPHome firmware and it can now be discovered by HomeAssistant and brought in as a device.

For future updates you can either deploy direct in ESPHomeBuilder (it will see the matching device once provisioned) or you can attach to the new ESPHome based webserver on your network and update there.

This link had some information that helped me out, specifically the RX/TX bridge reset.

One final note: I was never able to get the device to connect serial over USB for debugging/flashing. So WiFi flashing was my only successful method. I suspect that the boot button normally on these devices is one of the pins on the header, but I’ve not confirmed that yet. More information on the serial connectivity here. Summary is that USB-C connector is just for power. For serial access, the RX/TX lines are required to a USB adapter back to your PC. Jumpering IOO to ground should force the bootloader.

Good luck!

Thanks for the advise in this Feed, specifically on the GPIO pins and power setting. worked well.
I had no problemn wit the USB serial flashing of the board. Just applied the jumper GND and IOO pins and powered up board via serial device. Flashed first time. Note already had my wifi ID etc in ESPHome