Burglar Alarm System

Introduction

Ever dreamt of building a home security system? Bother less as this tutorial takes you through building your very own Burglar Alarm System in just two steps. It’s pretty easy and am sure you’d enjoy it.

 

List of Components

Buzzer

PIR sensor

InventOne dev. Board

Jumper wires

Breadboard

 You can order for most of your components from aliexpress, hub360, or ebay. Follow the link below to order for your inventone board http://inventone.ng/#/buy

 

Circuit diagram for burglar alarm system
Circuit diagram for the Burglar Alarm System

Tutorial

Step 1

The image above shows the complete circuit diagram. Connect up the circuit as shown in the image, ensure you take note of the pin numbers and wire up the modules to the exact point on the board else you’d have a problem with the code when you upload to the board.

Step 2

Copy the code from the code section and paste in your Arduino IDE, upload the code to the inventone board, if you don’t know how to upload codes to the board please check out our tutorial on how to upload codes to a development board. When you’ve successfully uploaded the code, open your serial monitor you should get these messages popping up:

“Motion detected”            when motion is detected


“No motion detected”      when no motion is detected

 

Code

Firstly, we define the pins used for the PIR sensor and the buzzer(Alarm). In the setup section, we established the nature of the pins; the PIR pin is an input as it reads the sensor output which goes high when motion is detected and is a low when no motion is detected. The buzzer(Alarm) is an output, we would be using it to write a voltage level to the buzzer when motion is detected. 

In the void loop, we used an if statement whose conditions are determined by the voltage level present on the PIR sensor's data pin. Once the if statement is true, we write a high to the buzzer and print "motion detected" to the serial monitor. If motion isn't detected, we ensure the buzzer doesn't come on mistakenly by writing a LOW to it and we print "No motion detected" to the serial monitor. We’ve added a 3 seconds delay to allow the PIR sensor settle before reading its data pin again.

 

Notes

The PIR sensor needs to be facing no obstacle when it comes on so ensure it has little or no obstructions. For more info on how the PIR sensor works you can go through this tutorial from adafruit PIR sensor.

 

//Define the pins for PIR sensor and alarm
int Alarm = 16;
int PIR = 13;
void setup() {
  pinMode(Alarm, OUTPUT);
  pinMode(PIR, INPUT);
  //Begin serial monitor communication
  Serial.begin(9600);
}

void loop() {
  //Check if PIR has sensed motion or not
  if(digitalRead(PIR) == HIGH){
    Serial.println("Motion Detected");
    //Turn ON the alarm
    digitalWrite(Alarm, HIGH);
  }
  else{
    Serial.println("No motion detected");
    //Ensure the alarm doesn't come on
    digitalWrite(Alarm,LOW);
  }
  delay(3000);
}