Useful Stuff

Smart Home Security System using Arduino and IoT

Project Overview

This Smart Home Security System uses an Arduino, PIR motion sensor, RFID module, and ESP8266 Wi-Fi module to detect unauthorized entry, send alerts, and allow secure access via RFID authentication. The system also integrates a buzzer and an LCD display for real-time status updates.

1. Components Required

ComponentQuantityDescription
Arduino Uno/Nano1Microcontroller Board
ESP8266 Wi-Fi Module1For Internet connectivity
PIR Motion Sensor1Detects movement
RFID Module (RC522)1For access control
Buzzer1Alarm system
16×2 LCD Display (I2C)1Displays system status
Relay Module (5V)1Controls door lock
Jumper WiresAs neededFor connections
Breadboard1For prototyping
5V Power Supply1To power ESP8266 and relays

2. Circuit Diagram and Pin Connections

2.1 PIR Motion Sensor to Arduino

Sensor PinArduino Pin
VCC5V
GNDGND
OUTD2

2.2 RFID Module (RC522) to Arduino

RFID PinArduino Pin
SDAD10
SCKD13
MOSID11
MISOD12
IRQNot connected
GNDGND
RSTD9
3.3V3.3V

2.3 Buzzer and Relay to Arduino

ComponentArduino Pin
BuzzerD3
RelayD4

2.4 ESP8266 to Arduino

ESP8266 PinArduino Pin
VCC3.3V
GNDGND
TXRX (via voltage divider)
RXTX
CH_PD3.3V

3. Code Implementation

This Arduino code integrates RFID authentication, motion detection, and remote alerts via ESP8266.

Required Libraries

  1. MFRC522.h (for RFID module)
  2. ESP8266WiFi.h (for Wi-Fi connection)
  3. ESP8266WebServer.h (for web server control)
  4. Wire.h and LiquidCrystal_I2C.h (for LCD display)

Install these libraries via Arduino Library Manager.

C
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <MFRC522.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

const char* ssid = "Your_SSID";
const char* password = "Your_PASSWORD";
ESP8266WebServer server(80);

#define PIR_SENSOR D2
#define BUZZER D3
#define RELAY D4
#define RST_PIN D9
#define SS_PIN D10

MFRC522 mfrc522(SS_PIN, RST_PIN);
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
    Serial.begin(115200);
    WiFi.begin(ssid, password);
    
    while (WiFi.status() != WL_CONNECTED) {
        delay(1000);
        Serial.println("Connecting to Wi-Fi...");
    }
    
    Serial.println("Connected to Wi-Fi");
    Serial.println(WiFi.localIP());
    
    pinMode(PIR_SENSOR, INPUT);
    pinMode(BUZZER, OUTPUT);
    pinMode(RELAY, OUTPUT);
    digitalWrite(RELAY, HIGH);
    digitalWrite(BUZZER, LOW);
    SPI.begin();
    mfrc522.PCD_Init();
    lcd.begin();
    lcd.backlight();
    lcd.setCursor(0, 0);
    lcd.print("Security System");
    
    server.on("/alert", []() {
        server.send(200, "text/plain", "Intrusion detected!");
    });
    
    server.on("/unlock", []() {
        digitalWrite(RELAY, LOW);
        delay(5000);
        digitalWrite(RELAY, HIGH);
        server.send(200, "text/plain", "Door Unlocked");
    });
    
    server.begin();
    Serial.println("Server started");
}

void loop() {
    server.handleClient();
    
    // PIR Motion Detection
    if (digitalRead(PIR_SENSOR) == HIGH) {
        Serial.println("Motion Detected!");
        lcd.setCursor(0, 1);
        lcd.print("Motion Detected!");
        digitalWrite(BUZZER, HIGH);
        server.send(200, "text/plain", "Intrusion Alert!");
        delay(5000);
        digitalWrite(BUZZER, LOW);
        lcd.setCursor(0, 1);
        lcd.print("                ");
    }
    
    // RFID Authentication
    if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
        String uid = "";
        for (byte i = 0; i < mfrc522.uid.size; i++) {
            uid += String(mfrc522.uid.uidByte[i], HEX);
        }
        Serial.print("Card UID: ");
        Serial.println(uid);
        
        if (uid == "YOUR_CARD_UID") {
            lcd.setCursor(0, 1);
            lcd.print("Access Granted");
            digitalWrite(RELAY, LOW);
            delay(5000);
            digitalWrite(RELAY, HIGH);
        } else {
            lcd.setCursor(0, 1);
            lcd.print("Access Denied");
            digitalWrite(BUZZER, HIGH);
            delay(3000);
            digitalWrite(BUZZER, LOW);
        }
        delay(2000);
        lcd.setCursor(0, 1);
        lcd.print("                ");
    }
}

4. Working Explanation

  1. The PIR sensor detects motion and triggers the buzzer.
  2. The RFID module verifies access and controls the door lock via the relay.
  3. The ESP8266 allows remote monitoring and door unlocking.
  4. Alerts are sent to the web server when motion is detected.
  5. The LCD display provides real-time security status.

Projects for Beginners and Enthusiasts

Click here: https://iotbyhvm.ooo/10-exciting-arduino-projects-for-beginners-and-enthusiasts/

Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. Tech enthusiast and IT professional with a B.Tech in IT, PG Diploma in IoT from CDAC, and 6 years of industry experience. Founder of HVM Smart Solutions, blending technology for real-world solutions. As a passionate technical author, I simplify complex concepts for diverse audiences. Let's connect and explore the tech world together! If you want to help support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning! Linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *