ElectronLab Project Lab
Smart Home IoT Relay Switching Galvanic Isolation

Multi-Channel Smart Home Automation System with Relays & Sensors

Safely interface low-voltage 5V Arduino logic with high-voltage AC mains appliances, fans, and smart lighting using optocoupled electro-mechanical relay modules, PIR motion sensors, and automated schedules.

Reading Time 10 Minutes
Difficulty Level Intermediate
Hardware Platform Arduino Uno & 4-Ch Relay

1. Aim of the Project

Project Objective

The aim is to design an automated home electrical control hub that safely toggles multiple AC/DC appliances (lights, fans, pumps) using 5V opto-isolated relay channels triggered by manual push-buttons, passive infrared (PIR) room occupancy detection, and LDR day/night transitions.

2. Interactive 3D Assembly & Circuit Wiring Model

Rotate the 3D model 360 degrees, zoom in/out, disassemble/explode parts to inspect individual hardware layers, toggle realistic circuit wires, and click any component to inspect its engineering specifications.

3D Hardware Simulation & Assembly Lab
Left Click + Drag: Rotate Orbit (360°)
Right Click + Drag: Pan Scene
Scroll: Zoom In / Out
Click Component: Inspect Hardware Details
Hovered Component

3. Laboratory Video Masterclass Tutorial

Step-by-step video walkthrough covering breadboard circuit assembly, wiring verification, and testing. Enrolled students and instructors can access video streaming below.

2. Learning Outcomes

Optocoupler Galvanic Isolation

Understand how light-emitting diodes and phototransistors physically isolate high-voltage mains from sensitive 5V logic.

Pyroelectric Motion Sensing

Detect human infrared heat radiation changes using Fresnel lenses and dual-element PIR sensor modules.

3. Required Components

Component Name Quantity Specification Interface
Arduino Uno 1 Microcontroller Core USB / 5V
4-Channel 5V Relay Module 1 Optoisolated 10A 250VAC Switching Digital GPIO (Pins D4-D7)
HC-SR501 PIR Motion Sensor 1 Human Body Pyroelectric Motion Detector Digital Pin D2
10k LDR Light Sensor 1 Ambient Night/Day detector Analog Pin A0

4. Circuit Connections

Module Pin Arduino Pin Description
Relay IN1 (Appliance 1: Main Light) Pin D4 Active LOW relay coil trigger
Relay IN2 (Appliance 2: Fan) Pin D5 Active LOW relay coil trigger
Relay IN3 & IN4 Pins D6, D7 Auxiliary appliance channels
PIR Motion Sensor (OUT) Pin D2 Room occupancy digital signal

5. Complete Arduino Source Code

smart_home_relay_controller.ino
/*
 * Project: Smart Home Automation System with 4-Channel Relays
 * Author: ElectronLab STEM Curriculum
 */

const int RELAY_LIGHT = 4;
const int RELAY_FAN   = 5;
const int PIR_PIN     = 2;
const int LDR_PIN     = A0;

// Relays are typically Active-LOW (LOW = ON, HIGH = OFF)
#define RELAY_ON  LOW
#define RELAY_OFF HIGH

unsigned long motionOffTime = 0;
const unsigned long AUTO_OFF_DELAY = 10000; // 10 seconds timeout

void setup() {
  Serial.begin(9600);

  pinMode(RELAY_LIGHT, OUTPUT);
  pinMode(RELAY_FAN, OUTPUT);
  pinMode(PIR_PIN, INPUT);

  // Initialize all appliances to OFF
  digitalWrite(RELAY_LIGHT, RELAY_OFF);
  digitalWrite(RELAY_FAN, RELAY_OFF);

  Serial.println("Smart Home Controller Online!");
}

void loop() {
  int motionDetected = digitalRead(PIR_PIN);
  int lightLevel = analogRead(LDR_PIN); // Lower value = Darker room

  if (motionDetected == HIGH) {
    Serial.println("Motion in Room -> Turning Appliances ON");
    
    // Turn ON light only if it's dark
    if (lightLevel < 400) {
      digitalWrite(RELAY_LIGHT, RELAY_ON);
    }
    digitalWrite(RELAY_FAN, RELAY_ON);
    
    motionOffTime = millis() + AUTO_OFF_DELAY;
  }

  // Check if room has been vacant past delay timeout
  if (millis() > motionOffTime) {
    digitalWrite(RELAY_LIGHT, RELAY_OFF);
    digitalWrite(RELAY_FAN, RELAY_OFF);
  }

  delay(200);
}

6. Working Principle

Relays are electro-mechanical switches. When the Arduino pulls a control pin LOW, current energizes an internal electromagnetic coil, pulling an iron armature contact from the Normally Open (NO) terminal to the Common (COM) terminal. This mechanically completes the AC circuit safely without any electrical connection between mains 220V and the 5V microcontroller.

7. Troubleshooting Guide

Relays Turn ON When Arduino Boots

Standard relay modules are Active-LOW. Write digitalWrite(pin, HIGH) immediately inside setup() to keep them OFF during startup.