Motion-Triggered Alarm System With LEDs (Home Security System)

by isha_momin8 in Circuits > Arduino

37 Views, 0 Favorites, 0 Comments

Motion-Triggered Alarm System With LEDs (Home Security System)

Screenshot 2025-01-22 at 9.39.07 AM.png

This project simulates a home security system using an Arduino. It detects motion using a PIR sensor, activates a red LED and buzzer when motion is detected, and shows the system's status using a green LED. To make it engaging, the components are mounted inside a model house to provide a realistic demonstration. The project teaches electronics and programming fundamentals while showcasing a practical application of sensors and actuators.

Supplies

Screenshot 2025-01-21 at 9.51.34 PM.png
Screenshot 2025-01-21 at 9.51.49 PM.png

Electronics:

  1. Arduino Uno: The microcontroller board that processes input and controls output components.
  2. PIR Motion Sensor: Detects motion to trigger the alarm.
  3. Green LED: Indicates the system is armed and no motion is detected.
  4. Red LED: Signals when motion is detected (alarm mode).
  5. Piezo Buzzer: Produces a sound to alert of motion detection.
  6. Resistors (Two 330 ohms and one 10k): 330 for the LED and 10k for the NPN Transistor.
  7. Breadboard: Allows for non-permanent and flexible connections between components.
  8. Jumper Wires: Used to connect the PIR Sensor
  9. Regular Wires: To connect other components to the breadboard.
  10. USB Cable and Power Bank or 9V Battery: To power the Arduino.
  11. If you're using a 9V battery make sure to have a battery clip used for the Arduino.
  12. NPN Transistor: Make sure the number on the transistor is 3904.

Model House Materials:

  1. Cardboard or Foam Board: For building the house structure.
  2. Hot Glue Gun and Glue Sticks: To assemble the model house securely.
  3. Utility Knife or Scissors: For cutting the cardboard or foam board.
  4. Paint or Decorative Paper: For aesthetics and realistic appearance.

Tools:

  1. Ruler: For accurate measurements.
  2. Tape: To secure electronics inside the house.
  3. Wire Strippers: To cut and strip wires to wire the components to the breadboard.

Build the Model House

Screenshot 2025-01-21 at 10.11.10 PM.png
Screenshot 2025-01-21 at 10.11.23 PM.png
Screenshot 2025-01-21 at 10.04.45 PM.png

Steps:

  1. Design the Base:
  2. Cut a square piece of cardboard to serve as the foundation for the house.
  3. It can be any size but ensure there is enough space for all of the components to fit inside.
  4. This base will support the walls and hold the electronics.
  5. Construct the Walls:
  6. Cut 4 rectangular pieces for the walls.
  7. Assemble the House:
  8. Glue the walls to the base and to each other using a hot glue gun. Ensure the walls are perpendicular to the base.
  9. Leave the roof open or make one side of the structure removable for easy access to the electronics.
  10. Decorate:
  11. Paint the house or use decorative paper to create a realistic appearance.
  12. Add any labels or decorations to make it your own!

Set Up the Electronics

Screenshot 2025-01-21 at 10.14.05 PM.png
Screenshot 2025-01-21 at 10.14.20 PM.png

Component Placement:

  1. PIR Sensor:
  2. Attach the sensor on one of the walls ensuring it faces outward for maximum motion detection.
  3. Use double-sided tape or glue to secure it.
  4. Green LED:
  5. Cut a slit to insert the LED, and secure it in place.
  6. Red LED:
  7. Place near the top or above the PIR sensor to represent "Alarm Triggered."
  8. Secure it using the same method as the green LED.
  9. Buzzer:
  10. Mount inside the house where sound can escape.
  11. Arduino and Breadboard:
  12. Place these inside the house, accessible via the open roof or removable panel.
  13. Secure them with double-sided tape.

Wiring the Components

Screenshot 2025-01-21 at 10.19.16 PM.png
Screenshot 2025-01-21 at 10.19.30 PM.png
Screenshot 2025-01-21 at 10.20.24 PM.png

Connections:

  1. PIR Sensor:
  2. VCC pin to Arduino 5V.
  3. GND pin to Arduino GND.
  4. OUT pin to Arduino Pin 2.
  5. Green LED:
  6. Anode (+) to Arduino Pin 5
  7. Cathode (-) to Arduino GND via a 330-ohm resistor.
  8. Red LED:
  9. Anode (+) to Arduino Pin 4.
  10. Cathode (-) to Arduino GND via a 330-ohm resistor.
  11. Piezo Buzzer:
  12. Positive terminal to collector of NPN Transistor.
  13. Negative terminal to Arduino PWR.
  14. NPN Transistor:
  15. Collector connected to the positive terminal of the piezo buzzer.
  16. Base connected to Arduino Pin 3.
  17. Emitter connected to GND via a 10k resistor.

Tips for Neat Wiring:

  1. Use jumper wires of appropriate lengths to avoid tangles.
  2. Test connections before finalizing to ensure proper functionality.

