Build Your Own Home Security System Using a PIR Sensor, Buzzer, and LCD Display

Build Your Own Home Security System Using a PIR Sensor, Buzzer, and LCD Display


Security is a priority for everyone, and with modern technology, creating a custom home security system is more accessible than ever. In this blog, we will guide you through building a **simple yet powerful motion detection security system** using a **PIR sensor**, an **LED**, a **buzzer**, and a **20x4 I2C LCD** to display real-time motion alerts.



This system can detect any motion in the designated area, alert you with both visual (LED) and auditory (buzzer) signals, and log the status on the LCD screen. Whether you're monitoring a room, an entrance, or a garage, this project provides a cost-effective way to improve your home's security.


Why Use a PIR Sensor?


A **PIR (Passive Infrared) sensor** is commonly used for detecting motion. It senses the infrared radiation emitted by humans and animals. When a warm body passes in front of the sensor, it detects this change and triggers the system.


**Advantages of PIR Sensors**:

- Low-cost and reliable

- Low power consumption

- Works well for general motion detection

- Ideal for home automation and security systems


What You’ll Need:


Here’s a list of components for this project:

- **Arduino Uno** – The brain of your system.

- **PIR Sensor** – To detect any motion in the room.

- **20x4 I2C LCD Display** – To show motion status.

- **Buzzer** – For audible alerts.

- **LED** – For visual alerts when motion is detected.

- **220Ω Resistor** – To limit the current for the LED.

- **Jumper Wires** – For connections.

- **Breadboard** – For easy prototyping.


---


# The Concept


The goal is to create a **motion detection system** that does the following:

- **Detects motion** using the PIR sensor.

- **Triggers an LED** and **sounds a buzzer** when motion is detected.

- **Displays real-time information** on a 20x4 LCD display.

- **Resets** once motion stops, preparing the system for the next detection.


---


# Wiring the Compone

. **PIR Sensor**

- **VCC**: Connect to the 5V pin on the Arduino.

- **GND**: Connect to GND on the Arduino.

- **OUT**: Connect to Pin 2 on the Arduino.


#### 2. **LED**

- **Anode (long leg)**: Connect to Pin 13 on the Arduino via a 220Ω resistor.

- **Cathode (short leg)**: Connect to GND on the Arduino.


#### 3. **Buzzer**

- **Positive (long leg)**: Connect to Pin 12 on the Arduino.

- **Negative (short leg)**: Connect to GND.


#### 4. **20x4 I2C LCD Display**

- **SDA**: Connect to A4 on the Arduino.

- **SCL**: Connect to A5 on the Arduino.

- **VCC**: Connect to 5V.

- **GND**: Connect to GND.


---


# Schematic


Here’s a simplified version of how your components should be connected:


- **PIR Sensor**: Power to 5V and GND, Output to Pin 2.

- **LED**: Positive (long leg) to Pin 13 (with 220Ω resistor), Negative (short leg) to GND.

- **Buzzer**: Positive to Pin 12, Negative to GND.

- **I2C LCD**: SDA to A4, SCL to A5, VCC to 5V, and GND to GND.


This setup will allow the Arduino to respond to the motion detected by the PIR sensor and reflect the status on both the buzzer, LED, and the LCD.


---


### The Code


Here’s the code that will bring your project to life:


```cpp

#include <Wire.h>

#include <LiquidCrystal_I2C.h>


// Set the LCD I2C address (you might need to adjust this based on your display)

LiquidCrystal_I2C lcd(0x27, 20, 4);


int pirPin = 2; // Pin connected to PIR sensor

int ledPin = 13; // Pin connected to LED

int buzzerPin = 12; // Pin connected to Buzzer

int pirState = LOW; // Variable to track motion state

int pirVal = 0; // Reading from PIR sensor


void setup() {

  pinMode(pirPin, INPUT); // Set PIR sensor as input

  pinMode(ledPin, OUTPUT); // Set LED as output

  pinMode(buzzerPin, OUTPUT); // Set buzzer as output


  Serial.begin(9600); // Start serial monitor

  lcd.init(); // Initialize the LCD

  lcd.backlight(); // Turn on the backlight

  lcd.setCursor(0, 0); // Set cursor to the first line

  lcd.print("Home Security"); // Initial message on the display

  delay(2000); // Wait for 2 seconds

  lcd.clear(); // Clear the LCD screen

}


void loop() {

  pirVal = digitalRead(pirPin); // Read PIR sensor value


  if (pirVal == HIGH) { // If motion is detected

    digitalWrite(ledPin, HIGH); // Turn LED on

    digitalWrite(buzzerPin, HIGH); // Sound the buzzer

    if (pirState == LOW) {

      lcd.clear(); // Clear the LCD screen

      lcd.setCursor(0, 0); // Set cursor to the first line

      lcd.print("Motion Detected"); // Display motion detection message

      Serial.println("Motion detected!");

      pirState = HIGH; // Update motion state

    }

  } else { // If no motion is detected

    digitalWrite(ledPin, LOW); // Turn LED off

    digitalWrite(buzzerPin, LOW); // Stop the buzzer

    if (pirState == HIGH) {

      lcd.clear(); // Clear the LCD screen

      lcd.setCursor(0, 0); // Set cursor to the first line

      lcd.print("No Motion"); // Display no motion message

      Serial.println("Motion ended!");

      pirState = LOW; // Update motion state

    }

  }


  lcd.setCursor(0, 2); // Set cursor to the third line

  lcd.print("PIR Status: "); // Display PIR status

  if (pirVal == HIGH) {

    lcd.print("HIGH "); // Display HIGH if motion is detected

  } else {

    lcd.print("LOW "); // Display LOW if no motion is detected

  }

}

```


---


# How the Code Works


1. **Libraries and Initialization:**

   - We use the `LiquidCrystal_I2C` library to interface with the LCD over I2C.

   - The **PIR sensor** is connected to **Pin 2**, and its state is read with `digitalRead()`.

   - The **LED** and **buzzer** are controlled by the Arduino, turning on when motion is detected and off when no motion is detected.


2. **Looping Logic:**

   - In the `loop()` function, the PIR sensor continuously checks for motion.

   - If motion is detected, the system turns on the LED and buzzer and displays "Motion Detected" on the LCD.

   - If no motion is detected, the system turns off the LED and buzzer and displays "No Motion" on the LCD.


3. **Real-Time Feedback:**

   - The status of the PIR sensor is always visible on the LCD screen, allowing you to monitor the security system in real time.


---


# Expanding the Project


Now that you have the basics of a **home security system**, you can expand this project further:

- **Wireless Alerts**: Add a GSM module to send SMS notifications when motion is detected.

- **Camera Integration**: Add a camera module to capture images or record video when motion is detected.

- **Multiple Sensors**: Use multiple PIR sensors to cover larger areas.


---


# Conclusion


With just a few components and some basic coding, you've built a functional **home security system** that provides both audible and visual alerts. This project is a great starting point for anyone interested in **home automation**, **security systems**, or **Arduino projects**. By understanding how the PIR sensor works and integrating it with other components, you now have the knowledge to create even more advanced systems.


Now your home is better protected, and you have control over your personal security setup. Happy building!

Comments

Popular posts from this blog

Temperature control fan using Arduino uno ||Arduino control fan