SECURITY ALARM PROJECT USING PIR SENSOR AND ARDUINO UNO

Home Security Alarm Using PIR Sensor & Arduino | MakeMindz
🚨 Intermediate Project — Dark-Activated

Home Security Alarm
PIR Sensor + Arduino Uno

A smart, dark-activated intrusion alarm using HC-SR501, LDR, 16×2 LCD, buzzer & LED. Only triggers at night — energy-efficient and ready for real-world home security.

HC-SR501 PIR LDR Night Mode 16×2 LCD Alert Buzzer + LED Arduino UNO ⏱ 45 min build
💡 What makes this special Unlike basic motion alarms, this system checks ambient light via an LDR before triggering. Daylight → system sleeps. Darkness + motion → full alarm activates. This dual-condition logic is exactly how professional security systems work.
01

Components Required

🔵
Arduino Uno
👁
HC-SR501 PIR Sensor
☀️
LDR Sensor
2 × 1kΩ Resistors
🔴
Red LED
🔊
Buzzer
🎛
Potentiometer
📟
16×2 LCD Display
🔋
9V Battery
🔌
Jumper Wires
🖇
Arduino USB Cable
02

Circuit Diagram

pir_security_alarm.json
PIR Security Alarm — Full Circuit Diagram ARDUINO UNO 5V GND A0 D2 D7 D8 D12(RS) D11(E) D5(D4) D4(D5) D3(D6) D2... ATmega328P 16 MHz USB PWR HC-SR501 PIR VCC OUT GND LDR + DIVIDER LDR 1kΩ 5V A0 GND LED + 220Ω BUZZER + 16×2 LCD DISPLAY Motion Detected! Intruder Alert! RS,E,D4-D7 → Arduino Digital Pins VSS→GND VDD→5V VO→Potentiometer PIR OUT → D2 LDR → A0 LCD bus Wire Legend 5V Power GND PIR OUT → D2 LDR → A0 LED → D7 Buzzer → D8 LCD → D3–D5,11,12
PIR→D2 · LDR→A0 · LED→D7 · Buzzer→D8 · LCD→RS(D12),E(D11),D4-D7(D5,D4,D3,D2*) · All GND connected
03

Pin Connection Tables

PIR Sensor (HC-SR501)

PIR PinArduinoNote
VCC5VPower
GNDGNDGround
OUTDigital Pin 2HIGH when motion detected

LDR (Voltage Divider)

LDR ConnectionArduinoNote
LDR End 15VTop of voltage divider
LDR End 2 + Resistor (1kΩ → GND)A0Junction reads light level
Resistor other endGNDBottom of divider

Output Devices

DeviceArduino PinNote
LEDDigital Pin 7Via 220Ω resistor to GND
Buzzer (+)Digital Pin 8Negative → GND

16×2 LCD Display

LCD PinArduino / ConnectionNote
VSSGNDPower ground
VDD5VPower supply
VOPotentiometer middleContrast control
RSDigital Pin 12Register select
EDigital Pin 11Enable
D4–D7Pins 5, 4, 3, 24-bit data mode
04

Step-by-Step Wiring

STEP 1

Wire the PIR Sensor (HC-SR501)

Locate the 3 pins on the back of the sensor module

VCC Arduino 5V  |  GND GND  |  OUT D2
STEP 2

Build the LDR Voltage Divider

LDR and 1kΩ resistor form a divider — the junction gives light-level voltage

LDR end 1 5V  |  LDR end 2 A0 + 1kΩ resistor to GND
STEP 3

Connect LED with Current-Limiting Resistor

Always use a 220Ω resistor in series to protect the LED

LED(+) 220Ω D7  |  LED(−) GND
STEP 4

Connect the Buzzer

Buzzer(+) D8  |  Buzzer(−) GND
STEP 5

Wire the 16×2 LCD (4-bit mode)

Connect potentiometer middle pin to VO for contrast adjustment

RSD12 · ED11 · D4D5 · D5D4 · D6D3 · D7D2
STEP 6

Power & Ground Rails

Connect all VCC pins to Arduino 5V and all GND pins to Arduino GND via the breadboard rails

⚠️ PIR Warm-Up Time The HC-SR501 needs 30–60 seconds to stabilize after power-on. During this time it may give false HIGH outputs — this is normal. Add a warm-up delay in your setup() function.
05

How the System Works

1

Light Detection — LDR reads ambient light

The LDR voltage divider outputs a value (0–1023) to analog pin A0. Bright light = high reading. Dark = low reading (below ~400). The system only arms itself when it's dark.

2

Motion Sensing — PIR detects IR changes

The HC-SR501 has two IR-sensitive slots. Ambient radiation is equal when idle. A warm body moving past creates an imbalance between the slots, generating a positive differential → digital HIGH on the OUT pin.

3

Dual Condition Check — Dark AND Motion