Write and Upload the Code

Screenshot 2025-01-21 at 10.22.55 PM.png

const int pirPin = 2; // PIR motion sensor

const int buzzerPin = 3; // Buzzer

const int greenPin= 5; // Green LED

const int redPin = 4; // Red LED

Why this is done:

  1. We define constants to represent the pins to which each component is connected on the Arduino board. This allows for easier maintenance of the code, as pin assignments are centralized at the beginning.
  2. pirPin is for the motion sensor, connected to digital pin 2.
  3. buzzerPin is connected to pin 3, which will produce the alarm sound.
  4. greenPin is connected to pin 5 to indicate the system is in safe mode.
  5. redPin is connected to pin 6 to indicate an alarm when motion is detected.


void setup() {

pinMode(pirPin, INPUT);

pinMode(buzzerPin, OUTPUT);

pinMode(greenPin, OUTPUT);

pinMode(redPin, OUTPUT);

Serial.begin(9600); // Initialize Serial Monitor

Why this is done:

  1. The setup() function is called once when the Arduino is powered on or reset. It configures the input and output pins.
  2. pinMode(pirPin, INPUT); sets the PIR sensor pin to input, as the sensor will send signals to the Arduino when it detects motion.
  3. pinMode(buzzerPin OUTPUT); sets the buzzer pin as output, since we want to control the buzzer.
  4. The green and red LEDs are set as outputs because we will use them to indicate system status.
  5. Serial.begin(9600); initializes the serial communication so we can send status messages to the Serial Monitor.


digitalWrite(greenPin, HIGH);

digitalWrite(redPin, LOW);

digitalWrite(buzzerPin, LOW);

Serial.println("System Armed. Green LED is on.");

}

Why this is done:

  1. This block sets the initial state when the system starts:
  2. Green LED is turned on (HIGH), indicating that the system is armed and in safe mode.
  3. Red LED is turned off (LOW), as no alarm has been triggered yet.
  4. Buzzer is turned off (LOW) to avoid any noise.
  5. A message is sent to the Serial Monitor to confirm that the system is in the "armed" state.


void loop() {

if (digitalRead(pirPin) == HIGH) {

Why this is done:

  1. loop() is where the continuous checks and operations happen. The Arduino will repeatedly check for any changes in the PIR sensor and update the system's status accordingly.
  2. int motion = digitalRead(PIR_PIN); reads the state of the PIR sensor (whether it detects motion or not).
  3. HIGH indicates motion is detected.
  4. LOW means no motion.


// Motion detected

digitalWrite(greenPin, LOW); // Turn off green LED

digitalWrite(redPin, HIGH); // Turn on red LED

digitalWrite(buzzerPin, HIGH); // Activate buzzer

Serial.println("Motion Detected! Red LED on. Alarm Triggered.");

delay(2000); // Alarm duration

} else {

// No motion

digitalWrite(greenPin, HIGH); // Turn on green LED

digitalWrite(redPin, LOW); // Turn off red LED

digitalWrite(buzzerPin, LOW); // Turn off buzzer

Serial.println("No Motion. System Armed. Green LED on.");

delay(500); // Stabilize sensor

}

}

Why this is done:

  1. The if-else block checks if motion is detected:
  2. If motion is detected (motion == HIGH):
  3. The green LED is turned off, signaling that the system is no longer in safe mode.
  4. The red LED is turned on to indicate an alarm has been triggered.
  5. The buzzer is activated to produce an alarm sound.
  6. A message is sent to the Serial Monitor to log the event.
  7. delay(2000) causes a 2-second pause, allowing the red LED and buzzer to stay on for 2 seconds before resetting.
  8. If no motion is detected:
  9. The green LED remains on, showing the system is in a safe, armed state.
  10. The red LED and buzzer are turned off to ensure the system is quiet and in standby mode.
  11. A message is sent to the Serial Monitor to confirm the system is armed.
  12. delay(500) stabilizes the sensor, preventing any potential flickering from sensor noise.

Test and Troubleshoot

Screenshot 2025-01-22 at 1.13.05 PM.png
Screenshot 2025-01-22 at 9.39.52 AM.png
Screenshot 2025-01-22 at 9.40.03 AM.png
Screenshot 2025-01-22 at 9.39.32 AM.png
  1. Power the Arduino:
  2. Connect the Arduino to a power bank or laptop via USB.
  3. Trigger the System:
  4. Move in front of the PIR sensor to activate the alarm (red LED and buzzer).
  5. Reset:
  6. Move away from the sensor to reset the system (green LED on, alarm off).
  7. Debugging:
  8. Use the Serial Monitor to view the system's status and troubleshoot if necessary.

Final Assembly

  1. Secure Components:
  2. Ensure all components are firmly attached and wires are organized.
  3. Close the Roof:
  4. Attach the roof or close the removable panel after testing.
  5. Presentation:
  6. Showcase your functional security system in the model house!

Downloads