The objective of this project is to create a cutting-edge home automation solution utilizing the ESP32 device. The system aims to enable remote management and monitoring of household appliances and devices, enhancing homeowners' control, convenience, and energy efficiency, particularly concerning AC appliances.

This project is the first prototype for my actual home automation idea. The main idea behind the project is to create a credit card-sized home automation system that fits inside the switchboard and connects to the existing wiring to control up to 8 AC appliances. The project allows users to use the existing switchboard as it is to control the ac appliance in addition to that it also allows users to control their ac appliances using a web dashboard or a mobile app via the internet, also using an ir remote. The project features 3 sensors that can be sued to automate a certain task, for example, the project has a temperature sensor connected to it, if the value of the temperature sensor goes above a certain value, the user can configure it to automatically turn on appliances like air conditioners or fans, etc.

ESP32 Home Automation FLowchart

The app or the web dashboard allows users to seamlessly control their appliances and it also helps them to automatically turn the devices on using timers.

ESP Home Autoamtion App Dashboard

The app or web dashboard also helps users to visualize their usage through beautiful charts and helps users to predict the electrical expenses.

ESP Home Autoamtion App Dashboard

The project also provides predictions on when the user is there in the home and when he leaves using daily usage analysis.


Components Required


Circuit Diagram

ESP32 Home Automation Circuit Diagram

The actual project circuit has been uploaded in the images section. The prototype of this project has an led that indicates if a device is on or not, the led is connected to the gpio2 of the esp32 development board. There is a switch that is connected to the gpio4 of the esp32 development board. the user can use the switch to control the led or us use the web dashboard.

Circuit Diagram

In the actual project idea, the plan was to create a custom PCB and solder all the components.

circuit diagram

The actual project idea basically consists of a PCB with 8 inbuilt relay modules with optocouplers,3 sensors connected to the esp32, ac to dc 12v link module, voltage regulators, logic converter, and an esp32 actual module instead of a development board. 

circuit diagram


PCB Design

PCB Design

3D Model

PCB Design


Arduino Code

Arduino Code For ESP32 Home Automation


Libraries: -

  • WiFi.h: Manages WiFi connections. 
  • HTTPClient.h: Enables HTTP communication.
  • Arduino.h: Provides built-in functions.

Constants and Variables: -

  • serverAddress: Webserver URL. 
  • ssid: WiFi SSID. 
  • password: WiFi password.
  • RelayPins[8]: GPIO pins connected to relays.
  • SwitchPins[8]: GPIO pins connected to switches.
  • SwitchStates[8]: Tracks switch states.
  • Response: Holds server response.
  • url: Webserver URL.
  • httpGetCode: HTTP GET response code.
  • httpPostCode: HTTP POST response code.
  • Esp_Http_Client: HTTPClient instance.

Functions: -

http_get(): Sends HTTP GET request to server.

http_post(int flag): Sends HTTP POST request.

print_relay_states(): Prints device states.

modify_relays(): Adjusts relays based on Response.

switch_state_change(): Detects changes in switch states.

modify_response(): Updates Response based on switches.

manual_mode(): Handles offline mode.

Setup Function: -

  • Initializes serial communication. 
  • Connects to WiFi. 
  • Sets pin modes for relays and switches. 
  • Initializes switch states.

Loop Function: -

If WiFi connected: -
  • Sends HTTP GET, checks relay changes.
  • If switch changes, updates Response, sends POST.
  • Modifies relay states from Response.

If WiFi not connected: -

  • Enters manual mode. 
  • Checks switch changes, updates relays. 
  • Prints relay states.

Leave a comment

Please note, comments must be approved before they are published

Your cart