Arduino Security Alarm with Reed Switch

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

Arduino Security Alarm with Reed Switch

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

  1. // ARDUINO-BASED SECURITY ALARM //
  2. // T.K.Hareendran //
  3. #include <LiquidCrystal.h>
  4. int sensPin = 2; // Sensor Input Pin
  5. int ledPin = 13; // LED output Pin
  6. int pzSpeaker = 5; //Piezo-speaker Output Pin
  7. int val = 0; // variable for reading the Input Pin status
  8. LiquidCrystal lcd (7, 8, 9, 10, 11, 12);
  9. void setup() {
  10. pinMode(sensPin, INPUT); // Set Sensor as input
  11. pinMode(pzSpeaker, OUTPUT); // Set Piezo-Speaker as output
  12. pinMode(ledPin, OUTPUT); // Set LED as output
  13. lcd.begin(16, 2);
  14. lcd.print(” SECURITY ALARM”);

Arduino Security Alarm with Reed Switch schematic

  1. }
  2. void loop(){
  3. val = digitalRead(sensPin); // read input value
  4. if (val == HIGH) { // check if the input is HIGH
  5. digitalWrite(ledPin, HIGH); // turn LED ON
  6. lcd.setCursor(0, 1);
  7. lcd.print(“ALERT ACTIVATED!”);
  8. playTone(500, 600);
  9. delay(100);
  10. playTone(500, 800);
  11. delay(100);
  12. } else {
  13. digitalWrite(ledPin, LOW); // turn LED OFF
  14. playTone(0, 0);
  15. delay(300);
  16. }
  17. }
  18. // duration in mSecs, frequency in hertz
  19. void playTone(long duration, int freq) {
  20. duration *= 1000;
  21. int period = (1.0 / freq) * 1000000;
  22. long elapsed_time = 0;
  23. while (elapsed_time < duration) {
  24. digitalWrite(pzSpeaker,HIGH);
  25. delayMicroseconds(period / 2);
  26. digitalWrite(pzSpeaker, LOW);
  27. delayMicroseconds(period / 2);
  28. elapsed_time += (period);
  29. }
  30. }

 

For more detail: Arduino Security Alarm with Reed Switch


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

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

Scroll to Top