dia (max-width: 768px) { .project-page { padding: 15px; } .project-hero h1 { font-size: 24px; } .project-meta-grid { grid-template-columns: 1fr 1fr; } }
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.
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.
Ensure your ESP32 is unplugged while making connections. Follow this master wiring 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 |
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.
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.
Use the Library Manager to install: ESPAsyncWebServer, AsyncTCP, Adafruit DHT, Adafruit GFX, and Adafruit SSD1306.
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.
#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);
}