Intruder Detection System using PIR and Arduino Part 1

https://ogbugbu-technologies.com.ng/

🚨 Arduino-Based Intruder Detection System: A Project Guide

This article outlines the design and operation of a cost-effective and efficient intruder detection system using an Arduino Uno as the central microcontroller, a Passive Infrared (PIR) sensor for motion detection, and visual/audible notification via a red LED, a green LED, and a buzzer. This project is ideal for beginners and provides a solid foundation in home security automation.


💡 Core Components and Function

The system operates by continuously monitoring for changes in infrared radiation using the PIR sensor. Any detected movement triggers an alert state, changing the system’s status from ‘Standby’ to ‘Alert’.

ComponentRoleFunctionality
Arduino UnoMicrocontroller (The Brain)Processes data from the PIR sensor and controls the state of the LEDs and the buzzer.
PIR SensorMotion Detector (The Eyes)Detects movement of warm objects (like a human) by sensing changes in infrared light. Outputs a HIGH digital signal when motion is detected.
Green LEDStatus IndicatorIlluminates when the system is in the Standby (No motion detected) state.
Red LEDAlert IndicatorIlluminates when the system is in the Alert (Motion detected) state.
BuzzerAudible NotificationEmits an alarm sound when the system is in the Alert state.

Export to Sheets


Video Description of Project

🔌 Hardware Connection (Wiring)

The components are connected to the Arduino Uno as follows (pin numbers are illustrative and can be modified in the code):

  1. PIR Sensor:
    • VCC → Arduino 5V
    • GND → Arduino GND
    • OUT → Arduino Digital Pin 7 (Input)
  2. Green LED (Standby):
    • Anode (Longer Leg) → Arduino Digital Pin 9 (via a 220Ω resistor)
    • Cathode (Shorter Leg) → Arduino GND
  3. Red LED (Alert):
    • Anode (Longer Leg) → Arduino Digital Pin 8 (via a 220Ω resistor)
    • Cathode (Shorter Leg) → Arduino GND
  4. Buzzer:
    • Positive (+) Pin → Arduino Digital Pin 10 (Output)
    • Negative (-) Pin → Arduino GND

Note: A current-limiting resistor (typically 220Ω) is crucial for both LEDs to prevent them from burning out.


💻 System Logic (Arduino Code Concept)

The Arduino code uses the digital input from the PIR sensor to decide the system’s state:

  1. Initialization (setup()):
    • Configure PIR sensor pin (e.g., D7) as an INPUT.
    • Configure LED and Buzzer pins (e.g., D8, D9, D10) as OUTPUTs.
    • Set the initial state to Standby (Green LED ON, Red LED and Buzzer OFF).
  2. Continuous Monitoring (loop()):
    • The Arduino constantly reads the digital state of the PIR sensor pin.
    • If motion is detected (PIR output is HIGH):
      • Transition to Alert state.
      • Turn the Green LED OFF.
      • Turn the Red LED ON.
      • Activate the Buzzer (use tone() for a continuous or pulsed alarm).
    • If no motion is detected (PIR output is LOW):
      • Transition to Standby state.
      • Turn the Green LED ON.
      • Turn the Red LED OFF.
      • Deactivate the Buzzer (use noTone()).

🛡️ Conclusion: Enhanced Security

This simple circuit provides an excellent introduction to building security systems. By leveraging the Arduino’s programmability, the system offers instantaneous visual and audible feedback upon detecting an intruder. The green LED reassures the user that the system is armed and monitoring, while the red LED and buzzer clearly communicate an active alert, serving both as a warning to the user and a deterrent to the intruder.

For more information on the hardware setup and code, you can check out this video: DIY HOMEMADE PIR ALARM SYSTEM with Arduino. This video describes a similar project and can help with the wiring and coding aspects of building your own PIR alarm system.

Project Code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// LCD setup (address 0x27 or 0x3F depending on module)
// If it doesn't work, change the address
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Pins
const int pirPin = 11;      // PIR sensor pin
const int buzzerPin = 2;    // Buzzer pin
const int ledDetect1 = 3;   // First LED for motion detected
const int ledDetect2 = 4;   // Second LED for motion detected
const int ledIdle1 = 5;     // First LED for no motion
const int ledIdle2 = 6;     // Second LED for no motion

int val = 0; // Value read from PIR

void setup() {
  pinMode(pirPin, INPUT);
  pinMode(buzzerPin, OUTPUT);
  pinMode(ledDetect1, OUTPUT);
  pinMode(ledDetect2, OUTPUT);
  pinMode(ledIdle1, OUTPUT);
  pinMode(ledIdle2, OUTPUT);

  digitalWrite(buzzerPin, LOW);
  digitalWrite(ledDetect1, LOW);
  digitalWrite(ledDetect2, LOW);
  digitalWrite(ledIdle1, LOW);
  digitalWrite(ledIdle2, LOW);

  Serial.begin(9600);

  // Initialize LCD
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("  PIR Sensor");
  lcd.setCursor(0, 1);
  lcd.print("   Ready...");
  delay(2000);
  lcd.clear();
}

void loop() {
  val = digitalRead(pirPin);

  if (val == HIGH) {
    // Motion detected
    Serial.println("Motion detected!");
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(" Motion Detected!");
    lcd.setCursor(0, 1);
    lcd.print("  ALERT!");

    // Blink motion LEDs and buzzer
    digitalWrite(ledDetect1, HIGH);
    digitalWrite(ledDetect2, HIGH);
    digitalWrite(buzzerPin, HIGH);
    delay(200);

    digitalWrite(ledDetect1, LOW);
    digitalWrite(ledDetect2, LOW);
    digitalWrite(buzzerPin, LOW);
    delay(200);

    // Turn off idle LEDs
    digitalWrite(ledIdle1, LOW);
    digitalWrite(ledIdle2, LOW);
  } 
  else {
    // No motion
    Serial.println("No motion...");
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(" No Motion...");
    lcd.setCursor(0, 1);
    lcd.print(" Safe :)");

    // Turn off motion LEDs and buzzer
    digitalWrite(ledDetect1, LOW);
    digitalWrite(ledDetect2, LOW);
    digitalWrite(buzzerPin, LOW);

    // Turn on idle LEDs
    digitalWrite(ledIdle1, HIGH);
    digitalWrite(ledIdle2, HIGH);

    delay(500);
  }
}

Leave a Reply

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