DIYables ESP32 RS485 Modbus 4 Channel Relay Module

Development BoardsFor ESP32Relays
$29.99
Final price shown on Amazon
Buy on Amazon
ESP32 RS485 Modbus relay module top view showing WiFi module 4 relay channels and terminal blocks Click to zoom
ESP32 RS485 Modbus relay module top view showing WiFi module 4 relay channels and terminal blocksProgrammable ESP32 relay board features: ESP32 module with WiFi and Bluetooth, 4 relays 10A 250VAC, NO COM NC terminals, RS485 A B, 9-24V DC input, 4 optocoupler inputs, BOOT and EN buttons, USB Type-C with CH340ESP32 RS485 Modbus relay module back view showing NO COM NC screw terminals RS485 A B and IN1 to IN4 optocoupler inputsESP32 RS485 Modbus relay module angled view showing USB Type-C port relay modules and terminal blocksESP32 relay board applications: relays switch lamps, fans, pumps, valves, door locks and alarms, optocoupler inputs monitor switches, sensors, PLC outputs and machine status contactsArduino IDE sample code for the ESP32 relay board: turn relay 1 on and off from a web browser over WiFi, select ESP32 Dev Module and upload over USB Type-CFactory Modbus RTU firmware: RS485 wiring to a PLC, HMI or PC, slave address 1, 115200 baud 8N1, function codes 01 05 0F and quick HEX commandsESP32 relay board pin mapping: relays on GPIO23 GPIO5 GPIO4 GPIO13, inputs IN1 to IN4 on GPIO25 GPIO26 GPIO27 GPIO33, RS485 on GPIO19 GPIO18 GPIO32, UART2 on GPIO17 GPIO16ESP32 relay board circuit: block diagram, PC817 relay driver with SS8050 transistor and flyback diode, PC817 isolated input with pull-up to GPIO25ESP32 relay board dimensions: 93 x 87 mm PCB with four 4 mm mounting holes, 85 g

Quick Overview

The DIYables ESP32 RS485 Modbus Relay Module is a programmable ESP32 board with real-world control built in: 4 relay outputs, 4 optocoupler-isolated inputs, and an RS485 port, plus WiFi and Bluetooth, all on one 93 x 87 mm board. Program it just like any ESP32 development board, in Arduino IDE (board: ESP32 Dev Module), PlatformIO, ESP-IDF, or MicroPython, and upload over the Type-C port through the built-in CH340 chip. No extra programmer is needed.

The 4 relay outputs switch high-voltage loads, up to 10A at 250VAC or 10A at 30VDC, such as lamps, fans, pumps, valves, and contactors, through NO, COM, and NC screw terminals. The 4 optocoupler inputs, IN1 to IN4, let your code monitor switches, sensors, PLC outputs, or the status contacts of machines, while the optocouplers keep the field wiring electrically isolated from the ESP32.

The board also comes with factory firmware. Out of the box it works as a Modbus RTU slave, so a PLC, an HMI, or any Modbus master can switch the relays over RS485 with no programming (address 1, 115200 bps, 8N1). Uploading your own program replaces this firmware, and you can bring it back at any time: download the factory firmware file or its source code from this page and upload it again.

Ideal for industrial automation, home automation, PLC expansion, Modbus RTU control systems, MQTT and Home Assistant relay control, and any project that needs reliable relay switching and isolated inputs over RS485, WiFi, or Bluetooth.

Key Features

  • Programmable ESP32 Board — Works like any ESP32 development board: write your own code in Arduino IDE (ESP32 Dev Module), PlatformIO, ESP-IDF, or MicroPython, with 2.4 GHz WiFi and Bluetooth built in
  • 4 Relay Outputs for High-Voltage Loads — SRD-05VDC-SL-C relays switch up to 10A 250VAC or 10A 30VDC, such as lamps, fans, pumps, valves, and contactors, each with NO, COM, and NC screw terminals and a status LED
  • 4 Optocoupler-Isolated Inputs — IN1 to IN4 use PC817 optocouplers and an isolated input ground to monitor switches, sensors, PLC outputs, or machine status contacts safely
  • Factory Modbus RTU Firmware Included — Ready to use out of the box as a Modbus RTU slave (address 1, 115200 bps, 8N1), so a PLC, HMI, or Modbus master can switch the relays over RS485 with no programming
  • Restore the Factory Firmware Anytime — Download the factory firmware file and its Arduino source code from this page and upload them again whenever you want the Modbus function back
  • One-Click Upload over Type-C — Built-in CH340 USB-to-serial chip with automatic BOOT and EN control, so uploads start without pressing any button
  • Protected RS485 Port — SP3485 transceiver with SM712 TVS protection and a 120Ω termination resistor across the A and B terminals
  • 9-24V DC Wide Input — On-board TPS54331 buck converter runs the board from 9-24V DC; the Type-C port can also power it for development
  • Extra Serial Port and GPIO Headers — 4-pin UART2 header (TX2, RX2, GND, 5V) and 4 spare pins (GPIO22, GPIO21, GPIO14, GPIO12), with GPIO22 and GPIO21 ready for I2C
  • Status LEDs — Power LED, USB serial RX/TX LEDs, one LED per relay, and one LED per input for easy monitoring and debugging
  • Versatile Applications — Industrial automation, home automation, Modbus RTU systems, PLC expansion, and IoT relay control

