Free Nationwide Doorstep Delivery on orders over ₹499
← All 10 Projects•Advanced•75 mins

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.

Real-World Engineering Application

Building automation systems, automated HVAC staging, and low-voltage industrial machine triggers.

Physics & Working Principle

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.

Key Learning Outcome:Understand galvanic isolation, flyback diodes, normally open (NO) vs normally closed (NC) contacts, and safe low-voltage switching.

Pin Connection & Wiring Table

Component Pin / TerminalMicrocontroller Pin (ESP32 / Arduino)Wiring Note
Relay VCCVIN / 5VPower supply for relay coil
Relay GNDGNDCommon ground
Relay INGPIO 23Relay trigger pin
Relay COM & NOExternal 5V DC load loopSeries switch for low-voltage load

Step-by-Step Plug & Play Assembly

1

Connect relay module VCC to 5V and GND to GND.

2

Connect relay IN to GPIO 23.

3

Wire the DC lamp in series with the relay COM and NO terminals and a 5V DC battery or USB power source.

4

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);
}
Code Logic Breakdown:

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

The relay makes an audible click every 3 seconds, alternating the low-voltage DC light on and off safely.
Troubleshooting Tips
  • •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.
Electrical Safety Directives
  • •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.
Companion Resources

Related Book Chapter & Hardware Kit

Covered in depth within Chapter 11: Hands-on Electronics Projects. Build this easily with the IoT Innovator Kit.