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:
- Arduino UNO Board
- PIR Sensor HC-SR501
- LDR
- 10K Resistor
- LED
- Buzzer
- 9V Battery
Circuit Diagram & Connections:
Assemble the circuit as shown in the figure below.
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.
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.
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:
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
4 Comments
IF PROJECT REPORT IS AVAILABLE SO PLZ MAIL ME [email protected]
header file name ?
Please I think the is an error in the program, because I have been compiling my own and it is not going
give power to arduino directly, not by battery . recorrect the source code .give proper setting up of this project. its my kind request