SPECIFICATION

Specification Value
Product Type Programmable ESP32 RS485 Modbus Relay Module
Microcontroller ESP32 (2.4 GHz WiFi + Bluetooth)
Compatibility Arduino IDE (ESP32 Dev Module), PlatformIO, ESP-IDF, MicroPython
Factory Firmware Modbus RTU slave, address 1, 115200 bps, 8N1 (restorable from this page)
Relay Outputs 4 channels, NO, COM, NC per channel
Relay Model SRD-05VDC-SL-C (5V coil)
Relay Load Rating 10A 250VAC / 10A 125VAC / 10A 30VDC / 10A 28VDC
Relay Driver PC817 optocoupler and SS8050 transistor per channel
Isolated Inputs 4 (IN1 to IN4), PC817 optocouplers, isolated input ground
RS485 Transceiver SP3485, SM712 TVS protection, 120Ω termination resistor
Modbus Function Codes 01, 05, 0F (factory firmware)
Serial Port Chip CH340
Programming Interface USB Type-C with automatic BOOT and EN control
Communication RS485, UART (3.3V header), WiFi, Bluetooth
Power Supply 9-24V DC screw terminal or 5V USB Type-C
Voltage Regulators TPS54331 buck converter (5V), AMS1117 (3.3V)
Buttons EN (reset), BOOT (GPIO0)
Indicators Power, RX and TX, 4 relay LEDs, 4 input LEDs
Dimensions 93 x 87 mm
Weight 85 g
Mounting Holes 4, 4 mm diameter
Package Quantity 1 piece
Applications Industrial automation, home automation, Modbus RTU, PLC expansion, IoT relay control

PIN MAPPING

Function ESP32 GPIO Notes
Relay 1 GPIO23 LOW = relay ON
Relay 2 GPIO5 LOW = relay ON
Relay 3 GPIO4 LOW = relay ON
Relay 4 GPIO13 LOW = relay ON
Input IN1 GPIO25 Reads LOW when the input is active
Input IN2 GPIO26 Reads LOW when the input is active
Input IN3 GPIO27 Reads LOW when the input is active
Input IN4 GPIO33 Reads LOW when the input is active
RS485 RX GPIO18 UART1
RS485 TX GPIO19 UART1
RS485 Direction GPIO32 HIGH = transmit, LOW = receive
Serial Port 2 TX2 GPIO17 UART2, 3.3V logic
Serial Port 2 RX2 GPIO16 UART2, 3.3V logic
GPIO Header G22 GPIO22 I2C SCL
GPIO Header G21 GPIO21 I2C SDA
GPIO Header G14 GPIO14 General purpose
GPIO Header G12 GPIO12 Strapping pin, keep it LOW at power-up
BOOT Button GPIO0 Hold during reset for download mode
USB Serial (CH340) GPIO1, GPIO3 UART0, Serial Monitor

HOW IT WORKS

You can use the board in two ways: program it yourself like any ESP32 board, or use the factory Modbus RTU firmware it ships with.

Option A — Program it as an ESP32 board

  1. In Arduino IDE, install the ESP32 board package (esp32 by Espressif Systems) from the Boards Manager.
  2. Connect the board over Type-C, then select ESP32 Dev Module and the board's COM port.
  3. Write your sketch and upload it. Use the Pin Mapping section: a relay turns ON when its GPIO is LOW, and an input reads LOW when it is active.

PlatformIO, ESP-IDF, and MicroPython work too, with the same pins. Uploading your own program replaces the factory firmware.

Option B — Use the factory Modbus RTU firmware (no programming)

The board ships with this firmware. Connect the RS485 A and B terminals to your Modbus master or to a USB-to-RS485 adapter, power the board, and send commands in HEX.

Setting Value
Slave Address 1
Baud Rate 115200 bps
Data Format 8N1 (8 data bits, no parity, 1 stop bit)
Relay 1 to Relay 4 Coil addresses 0x0000 to 0x0003
Function Codes 01 Read Coils, 05 Write Single Coil, 0F Write Multiple Coils

Ready-to-send commands (the last two bytes are the CRC-16/MODBUS checksum):

