Aim: Advanced burglar alarm security system with the help of PIR sensor, buzzer
and keypad. (Alarm gets disabled if correct keypad password is entered)
Procedure
Advanced Bulgar 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
3. LDR
4. 10K Resistor
5. LED
6. Buzzer
7. 9V Battery
Circuit Diagram & Connections:
Working of PIR Sensor:
PIR has multiple variables that affect the sensor’s input and output.
30
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 switchingwhen it detects a moving target.
Copy the code and paste it to your Arduino IDE and then compile & finally, upload it
to the Arduino Board.
Arduino Code
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;
}
}
}
}
32