๐ŸŽ™ Free live masterclass ยท Sun, 29 Nov, 7:00 pm IST ยท Java Full Stack roadmap Register free โ†’
Skills101

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.

Intermediateโฑ 10โ€“14 hours๐Ÿชœ 7 stepsESP32RelaysWeb server or MQTT

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. 1

    Start low-voltage

    Prototype with LEDs first. Only connect mains appliances with proper relay modules, enclosures and supervision by someone experienced.

  2. 2

    Wi-Fi

    Program the ESP32 with the Arduino IDE; WiFi.begin(ssid, password); print the IP address.

  3. 3

    Web server

    Use the WebServer library: route "/" returns an HTML page; "/toggle?ch=1" switches relay 1 and returns JSON state.

  4. 4

    UI

    Simple HTML buttons with fetch() calls; refresh state every few seconds.

  5. 5

    Keep state

    Save relay states in Preferences (flash) so they survive power cuts.

  6. 6

    MQTT

    Optionally publish/subscribe with PubSubClient to a broker (for example Mosquitto on a Raspberry Pi) for app integration.

  7. 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