dia (max-width: 768px) { .project-page { padding: 15px; } .project-hero h1 { font-size: 24px; } .project-meta-grid { grid-template-columns: 1fr 1fr; } }
🌐 IoT 📡 ESP32 Advanced ⏱️ 12-15 Hours

Smart Home Automation Hub

Transform your living space into a high-tech smart home! This advanced IoT project guides you through building a centralized hub using the ESP32. You'll learn to control high-voltage appliances safely via relays, monitor room conditions in real-time, and create a custom web dashboard for remote control from anywhere in the world.

💰
$30 - $45
📊
Advanced
🧩
6 Parts
📝
Jan 2026

📖 Project Overview

The heart of this system is the powerful ESP32 microcontroller, chosen for its integrated WiFi and dual-core processing. The hub acts as a local server, hosting a responsive web interface that allows you to toggle lights, fans, and other appliances.

Safety is paramount in home automation. We use electromechanical relays to isolate the low-voltage ESP32 from high-voltage AC circuits. Additionally, the system includes a DHT22 sensor for climate tracking and an OLED display for local status updates.

💡 Key Learning Outcomes

  • Setting up an ESP32 as an Asynchronous Web Server
  • Advanced GPIO control for multi-channel relay modules
  • Handling real-time sensor data over WiFi (WebSockets/HTTP)
  • Designing a responsive HTML/CSS dashboard for mobile and desktop
  • Implementing failsafe mechanisms for mains-powered devices

🧰 Components Required

Part Name Qty
ESP32 DevKit V1 1
4-Channel 5V Relay Module 1
DHT22 Temperature & Humidity Sensor 1
0.96" I2C OLED Display (128x64) 1
5V 2A USB Power Supply 1
Jumper Wires (Assorted) 1 set

🔌 Hardware Connections

Ensure your ESP32 is unplugged while making connections. Follow this master wiring guide:

🔍 Pin Mapping Guide

Peripheral Peripheral Pin ESP32 GPIO Notes
Relay Ch 1 IN1 GPIO 26 Light Control
Relay Ch 2 IN2 GPIO 27 Fan Control
DHT22 DATA GPIO 4 10k Pull-up included
OLED Display SCL GPIO 22 I2C Clock
OLED Display SDA GPIO 21 I2C Data
Power VCC / VIN 5V / USB Ensure shared GND

🚨 HIGH VOLTAGE WARNING

Connecting relays to main power (110V/220V AC) is extremely dangerous. Ensure all AC wiring is insulated and contained in a project box. Never work on the circuit while it is plugged into the wall.

📋 Setup Instructions

1

Prepare the Arduino IDE

Install the ESP32 Add-on in your Arduino IDE. Go to File > Preferences and add the ESP32 JSON URL to "Additional Boards Manager URLs". Then install "esp32" by Espressif Systems.

2

Install Required Libraries

Use the Library Manager to install: ESPAsyncWebServer, AsyncTCP, Adafruit DHT, Adafruit GFX, and Adafruit SSD1306.

3

Wire the Peripherals

Connect the components as per the Pin Mapping Guide. Use a breadboard for initial testing before moving to a permanent soldered PCB or project enclosure.

💻 ESP32 Firmware

C++ (Arduino IDE)
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
#include <DHT.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// Replace with your network credentials
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";

#define RELAY_PIN_1 26
#define RELAY_PIN_2 27
#define DHTPIN 4
#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);
AsyncWebServer server(80);
Adafruit_SSD1306 display(128, 64, &Wire, -1);

void setup() {
  Serial.begin(115200);
  
  pinMode(RELAY_PIN_1, OUTPUT);
  pinMode(RELAY_PIN_2, OUTPUT);
  digitalWrite(RELAY_PIN_1, HIGH); // Off for active-low relays
  digitalWrite(RELAY_PIN_2, HIGH);

  dht.begin();
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) Serial.println("OLED failed");

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.print("."); }
  
  Serial.println(WiFi.localIP());

  // Web Server Routes
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send(200, "text/plain", "MakersDeck Smart Hub is Online!");
  });

  server.on("/relay1/on", HTTP_GET, [](AsyncWebServerRequest *request){
    digitalWrite(RELAY_PIN_1, LOW);
    request->send(200, "text/plain", "Relay 1 ON");
  });

  server.begin();
}

void loop() {
  // Update OLED with status
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("Smart Home Hub");
  display.println(WiFi.localIP());
  display.display();
  delay(2000);
}
                    

🚀 Upgrade Ideas

🔧 Future Enhancements

  • Integrate with Home Assistant via MQTT
  • Add Voice Control using Amazon Alexa or Google Home
  • Incorporate Energy Monitoring using a PZEM-004T module
  • Add Physical Overrides with manual push buttons
← Back to All Projects