Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » IoT Home Automation using ESP32 WebServer with PCB
ESP32 Projects IoT Projects

IoT Home Automation using ESP32 WebServer with PCB

Mamtaz AlamBy Mamtaz AlamUpdated:November 18, 20246 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
IoT Home Automation using ESP32 WebServer with PCB
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Overview

In this IoT project, I will show you how to make Home Automation project with ESP32 WebServer. This Home Automation project solely relies on the webpage for controlling home devices with 4 relays. Once the device is powered on, the ESP32 connects to the WiFi network and generates a webpage. Using the ESP32 IP address, you can access the Webpage. By sending on/off command from webpage, we can control 4 relays.

Previously, we developed a Home Automation project based on the ESP32 platform, utilizing platforms such as Blynk, AWS IoT Core and Arduino IoT Cloud. To enhance portability and ease of use, a custom PCB is designed specifically for this project. Comprehensive documentation, including schematics, PCB layouts, Gerber Files, a detailed Bill of Materials, and the complete Source Code, is made available.

This system is designed to operate independently, free from reliance on external IoT applications, thereby streamlining the process of integrating it into a home automation system.


Bill of Materials

For this project, we will need the following components. The component list, footprint, and quantity are given below.

S.N.ComponentDesignatorFootprintQuantity
1Capacitor 100nfC1, C3, C6, C7, C8, C9, C10, C11CAP_08058
2Capacitor 10ufC2, C4, C5CAP_08053
3Capacitor 220uF, 25VC12FP-RAD-TH-D_10_0_5-L_16_1-MFG1
4Diode 1N4007D1, D2, D3, D4DIOM5027X262N4
5SP4322-01ETGD5SP432201ETG1
6Optocoupler PC817CIC1, IC3, IC4, IC5DIP762W60P254L458H450Q4N4
7ESP32 WROOM-32IC2ESP32WROOM3216MB1
82-Pin Terminal BlockJ11
93-Pin Terminal BlockJ2, J3, J4, J54
10Relay SRD-05VDC-SL-CK1, K2, K3, K4SRD4
11LED RedLED1, LED2, LED3, LED4, LED5LEDC2012X80N5
12Male Header 6 PinP1HDR1X61
13HLK-10M05PS1HLK10M051
14Transistor BC847BQ1, Q2, Q3, Q4, Q5, Q6BC847B2156
15Resistor 220RR1, R3, R9, R11, R14, R16, R17, R198058
16DNPR2, R10, R15, R188054
17Resistor 12KR4, R12, R138053
18Resistor 1KR5, R7, R8, R248054
19Resistor 470RR68051
20Resistor 10KR20, R21, R22, R238054
21Push Button SwitchS1, S2, S3, S4B3W10204
22Manual Switch (Optional)SW1, SW2, SW3, SW4HDR1X24
23HT7333 3.3V Voltage RegulatorU1IC_HT73331



Circuit Diagram & Hardware Design

Let us take a look at the Schematic of a ESP32 Webserver Home Automation. The schematic is drawn using the Altium Designer Software.

Schematic ESP32 Home Automation WebServer

We used SMD resistors, capacitors, and LED with the 0805 package. To convert 220V AC to 5V DC, we used an AC-to-DC Converter from Hi-Link. For providing power to ESP32 raw chip and other peripherals, a low-power LDO HT7333 IC was used. To separate the high-power line from the 3.3V circuit PC817 optocoupler IC is used. The LED5 in the circuit is used to indicate power.

HLK-10M05

Similarly the LED1, LED2, LED3 & LED4 is used to represent Relay1, Relay2, Relay3 & Relay4 output respectively. The LED5 is a power indication LED. The 4 Relays are connected to ESP32 via GPIO Pins 12, 14, 27, 26. The push buttons SW1, SW2, SW3, and SW4 are used in the manual controlling of Relays. They are connected to GPIO Pins 5, 17, 13, 16. You may attach a manual switch there and program the controller to control the circuit.

You can connect 4 home appliannces using the Relay connections at 3 Pin Terminal J2, J3. J4, J5. The 2 Pin Terminal J1 is used to supply AC Power directly to the Circuit. A Capacitor C12 of 220uF, 25V is connected to PCB stop voltage fluctuations.

