ESP32-based Industrial PLC — Complete Step■by■Step Guide
(BOM, Wiring, Schematics, Testing)
Prepared for: Umar Hayat
Date: 22 August 2025
This practical guide helps you build a robust ESP32-based PLC with isolation, Modbus, analog I/O, and industrial-grade
wiring.
Contents
1. Overview
2. BOM
3. Power Architecture
4. Digital Inputs
5. Digital Outputs
6. Analog Inputs
7. Analog Outputs
8. Communications
9. Isolation
10. Grounding & EMI
11. PCB/Layout
12. Assembly & Testing
13. Safety
BOM (Key parts)
Item Example Part/Notes
MCU ESP32-WROOM-32
DIN-rail PSU MeanWell HDR-60-24 (24V)
Isolated DC-DC Mornsun B2415S / B0505S
Optocoupler PC817 / HCPL-2630
ADC ADS1115 (16-bit)
DAC MCP4725 (12-bit)
RS485 transceiver MAX485 / ADM2483 (isolated)
I2C isolator ADuM1250 / ISO1540
MOSFET (DO) Logic-level N-channel MOSFET or SSR
TVS diodes SMBJ5.0A, SMBJ24A
Power Architecture (Recommended)
1) Mains -> DIN-rail PSU (24V) -> 24V bus (fused). 2) 24V -> isolated DC-DC -> 5V iso -> 3.3V for ESP (or isolated
5->3.3). 3) Use TVS, MOV, common mode choke and fuses.
Power wiring (text diagram):
MAINS (L,N) -> EMI FILTER -> DIN-RAIL PSU (HDR-60-24) +24V ---- fuse ---> 24V BUS ---> Field
devices 0V -------------------------------> Field return PE -> Chassis earth 24V BUS ->
Isolated DC-DC (24->5V) -> 5V_iso -> LDO -> 3.3V_iso -> ESP32 Do NOT bond 0V_iso to chassis
earth except single reference (1MΩ || 4.7nF).
Digital Inputs (Opto-isolated) - Schematic
Field side (24V domain): +24V ---[R_series 12kΩ]---|> (Opto LED)---|--- GND_field MCU side
(3.3V domain): +3.3V ---[R_pullup 10kΩ]---+---- Collector (Opto) | ESP GPIO (active LOW) |
Emitter ---- GND_ESP Notes: - R_series ~12kΩ (1%); adjust for opto LED current ~1-2mA. - Add
0.1uF decoupling on both domains. - Use TVS on 24V if long runs.
Digital Outputs (MOSFET low-side) - Schematic
ESP GPIO --[100Ω]-- Gate (MOSFET) Gate --[100kΩ pull-down]--> GND Drain --- Load --- +24V
Source --> GND Add flyback diode for inductive loads; use SSR for mains AC loads. Choose
MOSFET with Rds(on) spec at Vgs=3.3V or use gate driver.
Analog Inputs (0-10V & 4-20mA)
0-10V scaling: Vin -> Rtop=68kΩ -> Vout -> Rbot=33kΩ -> GND Vout (10V) ≈ 3.267V -> buffer ->
ADC (ADS1115) 4-20mA shunt: Current -> 249Ω precision shunt -> 0.996V to 4.98V -> ADS1115
differential input (PGA=±6.144V) Always add input protection diode and series resistor.
Analog Outputs (0-10V & 4-20mA)
Use MCP4725 (0-3.3V) then op-amp gain to reach 0-10V (gain ~3.03). For 4-20mA use dedicated
transmitter IC (XTR111) or op-amp + transistor current source stage. Prefer commercial loop
transmitter modules for reliability.
Communications - RS-485 (Modbus RTU)
Use isolated transceiver (ADM2483) between ESP UART and bus for galvanic separation.
Termination: 120Ω at ends. Biasing: pull-up to Vcc and pull-down to GND (~620Ω). DE/RE
control: Tie together and drive from ESP GPIO for TX enable. Modbus RTU settings: Baudrate
(configurable), Slave ID, parity as needed.
Isolation methods & I2C isolator
- Use ADuM1250 / ISO1540 for I2C isolation (MLX90614). Provide isolated supply to sensor side. - Use isolated DC-DC
modules to break ground loops. - Reference isolated ground to chassis via 1MΩ || 4.7nF network for noise bleed without
creating loop.
Assembly & Testing (Step-by-step)
1. Assemble power rails and verify 24V with multimeter.
2. Power isolated DC-DC and confirm isolation (measure resistance between grounds).
3. Power ESP32 on isolated 3.3V, upload basic blink firmware.
4. Test single DI with 24V and opto; verify ESP reads input.
5. Test single DO on low-voltage DC load with MOSFET.
6. Test ADS1115 readings with known voltages.
7. Test RS-485 comms with Modbus Poll/Slave.
8. Bring up rest of channels gradually.
Safety Notes
- Always disconnect mains before wiring.
- Use proper fusing and earth connections.
- Do not work on live mains unless certified.
- Test with small loads first.