🏠 Home Automation Hub
Take control of your room with an ESP32 web server and relay module.
Overview
Relays are electrically operated switches. They allow a low-voltage microcontroller (like the 3.3V ESP32) to safely switch high-voltage loads (like 120V/240V lamps or fans).
What you'll learn: Relay module logic (active low vs active high), web server routing, and controlling multiple digital outputs from a web interface.
Estimated time: 1.5-2 hours. Difficulty: ⭐⭐⭐ Intermediate.
Components Needed
| Component | Specification | Qty | Notes |
|---|---|---|---|
| ESP32 Development Board | WiFi enabled | 1 | |
| 4-Channel Relay Module | 5V Coil, 3.3V input tolerant | 1 | Opto-isolated preferred |
| Jumper Wires | Female-to-Male | ~6 | |
| Appliance/Lamp | For testing | 1 | USE CAUTION WITH AC VOLTAGE |
Step-by-Step Tutorial
1
Wire the Relays
Connect Relay VCC to ESP32 5V (VIN), GND to GND. Connect IN1, IN2, IN3, IN4 to GPIOs 13, 12, 14, 27.
2
Setup the Web Server
We will use
ESPAsyncWebServer to serve an HTML page with toggle buttons for each relay.3
Upload Code
Enter your WiFi credentials and upload. Find the IP address in the Serial Monitor.
4
Test Switching
Click the buttons on the web interface. You should hear the relays "click" as they switch states.
5
AC Wiring (Advanced)
Warning: High Voltage. Splice the hot wire of an appliance cord and connect it to the Common (COM) and Normally Open (NO) terminals of a relay.
Many relay modules are "Active Low", meaning pulling the pin to LOW turns the relay ON. Keep this in mind when writing your logic.
Code / Configuration
home_hub.ino
INO
// Home Automation Hub - Volt X
#include <WiFi.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
const int relay1 = 13;
bool relay1State = false;
AsyncWebServer server(80);
void setup() {
Serial.begin(115200);
pinMode(relay1, OUTPUT);
digitalWrite(relay1, HIGH); // Active low relay off
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) { delay(1000); }
Serial.println(WiFi.localIP());
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
String html = "<html><body><h1>Volt X Hub</h1>";Reviews & Ratings
—0 reviews
Sign in to leave a review
Loading reviews...