FTDI Module

To program the ESP32 raw chip, the FTDI pin is provided. We can connect an FTDI Module (USB-to-TTL Converter) to program the ESP32 Chip directly.




Project PCB Gerber File & PCB Ordering Online

We have designed the PCB using the Altium Designer Software. It took quite a lot of time fixing all the isses in the PCB but still we managed to design a complete working custom PCB. The PCB design looks like this.

ESP32 Home Automation PCB

Here is the 3D View of the PCB from the front side as well as from the backside.

ESP32 Home Automation WebServer PCB

The Gerber File for the PCB is given below. You can simply download the Gerber File and order the PCB from PCBGOGO at 1$ only.

Download Gerber File: ESP32 Home Automation Gerber File

You can use this Gerber file to order high-quality PCB for this project. To do that visit the PCBGOGO official website by clicking here: https://www.pcbgogo.com/.

You can now upload the Gerber File by choosing the Quote Now option. From these options, you can choose the Material Type, Dimensions, Quantity, Thickness, Solder Mask Color and other required parameters.

After filling all details, select your country and shipping method. Finally you can place the order.




PCB & Hardware Assembly

After ordering the PCB, it took almost 5 days and I got my PCB.

The PCB quality from PCBGOGO is superb with very high quality. That is why most people trust PCBGOGO for PCB/PCBA Services.

PCB Top Side
PCB Bottom Side

First solder all the SMD components like resistors, capacitors, transistors, LEDs, voltage regulators & diodes. Be careful about the SMD LED polarity, place it in the proper direction. The SMD soldering is to be done on the both sides.

After soldering all these, you can solder the ESP32 raw chip. The final stage would be soldering all the through-hole components like Optocoupler IC, terminal block, Relays, male-female headers, and AC-to-DC Converter Module.

After soldering all the components, the ESP32 Webserver Home Automation Board is ready for the test. You can upload a blink sketch by connecting a USB-to-TTL Converter Module.

ESP32 Webserver Home Automation Board

Note: There were some voltage fluctuation issues in the designed PCB, so I have updated the design by adding 220uF capacitor. Also, some connection issues have been fixed. The Gerber file above is updated and the PCB would be little different from shown above. But overall the functionality is same.



Source Code/Program for Home Automation using ESP32 WebServer

Let us see the code for IoT Home Automation using ESP32 WebServer. The following code sets up an ESP32 as a simple web server for home automation. It controls four devices connected to GPIO pins, allowing their states (ON/OFF) to be toggled via a web page.

Here is the complete code. In this code make changes to the WiFi SSID and Password.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include <WiFi.h>
 
// Replace with your network credentials
const char* ssid     = "***************";  // Network SSID (name)
const char* password = "***************";  // Network password
 
// Set web server port number to 80 (HTTP default)
WiFiServer server(80);
 
// Variable to store the HTTP request from the client
String header;
 
// Variables to store the current state of each device (ON/OFF)
String Device1State = "off";
String Device2State = "off";
String Device3State = "off";
String Device4State = "off";
 
// Assign each device to a GPIO pin
const int Device1 = 12;
const int Device2 = 14;
const int Device3 = 27;
const int Device4 = 26;
 
// Variables to track the current time and last time a client made a request
unsigned long currentTime = millis();
unsigned long previousTime = 0;
// Define timeout time in milliseconds (2000ms = 2 seconds)
const long timeoutTime = 2000;
 
void setup() {
  Serial.begin(115200);
  // Initialize the GPIO pins for the devices as outputs and set them to LOW
  pinMode(Device1, OUTPUT);
  pinMode(Device2, OUTPUT);
  pinMode(Device3, OUTPUT);
  pinMode(Device4, OUTPUT);
  digitalWrite(Device1, LOW);
  digitalWrite(Device2, LOW);
  digitalWrite(Device3, LOW);
  digitalWrite(Device4, LOW);
 
  // Connect to Wi-Fi network with SSID and password
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  // Print the local IP address once connected
  Serial.println("");
  Serial.println("WiFi connected.");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  server.begin();
}
 
