modbus-esp8266 library or Espressif's official esp-modbus ESP-IDF component makes a cheap, Wi-Fi-connected Modbus slave for IIoT edge testing. If you just need a slave to validate PLC/SCADA logic on your desk, a Windows Modbus simulator gets you there without flashing firmware.
Why simulate a Modbus slave on an ESP32?
The ESP32's built-in Wi-Fi (and optional Ethernet via an add-on PHY) makes it a natural fit for simulating a networked Modbus TCP field device — no laptop, no extra network adapter, just power and a Wi-Fi connection. That makes it popular for IIoT prototyping: simulating a sensor node, edge gateway, or remote I/O unit that a PLC or SCADA system polls over the network, at a fraction of the cost and footprint of a full field device.
Two library options
| Library | Toolchain | Notes |
|---|---|---|
modbus-esp8266 | Arduino IDE / PlatformIO (Arduino framework) | Works on ESP8266 and ESP32; supports master, slave, or both; Modbus TCP and RTU/serial |
esp-modbus | Native ESP-IDF | Espressif's official component; supports serial (RTU/ASCII) and TCP ports, master and slave roles |
Pick modbus-esp8266 if your project already lives in Arduino/PlatformIO. Pick esp-modbus if you're building a native ESP-IDF project and want the component Espressif maintains directly.
Modbus TCP slave on ESP32 (Arduino, modbus-esp8266)
No extra hardware is needed beyond Wi-Fi. A minimal TCP slave looks like this:
#include <WiFi.h>
#include <ModbusIP_ESP8266.h>
ModbusIP mb;
const int HREG_START = 0;
void setup() {
WiFi.begin("your-ssid", "your-password");
while (WiFi.status() != WL_CONNECTED) delay(500);
mb.server(); // start Modbus TCP slave on port 502
mb.addHreg(HREG_START, 0, 100); // 100 holding registers, initial value 0
}
void loop() {
mb.task();
}
Point any Modbus master (PLC, SCADA, or a desktop simulator) at the ESP32's IP address on port 502 to read/write the simulated holding registers.
Modbus RTU slave on ESP32 (RS485 wiring)
The ESP32's UART pins output 3.3V TTL, not RS485 levels, so Modbus RTU needs a MAX485 (or similar) RS485 transceiver module wired between a UART pair and the bus:
- Wire the transceiver's RO/DI pins to an ESP32 UART (e.g. UART2 on GPIO16/17), and its DE/RE pins to a spare GPIO for direction control
- Wire A/B to the RS485 bus, matching polarity with the master
- Configure the library's serial server with the matching baud rate, parity, and unit ID your master expects
- Toggle DE/RE around each transmit in your loop (or use a library helper that does this for you) and confirm the master can read registers
ESP32 vs a desktop Modbus simulator
| Aspect | ESP32 (modbus-esp8266 / esp-modbus) | Desktop simulator (Windows/PC) |
|---|---|---|
| Setup time | Toolchain + firmware flash + wiring (RTU) | Install and click "Start Slave" |
| Networking | Wi-Fi built in — no cabling for TCP | Needs the host PC's own network connection |
| GUI for register values | None by default (code-defined registers) | Built-in GUI, live editing |
| Best for | Wireless IIoT edge simulation, low-cost field-adjacent rigs | Day-to-day desk testing, CI/regression, quick checks |
| Cost | ESP32 board (~$5–10) + RS485 module for RTU (~$2–5) | Free 30-day trial, $99 one-time after |
When you don't need an ESP32 at all
If your goal is simply to have a Modbus slave to validate PLC logic, HMI tags, or SCADA polling — without needing the ESP32's wireless/edge-device advantages — a desktop Modbus simulator gives you the same TCP and RTU slave behavior with a visual register editor, no firmware flashing, and no separate board to keep powered and connected.
Related pages
Skip the firmware flash for desk testing
Simulate Modbus TCP and RTU slaves on your PC in minutes — free 30-day trial, then a $99 one-time license.
Download Free tierFAQ
Can an ESP32 act as a Modbus slave?
Yes. Using either Espressif's official esp-modbus component (ESP-IDF) or the Arduino-compatible modbus-esp8266 library, an ESP32 can run a Modbus TCP or RTU slave that responds to master requests with simulated register data.
Does ESP32 Modbus TCP need extra hardware?
No — the ESP32's built-in Wi-Fi handles it. Modbus RTU needs a MAX485 (or similar) RS485 transceiver module since the UART pins are 3.3V TTL, not RS485.
Which library should I use — modbus-esp8266 or ESP-IDF's esp-modbus?
modbus-esp8266 for Arduino IDE/PlatformIO projects (works on ESP8266 and ESP32); Espressif's esp-modbus component for native ESP-IDF projects.
Is an ESP32 Modbus simulator good enough for CI or regression testing?
It works for physical/field-adjacent testing, but firmware flashing and Wi-Fi reliability add overhead most teams skip for day-to-day CI — a desktop simulator is usually faster there.
Can one ESP32 simulate multiple Modbus slave devices?
One ESP32 can expose one slave with many registers. For several independent slave unit IDs at once, use multiple boards or a desktop simulator that supports multiple simulated slaves in one instance.