Arduino checks: Is lightLevel < 400 (dark)? AND Is pirState == HIGH (motion)? Both must be true to trigger the alarm. This prevents daytime false alarms.

4

Alert Activated — Buzzer + LED + LCD

LED turns ON (D7), buzzer sounds (D8), and the LCD displays "Motion Detected!" on line 1 and "Intruder Alert!" on line 2.

5

All-Clear — Alarm resets automatically

When no motion is detected, LED and buzzer turn OFF. LCD displays "System Armed..." and waits for the next trigger.

06

Arduino Code

pir_security_alarm.ino
// ── PIR Security Alarm | MakeMindz.com ───────────────────
// Dark-activated home security alarm with PIR + LDR + LCD
// Activates buzzer + LED + LCD message when motion detected at night

#include <LiquidCrystal.h>

// ── Pin Definitions ──────────────────────────────────────
const int pirPin   = 2;    // PIR OUT pin
const int ldrPin   = A0;   // LDR voltage divider output
const int ledPin   = 7;    // Red LED
const int buzPin   = 8;    // Buzzer
int       lightThr  = 400;  // Below this = dark. Adjust for your room.

// ── LCD: RS, E, D4, D5, D6, D7 ───────────────────────────
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// ── Setup ─────────────────────────────────────────────────
void setup() {
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(buzPin, OUTPUT);

  lcd.begin(16, 2);
  lcd.print("System Ready");
  lcd.setCursor(0, 1);
  lcd.print("Warming up...");

  Serial.begin(9600);
  delay(30000);   // 30s PIR warm-up

  lcd.clear();
  lcd.print("System Armed...");
}

// ── Main Loop ─────────────────────────────────────────────
void loop() {
  int lightLevel  = analogRead(ldrPin);  // Read light (0=dark,1023=bright)
  int pirState    = digitalRead(pirPin);  // HIGH = motion detected

  Serial.print("Light: "); Serial.print(lightLevel);
  Serial.print(" | PIR: "); Serial.println(pirState);

  // ── Dual condition: Dark AND Motion ──────────────────
  if (lightLevel < lightThr && pirState == HIGH) {
    // ⚠ ALARM TRIGGERED
    digitalWrite(ledPin, HIGH);
    digitalWrite(buzPin, HIGH);

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Motion Detected!");
    lcd.setCursor(0, 1);
    lcd.print("Intruder Alert!");

    Serial.println("⚠ ALARM: Motion in dark detected!");
    delay(3000);   // Hold alarm for 3 seconds

  } else {
    // ✓ Safe — reset
    digitalWrite(ledPin, LOW);
    digitalWrite(buzPin, LOW);

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("System Armed...");
    lcd.setCursor(0, 1);
    lcd.print("Light: ");
    lcd.print(lightLevel);
  }

  delay(500);
}
📚 Library Required This code uses the built-in LiquidCrystal library — it's included with Arduino IDE by default. No installation needed. Go to Sketch → Include Library → LiquidCrystal.
🎛 Calibrating the Light Threshold Open Serial Monitor (9600 baud) and read the "Light:" value in your room at night. Set lightThr to slightly above that value. Typical range: 200–500 depending on your LDR and resistor combination.
07

Tinkercad Simulation

🧪 Try the Full Circuit in Tinkercad

Pre-built simulation — adjust the PIR slider and LDR slider to test night-mode detection

Open in Tinkercad

Simulation steps:

1

Open the simulation link

Click "Open in Tinkercad" above — the complete circuit with code is already loaded

2

Start Simulation

Click the green "Start Simulation" button in the top-right panel

3

Simulate darkness (LDR)

Click on the LDR component and drag its light slider to LOW — this simulates nighttime

4

Trigger the PIR sensor

Click on the PIR sensor and trigger motion — the LED lights up, buzzer activates, and LCD shows "Motion Detected!"

5

Test daytime mode

Drag the LDR slider to HIGH (bright light) — even with PIR triggered, the alarm will NOT activate

08

Download Code

⬇ Download pir_security_alarm.ino

Complete Arduino sketch with LCD support and calibration comments

Download from Google Drive

Key Features

🌙
Dark-ActivatedLDR ensures alarm only arms at night — saves power
👤
Human Motion OnlyPIR detects IR heat from warm bodies, not pets or fans
🔊
Dual AlertAudible buzzer + visual LED for immediate attention
📟
LCD Status DisplayReal-time messages — "Armed", "Motion!", "Intruder!"
🎛
Adjustable SensitivityPIR has two trimpots for range and hold-time tuning
💰
Low Cost BuildAll components available under ₹200 / $5 total

Possible Upgrades

📱
GSM SMS Alerts
📶
WiFi IoT Notify
📸
Camera Module
🔑
Password Arming
🚨
Emergency Siren
💾
SD Card Logging
🌒
Auto Night Mode
🌐
Web Dashboard

More Arduino Projects

Beginner

Intermediate

Advanced

Comments

try for free