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.
Components Required
Circuit Diagram
Pin Connection Tables
PIR Sensor (HC-SR501)
LDR (Voltage Divider)
Output Devices
16×2 LCD Display
Step-by-Step Wiring
Wire the PIR Sensor (HC-SR501)
Locate the 3 pins on the back of the sensor module
Build the LDR Voltage Divider
LDR and 1kΩ resistor form a divider — the junction gives light-level voltage
Connect LED with Current-Limiting Resistor
Always use a 220Ω resistor in series to protect the LED
Connect the Buzzer
Wire the 16×2 LCD (4-bit mode)
Connect potentiometer middle pin to VO for contrast adjustment
Power & Ground Rails
Connect all VCC pins to Arduino 5V and all GND pins to Arduino GND via the breadboard rails
How the System Works
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.
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.
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.
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.
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.
Arduino Code
// ── 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); }
LiquidCrystal library — it's included with Arduino IDE by default. No installation needed. Go to Sketch → Include Library → LiquidCrystal.
lightThr to slightly above that value. Typical range: 200–500 depending on your LDR and resistor combination.
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 TinkercadSimulation steps:
Open the simulation link
Click "Open in Tinkercad" above — the complete circuit with code is already loaded
Start Simulation
Click the green "Start Simulation" button in the top-right panel
Simulate darkness (LDR)
Click on the LDR component and drag its light slider to LOW — this simulates nighttime
Trigger the PIR sensor
Click on the PIR sensor and trigger motion — the LED lights up, buzzer activates, and LCD shows "Motion Detected!"
Test daytime mode
Drag the LDR slider to HIGH (bright light) — even with PIR triggered, the alarm will NOT activate
Download Code
⬇ Download pir_security_alarm.ino
Complete Arduino sketch with LCD support and calibration comments
Download from Google DriveKey Features
Possible Upgrades
More Arduino Projects
Beginner
Intermediate
Advanced
Comments
Post a Comment