Skip to content

ESP32_Relay_X4_Modbus_v1.3

Device Type:relay
Electrical Standard:global
Board:esp32
Difficulty:Plug-n-flash (2/5)

Product Description

This is a 4-relay board, having 4 binary inputs and an RS485 interface based on ESP32. The inputs are optoisolated (mine came with TLP785GB with 4.7k resistors on inputs, making it safe to operate them around max 24V), with a common ground, independent from the board’s main ground. The RS485 transceiver is a SP3485E. Connectors are detachable.

Manufacturer documentation

I bought it from AliExpress.

Product Images

ESP32_Relay_X4_Modbus_v1.3

GPIO Pinout

According to Tasmota discussion:

Function / SignalESP32 GPIOESP32 QFN PinDirectionConnected Hardware / Notes
RS485 TXGPIO19Pin 31OutputUART TX -> SP3485 DI
RS485 RXGPIO18Pin 30InputUART RX <- SP3485 RO
RS485 Driver EnableGPIO32Pin 8OutputSP3485 DE
RS485 Receiver EnableGPIO32Pin 8OutputSP3485 RE (active LOW)
Relay 1GPIO23Pin 37OutputRelay output 1
Relay 2GPIO5Pin 29OutputRelay output 2
Relay 3GPIO4Pin 26OutputRelay output 3
Relay 4GPIO13Pin 15OutputRelay output 4
Digital Input 1GPIO25Pin 10InputIN1
Digital Input 2GPIO26Pin 11InputIN2
Digital Input 3GPIO27Pin 12InputIN3
Digital Input 4GPIO33Pin 9InputIN4
Status LEDGPIO15Pin 23OutputUsually inverted
PAD_TX2GPIO17Pin 28..no PSRAM
PAD_RX2GPIO16Pin 27..no PSRAM
PDAD_G12GPIO12......
PDAD_G14GPIO14......
PDAD_G21GPIO21......
PDAD_G22GPIO22......

All pins are inverted. It also exposes GPIOs 12, 14, 21, 22 labeled appropriately on the board.

Basic Config

substitutions:
device_name: esp32-relay-x4_modbus-v1-3
esphome:
name: ${device_name}
esp32:
variant: esp32
framework:
type: esp-idf
logger:
baud_rate: 0
sensor:
- platform: uptime
name: Uptime
button:
- platform: restart
name: Reboot
- platform: safe_mode
name: Reboot in safe mode
# ==========================
# RELAYS (OUTPUTS)
# ==========================
switch:
- platform: gpio
pin:
number: 23
inverted: true
name: "Relay 1"
- platform: gpio
pin:
number: 5
inverted: true
ignore_strapping_warning: true
name: "Relay 2"
- platform: gpio
pin:
number: 4
inverted: true
name: "Relay 3"
- platform: gpio
pin:
number: 13
inverted: true
name: "Relay 4"
# ==========================
# INPUTS (BINARY SENSORS)
# ==========================
binary_sensor:
- platform: gpio
pin:
number: 25
inverted: true
name: "Input 1"
- platform: gpio
pin:
number: 26
inverted: true
name: "Input 2"
- platform: gpio
pin:
number: 27
inverted: true
name: "Input 3"
- platform: gpio
pin:
number: 33
inverted: true
name: "Input 4"
# ==========================
# EXTRA PADS (RX2/TX2)
# ==========================
- platform: gpio
pin:
number: 16
inverted: true
mode: INPUT_PULLUP
name: "Pad RX2 as input"
- platform: gpio
pin:
number: 17
inverted: true
mode: INPUT_PULLUP
name: "Pad TX2 as input"
# ==========================
# RS485 (MODBUS) UART
# ==========================
uart:
rx_pin: 18 # RS485 RX
tx_pin: 19 # RS485 TX
flow_control_pin: 32 # RS485 DE
baud_rate: 9600
# ==========================
# Status LED (system state)
# ==========================
status_led:
pin:
number: 15
inverted: true
ignore_strapping_warning: true