Production-ready ESP32 firmware for multi-zone temperature control with PID controllers, SSR outputs, and a web-based interface.
- Web Interface: ESP32-hosted web UI with live updates via WebSockets
- Temperature Probes: Full CRUD for temperature probe configuration
- PID Controllers: Multiple independent PID controllers with time-proportional SSR control
- Auto-Tuning: Built-in PID auto-tuning algorithm
- Wi-Fi Management: Automatic captive portal for Wi-Fi configuration
- Persistent Storage: All configurations stored in NVS (Non-Volatile Storage)
- SSR outputs default to OFF on boot and errors
- Watchdog timer prevents system hangs
- Automatic SSR shutdown if sensor becomes unavailable
- Clear separation between low-voltage logic and SSR control
- ESP32 development board
- DS18B20 temperature sensors (OneWire bus)
- AC SSRs (Solid State Relays) for heater control
- Appropriate power supplies and isolation
- PlatformIO IDE or PlatformIO CLI
- ESP32 Arduino framework
- Clone or download this repository
- Open in PlatformIO
- Connect your ESP32 via USB
- Build and upload:
pio run -t upload
- Monitor serial output:
pio device monitor
Note: This firmware is configured for production use with OTA (Over-The-Air) updates only. USB access is not available in the production environment.
To update firmware via OTA:
-
Find your device's IP address:
- Check the web UI header (displays IP address)
- Check serial monitor output:
WiFi connected! IP: x.x.x.x - Use mDNS:
http://pidtool.local(then check/api/ipendpoint)
-
Update
platformio.ini:- Set
upload_portto your device's IP address (currently set to10.0.0.128) - OTA password is
Printer123(configured inupload_flags)
- Set
-
Build and upload:
pio run -t upload
-
The device will automatically reboot after a successful OTA update.
OTA Configuration:
- Hostname:
pidtool(accessible viahttp://pidtool.local) - Password:
Printer123 - Port: 3232 (ArduinoOTA default)
On first boot, if no Wi-Fi credentials are stored:
- The ESP32 will create an Access Point:
- SSID:
PrintboxConfig - Password:
Printer123
- SSID:
- Connect to this network from your device
- A captive portal will automatically open (or navigate to
192.168.4.1) - Select your Wi-Fi network and enter credentials
- The device will reboot and connect to your network
- Access the web interface at the IP address shown in serial monitor
- Navigate to the "Temperature Probes" tab
- Click "Add Probe"
- Configure:
- Name: User-friendly identifier
- GPIO Pin: Pin connected to OneWire bus (typically GPIO 4)
- Pull Mode: None/Pull-up/Pull-down (usually None for OneWire)
- Enabled: Enable/disable this probe
Note: Currently, all probes share the same OneWire bus on GPIO 4. For multiple independent buses, modify sensors.cpp.
- Navigate to the "PID Controllers" tab
- Click "Add PID Controller"
- Configure:
- Name: Identifier for this controller
- Temperature Probe: Select the probe to read from
- Setpoint: Target temperature (°C)
- Kp, Ki, Kd: PID constants (start with defaults or use auto-tune)
- Output GPIO Pin: Pin connected to SSR control input
- Output Pull Mode: Usually None for SSR control
- Control Window: Time window for time-proportional control (1-5 seconds, default 2000ms)
- Enabled: Enable/disable this controller
- Configure a PID controller with a probe and setpoint
- Ensure the heater is connected and safe to operate
- Click "Tune" on the PID controller
- The system will:
- Heat the system to create oscillations
- Measure oscillation characteristics
- Calculate optimal PID constants using Ziegler-Nichols method
- Save the tuned values automatically
- Tuning typically takes 2-10 minutes depending on system response
Warning: Auto-tuning will actively control the heater. Ensure proper safety measures are in place.
src/
├── main.cpp # Main entry point, initialization, and loop
├── storage.h/cpp # NVS-based persistent storage
├── wifi_manager.h/cpp # Wi-Fi connection and captive portal
├── sensors.h/cpp # Temperature probe management
├── pid_controller.h/cpp # PID control and auto-tuning
└── web_ui.h/cpp # Web server and UI
-
Time-Proportional Control: SSRs are controlled using time-proportional output within a configurable window (1-5 seconds). This avoids high-frequency PWM that can damage SSRs and provides smooth control.
-
Persistent Storage: All configurations use ESP32's Preferences (NVS) library for reliable non-volatile storage.
-
Safety-First Design:
- All SSR outputs initialize to OFF
- Watchdog timer prevents system hangs
- Sensor validation prevents heater operation with bad readings
- Clear separation between control logic and output hardware
-
Modular Architecture: Each subsystem is self-contained with clear interfaces, making maintenance and extension easier.
-
WebSocket Updates: Live data updates use WebSockets for efficient real-time communication without polling overhead.
GET /- Main web interfaceGET /api/probes- List all temperature probesPOST /api/probe- Create/update probeDELETE /api/probe?id=X- Delete probeGET /api/pids- List all PID controllersPOST /api/pid- Create/update PID controllerDELETE /api/pid?id=X- Delete PID controllerGET /api/data- Get current temperature readings and PID statesPOST /api/tune?id=X&action=start- Start auto-tuningWebSocket /ws- Live updates (JSON messages)
-
Electrical Safety:
- Ensure proper isolation between low-voltage ESP32 and high-voltage AC circuits
- Use appropriate SSRs rated for your load
- Follow local electrical codes
-
Thermal Safety:
- Implement external thermal fuses/cutoffs if required
- Monitor system behavior during auto-tuning
- Set reasonable temperature limits in your application
-
Software Safety:
- Watchdog timer resets system if it hangs
- Sensor validation prevents operation with bad readings
- SSR defaults to OFF on all error conditions
- Check serial monitor for connection errors
- Verify credentials are correct
- Ensure 2.4GHz Wi-Fi (ESP32 doesn't support 5GHz)
- Try factory reset (clear NVS) if credentials are corrupted
- Verify OneWire bus wiring (data line needs pull-up resistor, typically 4.7kΩ)
- Check GPIO pin configuration matches hardware
- Ensure DS18B20 sensors are properly powered
- Verify sensor addresses if using multiple sensors
- Verify probe is assigned and enabled
- Check SSR wiring and GPIO configuration
- Ensure PID controller is enabled
- Verify setpoint is reasonable
- Check that probe readings are valid
- Ensure heater is properly connected
- Verify probe is reading correctly
- Check that system can actually heat up (thermal mass, insulation)
- Increase tuning timeout if system is slow to respond
- Finding Device IP:
- Check web UI header (displays IP address)
- Use mDNS:
http://pidtool.localthen check/api/ipendpoint - Check serial monitor output:
WiFi connected! IP: x.x.x.x
- Update Fails:
- Verify device IP is correct in
platformio.ini - Ensure device is on the same network
- Check password is correct (
Printer123) - Verify device is responding:
curl http://<IP>/api/ip - OTA uploads can take 60+ seconds - be patient
- Verify device IP is correct in
- Device Not Responding After OTA:
- Wait 10-15 seconds for device to reboot
- Check serial monitor for boot messages
- Verify WiFi connection is stable
-
OneWire Bus: Currently all probes share GPIO 4. Future: Support multiple independent OneWire buses.
-
Sensor Types: Currently optimized for DS18B20. Future: Support other sensor types (analog, I2C, etc.).
-
PID Tuning: Current implementation uses simplified Ziegler-Nichols. Future: More sophisticated tuning algorithms.
-
Web UI: Basic but functional. Future: Enhanced visualization, graphs, logging.
This firmware is provided as-is for use in embedded temperature control applications.
When modifying this code:
- Maintain safety features (SSR defaults, watchdog, sensor validation)
- Keep modular structure
- Test thoroughly before deployment
- Document any hardware-specific assumptions