Action HEX Command
Relay 1 ON 01 05 00 00 FF 00 8C 3A
Relay 1 OFF 01 05 00 00 00 00 CD CA
Relay 2 ON 01 05 00 01 FF 00 DD FA
Relay 2 OFF 01 05 00 01 00 00 9C 0A
Relay 3 ON 01 05 00 02 FF 00 2D FA
Relay 3 OFF 01 05 00 02 00 00 6C 0A
Relay 4 ON 01 05 00 03 FF 00 7C 3A
Relay 4 OFF 01 05 00 03 00 00 3D CA
All Relays ON 01 0F 00 00 00 04 01 0F 7E 92
All Relays OFF 01 0F 00 00 00 04 01 00 3E 96
Relays 1 and 3 ON 01 0F 00 00 00 04 01 05 FE 95
Read Relay Status 01 01 00 00 00 04 3D C9

In the factory firmware, the inputs are linked to the relays: while IN1 is active, relay 1 is ON, and when IN1 is released, relay 1 turns OFF. The same applies to IN2 to IN4. An active input has priority over Modbus commands for its relay.

Restore the factory firmware

After uploading your own code, you can bring the factory firmware back in either of these ways.

With Arduino IDE

  1. Download the factory firmware source code (ZIP) from the Download section and unzip it.
  2. Install the modbus-esp8266 library from the Library Manager.
  3. Open ESP32_RS485_Modbus_Relay.ino, select ESP32 Dev Module, and upload.

With the firmware file

  1. Download the factory firmware (BIN) from the Download section.
  2. Open the Espressif Flash Download Tool and choose the ESP32 chip type.
  3. Add the file, tick it, set the address to 0x0, select the board's COM port, and click START.

COMPATIBLE HARDWARE

  • High-voltage AC loads (lamps, fans, pumps, heaters, valves, contactors) — relay NO, COM, and NC terminals, up to 10A 250VAC
  • DC loads (solenoids, DC pumps, LED strips) — relay terminals, up to 10A 30VDC
  • Switches, sensors, PLC outputs, and machine status contacts — isolated inputs IN1 to IN4
  • PLCs, HMIs, and any Modbus RTU master — RS485 A and B terminals at 115200 bps, 8N1, slave address 1
  • USB to RS485 adapters — send Modbus commands from a PC to test the board
  • Computer with Arduino IDE, PlatformIO, or ESP-IDF — Type-C USB for uploads and Serial Monitor
  • Home automation controllers (Home Assistant, Node-RED) — WiFi or Bluetooth with your own firmware
  • MQTT brokers and IoT platforms — ESP32 WiFi for publish and subscribe relay control
  • I2C sensors and displays — GPIO22 (SCL) and GPIO21 (SDA) header pins
  • UART devices — 3.3V serial port 2 header (TX2, RX2, GND, 5V)
  • DC power supplies (9-24V) — direct wiring to the power input terminals

WARNING

Mains voltage is dangerous. Turn off the power before wiring the relay terminals, and have mains wiring done by a qualified person. The optocoupler inputs are for low-voltage DC signals only; never connect mains voltage to IN1 to IN4.

DRIVER

This board uses the CH340/CH341 USB to Serial chip. Most operating systems support it automatically, but if your computer doesn't recognize the board, you may need to install the driver manually.

FAQ

Is this a programmable ESP32 board?

Yes. It works like any ESP32 development board. Program it in Arduino IDE (select ESP32 Dev Module), PlatformIO, ESP-IDF, or MicroPython, and upload over Type-C. The Pin Mapping section lists the relay and input pins.

Does it come with firmware?

Yes. It ships with Modbus RTU firmware: slave address 1, 115200 bps, 8N1. Connect A and B to a Modbus master or a USB-to-RS485 adapter and send the commands in the How It Works section, with no programming.

Can I get the factory firmware back after uploading my own code?

Yes. Download the factory firmware file or its source code from the Download section and upload it again. The steps are in the How It Works section.

What can the relays switch?

Each relay switches up to 10A at 250VAC or 10A at 30VDC through NO, COM, and NC terminals, enough for lamps, fans, pumps, valves, and contactors. Turn off the power before wiring mains loads.

Can the inputs read mains voltage directly?

No. The optocoupler inputs take low-voltage DC signals only. To monitor a mains-powered machine, use a low-voltage DC signal from it instead, for example a status contact or contactor auxiliary contact switching a DC supply, or an AC voltage detection module.

Can I change the slave address or baud rate?

They are fixed in the factory firmware. Download the factory firmware source code, change SLAVE_ID and the baud rate in mySerial.begin(), then upload it with Arduino IDE.

Why doesn't a relay respond to my Modbus command?

Check the matching isolated input. While an input is active, its relay stays ON and Modbus commands cannot turn it off.

The board does not answer Modbus commands. What should I check?

Make sure A and B are not swapped, the master uses 115200 bps, 8N1, and slave address 1, and your serial tool sends in HEX mode.

How do I start an upload manually?

Uploads normally start automatically. If one does not, hold the BOOT button, press and release EN, then release BOOT and upload again.

DOWNLOAD