Project · Intermediate · ESP32
ESP32 Home Automation with Sensors & Relays (Safe Bench Build)
Sensors publish; actuators subscribe. Keep v1 on low-voltage practice loads. Pairs with the Pi + ESP32 MQTT architecture and free ESP32 kit PDF. Scope & non-goals In scope: BME280/DHT class sensors, opto…
Project template
- Goal & materials
- Steps / firmware
- Troubleshooting
- AI assist notes
- Related gear & books
Pairs with the Pi + ESP32 MQTT architecture and free ESP32 kit PDF.
Scope & non-goals
- In scope: BME280/DHT class sensors, opto-isolated relay modules on low-voltage practice loads, serial + optional MQTT publish.
- Out of scope for beginners: mains switching, unlabeled relay modules without ratings, “smart home” cloud lock-in on day one.
BOM (one node)
| Item | Qty | Ballpark |
|---|---|---|
| ESP32 DevKit | 1 | $4–12 |
| BME280 (I²C) or DHT22 | 1 | $3–10 |
| Opto relay module (logic-level) | 1 | $3–8 |
| 12V LED strip segment / DC load for practice | 1 | $5–15 |
| 4.7k pull-ups if needed for I²C | 2 | $0.10 |
Bring-up order
- Blink + serial (prove the board) — first project.
- I²C scan / sensor readings with units printed every 2s.
- GPIO drive of relay on a safe low-V load.
- Only then add Wi-Fi + MQTT publish of the same JSON you already print to serial.
Expected serial (example)
t_c=24.10 rh=41.2 relay=0
t_c=24.12 rh=41.1 relay=0
Failure table
| Symptom | Likely cause | Test |
|---|---|---|
| I²C address missing | Wiring / 5V sensor on 3.3V bus | Scan bus; check level shift |
| Humidity stuck / NaN | DHT timing / bad library | Swap sensor; verify supply |
| Relay chatters | Floating input / no debounce / shared ground | Explicit GPIO mode; common GND |
| Wi-Fi OK, no MQTT | Broker IP / firewall | Ping Pi; mosquitto_sub on LAN |
Export / repo pack
Download skeleton: pi-esp32-mqtt-lab.zip · PlatformIO path: platformio-esp32-starter.zip
Verdict
Ship sensors and low-V actuators first. Mains and “whole house” automations wait until isolation, enclosures, and a local broker are boringly reliable.