void loop() {
  WiFiClient client = server.available();   // Listen for incoming clients
 
  if (client) {                             // If a new client connects,
    Serial.println("New Client.");          // print a message out in the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    currentTime = millis();
    previousTime = currentTime;
    while (client.connected() && currentTime - previousTime <= timeoutTime) { // loop while the client's connected
      currentTime = millis();
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        header += c;
        if (c == '\n') {                    // if the byte is a newline character
          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println("Connection: close");
            client.println();
 
            // turns the Relays on and off
            if (header.indexOf("GET /1/on") >= 0) {
              Serial.println("Device 1 on");
              Device1State = "on";
              digitalWrite(Device1, HIGH);
            } else if (header.indexOf("GET /1/off") >= 0) {
              Serial.println("Device 1 off");
              Device1State = "off";
              digitalWrite(Device1, LOW);
            } else if (header.indexOf("GET /2/on") >= 0) {
              Serial.println("Device 2 on");
              Device2State = "on";
              digitalWrite(Device2, HIGH);
            } else if (header.indexOf("GET /2/off") >= 0) {
              Serial.println("Device 2 off");
              Device2State = "off";
              digitalWrite(Device2, LOW);
            }
            else if (header.indexOf("GET /3/on") >= 0) {
              Serial.println("Device 3 off");
              Device3State = "on";
              digitalWrite(Device3, HIGH);
            }
            else if (header.indexOf("GET /3/off") >= 0) {
              Serial.println("Device 3 off");
              Device3State = "off";
              digitalWrite(Device3, LOW);
            }
            else if (header.indexOf("GET /4/on") >= 0) {
              Serial.println("Device 4 off");
              Device4State = "on";
              digitalWrite(Device4, HIGH);
            }
            else if (header.indexOf("GET /4/off") >= 0) {
              Serial.println("Device 4 off");
              Device4State = "off";
              digitalWrite(Device4, LOW);
            }
 
            // Display the HTML web page
            client.println("<!DOCTYPE html><html>");
            client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
            client.println("<link rel=\"icon\" href=\"data:,\">");
            // Enhanced CSS for a compact look
            client.println("<style>");
            client.println("html { font-family: 'Roboto', sans-serif; background: #f5f5f5; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; }");
            client.println("body { max-width: 600px; background: #fff; padding: 20px; margin: 20px; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); }");
            client.println("h1 { color: #333; text-align: center; }");
            client.println(".device { background: linear-gradient(to right, #dae2f8, #d6a4a4); padding: 15px; margin: 10px 0; border-radius: 10px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); text-align: center; }"); // Reduced padding and margin
            client.println("p { font-size: 18px; color: #555; margin: 10px 0; }");
            client.println(".button { border: none; padding: 15px 35px; text-align: center;"); // Slightly reduced padding
            client.println("text-decoration: none; display: inline-block; font-size: 22px; margin: 10px; cursor: pointer; border-radius: 5px; transition: all 0.3s ease; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); }");
            client.println(".button:hover { box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4); }");
            client.println(".button-on { background-color: #4CAF50; color: white; }");
            client.println(".button-off { background-color: #f44336; color: white; }");
            client.println("</style></head>");
 
            // Web Page Heading
            client.println("<body><h1>Smart Home Automation</h1>");
 
            // Display current state, and ON/OFF buttons for Relay 1
            client.println("<div class=\"device\"><p>Device 1 - State " + Device1State + "</p>");
            if (Device1State == "off") {
              client.println("<a href=\"/1/on\"><button class=\"button button-on\">ON</button></a>");
            } else {
              client.println("<a href=\"/1/off\"><button class=\"button button-off\">OFF</button></a>");
            }
            client.println("</div>");
 
            // Display current state, and ON/OFF buttons for Relay 2
            client.println("<div class=\"device\"><p>Device 2 - State " + Device2State + "</p>");
            if (Device2State == "off") {
              client.println("<a href=\"/2/on\"><button class=\"button button-on\">ON</button></a>");
            } else {
              client.println("<a href=\"/2/off\"><button class=\"button button-off\">OFF</button></a>");
            }
            client.println("</div>");
 
            // Display current state, and ON/OFF buttons for Relay 3
            client.println("<div class=\"device\"><p>Device 3 - State " + Device3State + "</p>");
            if (Device3State == "off") {
              client.println("<a href=\"/3/on\"><button class=\"button button-on\">ON</button></a>");
            } else {
              client.println("<a href=\"/3/off\"><button class=\"button button-off\">OFF</button></a>");
            }
            client.println("</div>");
 
            // Display current state, and ON/OFF buttons for Relay 4
            client.println("<div class=\"device\"><p>Device 4 - State " + Device4State + "</p>");
            if (Device4State == "off") {
              client.println("<a href=\"/4/on\"><button class=\"button button-on\">ON</button></a>");
            } else {
              client.println("<a href=\"/4/off\"><button class=\"button button-off\">OFF</button></a>");
            }
            client.println("</div>");
 
            client.println("</body></html>");
 
            // The HTTP response ends with another blank line
            client.println();
            // Break out of the while loop
            break;
          } else { // if you got a newline, then clear currentLine
            currentLine = "";
          }
        } else if (c != '\r') {  // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }
      }
    }
    // Clear the header variable
    header = "";
    // Close the connection
    client.stop();
    Serial.println("Client disconnected.");
    Serial.println("");
  }
}


