Home Security Alarm Using PIR Sensor & Arduino for Night

Home Security Alarm Using PIR Sensor & Arduino for Night (Last Updated On: December 1, 2018)

Home Security Alarm Using PIR Sensor & Arduino for Night:

In this project we will discuss about Home Security Alarm Using PIR Sensor & Arduino for Night time only.
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 – (Buy Online from Amazone)
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 sensors input and output.

Home Security Alarm Using PIR Sensor & Arduino for Night

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 infact 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.

int ledPin = 5; // choose the pin for the LED
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:




Leave a Reply

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