How does the security alarm circuit works?
When power is turned on, the circuit goes into standby mode, and this condition is indicated by “SECURITY ALARM” in the LCD screen.Note that here a N/O reedswitch + bar magnet combination is used to detect any mishaps, and hence the reed switch should be in “closed”state at standby mode. When reed switch is opened, pin 2 of Arduino goes high with the help of the pull-up resistor R2, and the alert signal is available through the piezo-speaker PZ1 (not an active piezo-buzzer).
At the same instant “ALERT ACTIVATED” message is displayed on the LCD screen. Once triggered, this “ALERT ACTIVATED” message remains lit until the system is resetted by the “reset” switch in the arduino board. In this way the owner is informed that the alert went off atleast once during his/her absence. Components R1 (100R) is added to limit the operating current of the LCD backlight unit, and P1 (10K) is the display contrast controller.
Arduino Sketch
- // ARDUINO-BASED SECURITY ALARM //
- // T.K.Hareendran //
- #include <LiquidCrystal.h>
- int sensPin = 2; // Sensor Input Pin
- int ledPin = 13; // LED output Pin
- int pzSpeaker = 5; //Piezo-speaker Output Pin
- int val = 0; // variable for reading the Input Pin status
- LiquidCrystal lcd (7, 8, 9, 10, 11, 12);
- void setup() {
- pinMode(sensPin, INPUT); // Set Sensor as input
- pinMode(pzSpeaker, OUTPUT); // Set Piezo-Speaker as output
- pinMode(ledPin, OUTPUT); // Set LED as output
- lcd.begin(16, 2);
- lcd.print(” SECURITY ALARM”);
- }
- void loop(){
- val = digitalRead(sensPin); // read input value
- if (val == HIGH) { // check if the input is HIGH
- digitalWrite(ledPin, HIGH); // turn LED ON
- lcd.setCursor(0, 1);
- lcd.print(“ALERT ACTIVATED!”);
- playTone(500, 600);
- delay(100);
- playTone(500, 800);
- delay(100);
- } else {
- digitalWrite(ledPin, LOW); // turn LED OFF
- playTone(0, 0);
- delay(300);
- }
- }
- // duration in mSecs, frequency in hertz
- void playTone(long duration, int freq) {
- duration *= 1000;
- int period = (1.0 / freq) * 1000000;
- long elapsed_time = 0;
- while (elapsed_time < duration) {
- digitalWrite(pzSpeaker,HIGH);
- delayMicroseconds(period / 2);
- digitalWrite(pzSpeaker, LOW);
- delayMicroseconds(period / 2);
- elapsed_time += (period);
- }
- }
For more detail: Arduino Security Alarm with Reed Switch