Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » Home Security Alarm Using PIR Sensor & Arduino for Night
Arduino Projects

Home Security Alarm Using PIR Sensor & Arduino for Night

Mamtaz AlamBy Mamtaz AlamUpdated:December 23, 20234 Comments3 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
Home Security Alarm Using PIR Sensor & Arduino for Night
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Home Security Alarm Using PIR Sensor & Arduino for Night:

In this project, we will discuss Home Security Alarm Using PIR Sensor & Arduino for Night time only. Earlier we discussed about PIR Sensor and Arduino interfacing to learn the basics.

A night security light only turns on when it’s dark and when movement is detected. The lamp & the buzzer turns on when it’s dark & movement is detected. When there’s light, the lamp is turned off, even when motion is detected.


Components Required:

  1. Arduino UNO Board
  2. PIR Sensor HC-SR501
  3. LDR
  4. 10K Resistor
  5. LED
  6. Buzzer
  7. 9V Battery




Circuit Diagram & Connections:

Assemble the circuit as shown in the figure below.

Home Security Alarm Using PIR Sensor & Arduino for Night


Working of PIR Sensor:

PIR sensors are more complicated than many of the other sensors explained in these tutorials (like photocells, FSRs and tilt switches) because there are multiple variables that affect the sensor’s input and output.

Working of PIR Sensor

The PIR sensor itself has two slots in it, each slot is made of a special material that is sensitive to IR. The lens used here is not really doing much and so we see that the two slots can ‘see’ out past some distance (basically the sensitivity of the sensor). When the sensor is idle, both slots detect the same amount of IR, the ambient amount radiated from the room or walls or outdoors. When a warm body like a human or animal passes by, it first intercepts one-half of the PIR sensor, which causes a positive differential change between the two halves. When the warm body leaves the sensing area, the reverse happens, whereby the sensor generates a negative differential change. These change pulses are what is detected.


Working of the Project:

The circuit is in fact a dark activated switch that measures the ambient light level and will enable the system only when ambient light level is below a threshold value. Here an LDR (Light Dependent Resistor) is used to measure the light level. The alarm system is triggered when a “Logic High (H)” level signal is detected at its sensor input port.

Home Security Alarm Using PIR Sensor & Arduino for Night

The best sensor you can use to detect an intrusion is the Passive Infrared (PIR) Sensor. The PIR Sensor detects the motion of a human body by the change in surrounding ambient temperature when a human body passes across, and effectively controls the switching
when it detects a moving target.



Source Code/Programs:

The code for Home Security Alarm Using PIR Sensor & Arduino for Night is given below. Copy the code and paste it to your Arduino IDE and then compile & finally, upload it to the Arduino Board.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
int Buzzer = 6; // choose the pin for the Buzzer
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(Buzzer, OUTPUT); // declare Buzzer as output
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
}
void loop(){
val = digitalRead(inputPin); // read input value
int value_ldr = analogRead(A0); // read LDR value
if((300>value_ldr) && ( val==HIGH) ){
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
digitalWrite(Buzzer, 1); // turn Buzzer ON
delay(5000);
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
digitalWrite(Buzzer, 0); // turn Buzzer OFF
if (pirState == HIGH){
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}
}




Video Preview & Demonstration:

PIR Sensor Based Night Security Alarm Using Arduino
Watch this video on YouTube.

If you are facing any issue with the PIR Sensor prformance, then you can refer to a better PIR Sensor called Panasonic PIR Sensor. The result will be highly accurate.

You can check this post for some other similar Arduino Project: Top 15 Latest Sensor Projects for Arduino Beginners

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleWireless Charging Technology : The Fuel of Future
Next Article IoT BPM Monitoring on ThingSpeak using ESP8266 & Pulse Sensor

Related Posts

DC Energy Meter using Arduino

Build a DC Energy Meter using Arduino – 32V/5A

Updated:August 26, 20252K
Interfacing ADXL375 Accelerometer with Arduino

Interfacing ADXL375 Accelerometer with Arduino (±200g)

Updated:June 28, 2025
PZEM-004T Arduino Energy Meter

DIY AC Energy Meter using PZEM-004T & Arduino

Updated:March 6, 20258K
Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Updated:February 2, 20259K
Password Based Door Lock Security System Using Arduino & Keypad

Password Based Door Lock Security System Using Arduino & Keypad

Updated:February 2, 20252436K
Earthquake Detector Alarm with with Accelerometer & Arduino

Earthquake Detector Alarm with Accelerometer & Arduino

Updated:February 2, 2025661K
View 4 Comments

4 Comments

  1. Pavan Rajure on March 20, 2020 6:39 PM

    IF PROJECT REPORT IS AVAILABLE SO PLZ MAIL ME [email protected]

    Reply
  2. jagadeesh on November 14, 2021 10:24 PM

    header file name ?

    Reply
  3. Franklin on January 3, 2023 4:46 AM

    Please I think the is an error in the program, because I have been compiling my own and it is not going

    Reply
  4. Pranesh on August 4, 2023 11:52 AM

    give power to arduino directly, not by battery . recorrect the source code .give proper setting up of this project. its my kind request

    Reply

CommentsCancel reply

Latest Posts

ESP32 Fingerprint Attendance System with Live Web Dashboard

June 14, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
Top Posts & Pages
  • IoT Based PM & Air Quality Monitoring System using ESP32
    IoT Based PM & Air Quality Monitoring System using ESP32
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • How to use INA219 DC Current Sensor Module with Arduino
    How to use INA219 DC Current Sensor Module with Arduino
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU
    High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU
  • L293D Dual H-Bridge Motor Driver IC Pins, Circuit, Working
    L293D Dual H-Bridge Motor Driver IC Pins, Circuit, Working
  • IoT Based Electricity Energy Meter using ESP32 & Blynk
    IoT Based Electricity Energy Meter using ESP32 & Blynk
  • Designing of MPPT Solar Charge Controller using Arduino
    Designing of MPPT Solar Charge Controller using Arduino
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (205)
    • ESP32 MicroPython (7)
    • ESP32 Projects (82)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.