To program the ESP32 Raw Chip, connect the FTDI Module to your FTDI Pin of the PCB.

Then go to the tools & select ESP32 Dev Module that you are using for this project. Also, select the COM port. Then click on the upload option to upload the code to the ESP32 Chip.

Note: While uploading the code disconnect the relay from the power source.

Once the code uploading is done, open the Serial Monitor. The ESP32 will try connecting to the WiFi Network. Once it gets connected to the WiFi Network, the Serial Monitor will display the IP Address of ESP32.

Now remove the FTDI Module connection and power the device using the AC Supply.


Testing ESP32 Webserver Home Automation Project

Let us test the working of the project. Testing the ESP32 Webserver Home Automation project involves verifying that the ESP32 correctly interprets HTTP requests from the web interface and controls the connected devices as expected. Here’s how you can do the testing.

Ensure the ESP32 is powered correctly, with stable voltage and current. Check that the ESP32 connects to the WiFi network. The serial monitor should display the assigned IP address after connecting.

Enter the IP address displayed in the serial monitor into a web browser. The home automation control interface should load. The Webpage looks beautiful and very stylish.

ESP32 Home Automation Webserver Webpage

Click the buttons on the web interface to send ON/OFF commands to each device.

Observe the connected devices (relays, LEDs, etc.) to verify they respond correctly to the commands from the web interface.

ESP32 Webserver Home Automation Test

Ensure that the web interface correctly displays the current state of each device after sending commands. This is how you can control Home Appliances with Automation using the ESP32 WebServer.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleMyArm 300 Pi Unboxing & Usage – Portable 7-Axis Robotic Arm
Next Article MAX30102 & Arduino: Heart Rate + Blood Oxygen Monitoring

Related Posts

ESP32 Fingerprint Attendance System with Live Web Dashboard

Updated:June 14, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

Updated:June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

Updated:May 10, 20261K
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

Updated:May 2, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

Updated:April 27, 20261K
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

Updated:April 27, 20262K
Add A Comment

CommentsCancel reply

Latest Posts

ESP32 Fingerprint Attendance System with Live Web Dashboard

June 14, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
Top Posts & Pages
  • IoT Based PM & Air Quality Monitoring System using ESP32
    IoT Based PM & Air Quality Monitoring System using ESP32
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • How to use INA219 DC Current Sensor Module with Arduino
    How to use INA219 DC Current Sensor Module with Arduino
  • Designing of MPPT Solar Charge Controller using Arduino
    Designing of MPPT Solar Charge Controller using Arduino
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU
    High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU
  • ECG Graph Monitoring with AD8232 ECG Sensor & Arduino
    ECG Graph Monitoring with AD8232 ECG Sensor & Arduino
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (205)
    • ESP32 MicroPython (7)
    • ESP32 Projects (82)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.