Smart Home Automation with Low-Voltage DC Relay
Safely operate a low-voltage DC demonstration load (5V LED lamp or DC fan) using an optocoupler-isolated relay module controlled via ESP32 Wi-Fi.
Building automation systems, automated HVAC staging, and low-voltage industrial machine triggers.
Microcontrollers output only 3.3V at ~20mA, which is insufficient for motors. An optocoupler relay isolates the microcontroller electrically via light beam, while an electromagnet physically closes mechanical contacts for the secondary circuit.
Pin Connection & Wiring Table
| Component Pin / Terminal | Microcontroller Pin (ESP32 / Arduino) | Wiring Note |
|---|---|---|
| Relay VCC | VIN / 5V | Power supply for relay coil |
| Relay GND | GND | Common ground |
| Relay IN | GPIO 23 | Relay trigger pin |
| Relay COM & NO | External 5V DC load loop | Series switch for low-voltage load |
Step-by-Step Plug & Play Assembly
Connect relay module VCC to 5V and GND to GND.
Connect relay IN to GPIO 23.
Wire the DC lamp in series with the relay COM and NO terminals and a 5V DC battery or USB power source.
NEVER CONNECT RELAY CONTACTS TO WALL SOCKETS OR MAINS POWER.
Complete Tested Source Code
// NovaCircuit Project 9: Safe Low-Voltage Smart Home Automation
#include <WiFi.h>
const int RELAY_PIN = 23;
// Most hobby relay modules are ACTIVE LOW (LOW = Relay ON, HIGH = Relay OFF)
const int RELAY_ON = LOW;
const int RELAY_OFF = HIGH;
void setup() {
Serial.begin(115200);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, RELAY_OFF); // Start in safe OFF state
Serial.println("Smart Home Automation Module Initialized (Safe DC Only)");
}
void loop() {
Serial.println("Activating DC Load via Relay (Click!)...");
digitalWrite(RELAY_PIN, RELAY_ON);
delay(3000);
Serial.println("Deactivating DC Load via Relay...");
digitalWrite(RELAY_PIN, RELAY_OFF);
delay(3000);
}The code drives GPIO 23 to energize the relay coil. An audible click indicates contact closure. Because of opto-isolation, electromagnetic noise from the load does not reset the ESP32.
Expected Physical Output
- •Relay stays ON constantly: Check if your module is active-LOW or active-HIGH.
- •ESP32 restarts on relay trigger: Ensure 5V power source can supply sufficient current during coil energization.
- •CRITICAL SAFETY WARNING: This project is strictly for low-voltage DC demonstration circuits (5V/12V DC). Under no circumstances should students connect household 230V AC mains electricity.
Related Book Chapter & Hardware Kit
Covered in depth within Chapter 11: Hands-on Electronics Projects. Build this easily with the IoT Innovator Kit.