Wi-Fi home automation (ESP32)
Switch lights and fans from your phone over Wi-Fi with a small web page hosted on the ESP32 itself.
What you'll learn
- โESP32 Wi-Fi and a built-in web server
- โRelays and electrical safety
- โMQTT for IoT messaging
What you'll build
- โPhone-friendly control page
- โShows current state of each switch
- โPhysical switch still works
- โSchedules (on at 7 pm)
Step-by-step guide
- 1
Start low-voltage
Prototype with LEDs first. Only connect mains appliances with proper relay modules, enclosures and supervision by someone experienced.
- 2
Wi-Fi
Program the ESP32 with the Arduino IDE; WiFi.begin(ssid, password); print the IP address.
- 3
Web server
Use the WebServer library: route "/" returns an HTML page; "/toggle?ch=1" switches relay 1 and returns JSON state.
- 4
UI
Simple HTML buttons with fetch() calls; refresh state every few seconds.
- 5
Keep state
Save relay states in Preferences (flash) so they survive power cuts.
- 6
MQTT
Optionally publish/subscribe with PubSubClient to a broker (for example Mosquitto on a Raspberry Pi) for app integration.
- 7
Security
Do not expose it to the internet directly; add a simple password and keep it on your home network.
๐ Make it stand out
- +Voice control through a home assistant platform
- +Energy usage with a current sensor
- +OTA firmware updates