Building a Simple Alarm System with Arduino

Difficulty Level: Intermediate

In this tutorial, we’ll create a simple alarm system using Arduino, a PIR motion sensor, a buzzer, and an LED. When motion is detected, the alarm system will activate the buzzer and LED as a visual and audible alert.

Components Required

Wiring the Circuit

Follow the wiring instructions below:

Arduino Code

The following code detects motion and triggers the alarm system:


#define PIR_PIN 2     // PIR sensor input pin
#define BUZZER_PIN 8  // Buzzer output pin
#define LED_PIN 7     // LED output pin

void setup() {
  pinMode(PIR_PIN, INPUT);       // Set PIR sensor as input
  pinMode(BUZZER_PIN, OUTPUT);   // Set buzzer as output
  pinMode(LED_PIN, OUTPUT);      // Set LED as output
  Serial.begin(9600);            // Initialize serial monitor
}

void loop() {
  int pirState = digitalRead(PIR_PIN);  // Read PIR sensor

  if (pirState == HIGH) {               // If motion is detected
    digitalWrite(BUZZER_PIN, HIGH);     // Activate the buzzer
    digitalWrite(LED_PIN, HIGH);        // Turn on the LED
    Serial.println("Motion detected!");
  } else {
    digitalWrite(BUZZER_PIN, LOW);      // Turn off the buzzer
    digitalWrite(LED_PIN, LOW);         // Turn off the LED
  }

  delay(500);  // Delay between readings
}
        

Code Explanation

Testing the System

  1. Upload the code to the Arduino.
  2. Ensure all components are wired correctly.
  3. Place the PIR sensor in an area where it can detect motion.
  4. When motion is detected, the LED should light up, and the buzzer will sound.

Conclusion

You've successfully created a simple alarm system using a PIR sensor, buzzer, and LED. This project can be expanded by adding a keypad to deactivate the alarm, a display to show information, or even connecting it to a Wi-Fi module for remote monitoring.