Arduino Home Security System
Arduino Home Security System
Hussam Abedi
University of Kashan , Kāshān · Department of Thermal Sciences and Fluid
Mechanics
This a Home Security System using Arduino Mega 2560, which will
trigger alarm when any door is opened or movement detected in the
room when the system is activated. Its a nice project for anyone in final
year in the university. you can upgrade it even much better. will be here
to help. Have fun!!
the items needed are shown in the pictures, not forgetting the camera,
you can use a dashcam from the ones use in a car. you can also add IP
camera to broadcast live videos online.
all this components can be purchased cheap on eBay
> Arduino Mega 2560 is the main brain for the system
> Arduino Uno is for the lights in the house
> keypad for entering pin to activate and de-activate the system
>breadboard for the components and connection
>Servo for the movement of the camera with respect to the sensor or
motion detected
>PIR motion sensor for the rooms to detect any movement
> 20X4 LCD display screen for display of the results and indicating the
location of the motion detected, alarm status etc
>Magnetic Door rid switch, this is attached to the doors to detect when
door is open or closed
> buzzer for the alarm
> Jumper wires for connection
>DS 1305 for interrupt input
>RGB led
>camera
> 1KOhm resistorsX4
>4.7KOhm potentiometers X2
>Relay to control camera on and off status and the LED if you using
12V LEDs if not you can choose to ignore the relay and power up the
camera with your laptop and any low voltage LED's with 3V-5V can
power up with the Arduino..
this devices will be connected using the circuit diagram shown in next
stage.
First test the LCD screen display with the short code. test the
components functionality with code as you build along to solve error
problems and avoid a system that dosn't work. a complete system with
error can be hard to solve if it was handled step-by-step. most of the
problem that will arise are due to either wrong connection, code error or
defective component used. be sure to watch out for those alone the way
NB: remember to attach 1KOhm resistor to the positive leads of the PIR
sensor to act as pull-up resistor.
the model depends on how you want it to look like, chose a design and
build, that will help to test the device in a real-time situation. i used
plywood at first, and later tried it with cardboard paper. Any can be
great for the job.
it doesn't matter the compartments you choose to build, if you build 3
bedrooms, you will need 3 PIR sensors and an additional code which is
similar to the others but different pin-outs and it will still work great.
you can also have a garage or make it more complex.
the roof i used a cardboard and cut out a print of patterns from A4 paper.
The Magnetic door rid's go behind the front door and backdoor, while
the PIR sensors go in the rooms, label the rooms as bedroom 1 and
bedroom 2 or 3 if you chose to add more.
Now perform a test on the servo's operation, be sure its moving the right
direction and angle required. you will have to update the code if your
model house isn't the exact shape and size as mine. That's just to change
the position in the code.
Put all stuffs together and give it one more trial. each door opening
should trigger the alarm and the screen displays which door is opened.
any motion in the rooms should also trigger the alarm and displayed
onscreen the point of movement.
attached is the code!!
attac
HAVE FUN!!!!
/////////////////////////////////////////////////////////////////
#include <LiquidCrystal.h>
#include <Wire.h>
#include <Password.h>
//http://www.arduino.cc/playground/uploads/Code/Password.zip
#include <Servo.h>
#include "RTClib.h"
//Servo
RTC_DS1307 RTC;
//Password
'1','2','3','A' }
'4','5','6','B' }
'7','8','9','C' }
'*','0','#','D' }
};
byte rowPins[ROWS] = {
46, 47, 48, 49}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
50, 51, 52, 53}; //connect to the column pinouts of the keypad
LiquidCrystal lcd(7,8, 9, 10, 11, 12); // Assignign arduino pins to LCD display module
//Stroke LED Lights
//int relay1 = 3; //
int relay4 = 6; //
int alarmStatus = 0;
int zone = 0;
int alarmActive = 0;
void setup(){
Serial.begin(9600);
lcd.begin(20, 4);
//Adding time
Wire.begin();
RTC.begin();
//If we remove the comment from the following line, we will set up the module time
and date with the computer one
RTC.adjust(DateTime(__DATE__, __TIME__));
displayCodeEntryScreen();
pinMode(redPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(speakerPin, OUTPUT);
//pinMode(relay1, OUTPUT);
pinMode(relay4, OUTPUT); //
digitalWrite(redLED, LOW);
digitalWrite(greenLED, HIGH);
digitalWrite(speakerPin, LOW);
//digitalWrite(relay1, LOW); //
digitalWrite(relay4, LOW); //
myservo.write(pos);
void loop(){
//DATE
lcd.setCursor(0,1);
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.day(), DEC);
lcd.print('/');
//We print the year
lcd.print(now.year(), DEC);
lcd.print(' ');
//TIME
lcd.setCursor(13,1);
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.setCursor(16,1);
lcd.print(now.minute(), DEC);
//lcd.print(':');
//lcd.print(now.second(), DEC);
//delay(1000);
keypad.getKey();
//Serial.println(digitalRead(reedPin2));
//Serial.println(digitalRead(pirPin));
//Serial.println(digitalRead(pirPin2));
if (alarmActive == 1){
if (digitalRead(pirPin1) == HIGH)
zone = 0;
alarmTriggered();
if (digitalRead(reedPin1) == LOW)
zone = 1;
alarmTriggered();
if (digitalRead(reedPin2) == LOW)
zone = 2;
alarmTriggered();
if (digitalRead(pirPin2) == HIGH)
zone = 3;
alarmTriggered();
switch (keypad.getState()){
case PRESSED:
if (passwd_pos - 15 >= 5) {
return ;
lcd.setCursor((passwd_pos++),0);
switch (eKey){
checkPassword();
break;
password.reset();
passwd_pos = 15;
break;
default:
password.append(eKey);
lcd.print("*");
void alarmTriggered(){
int expected_pos;
int incr;
digitalWrite(speakerPin, HIGH);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);
digitalWrite(redPin, HIGH);
//
password.reset();
alarmStatus = 1;
// alarmActive = 0;
lcd.clear();
lcd.setCursor(0,2);
lcd.setCursor(0,4);
if (zone == 1)
expected_pos = 65;
delay(1000);
if(zone == 0){
expected_pos = 40;
delay(1000);
expected_pos = 10;
lcd.print("Backdoor Open");
delay(1000);
expected_pos = 145;
lcd.print("Motion in Garage");
delay(1000);
} else {
incr = -1;
/*
for(pos = 0; pos < angle; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
*/
StrokeLight();
}
void StrokeLight(){ //Stroke LED Lights
delay(ledDelay); // wait 50 ms
delay(ledDelay); // wait 50 ms
delay(ledDelay); // wait 50 ms
delay(ledDelay); // wait 50 ms
delay(ledDelay); // wait 50 ms
delay(ledDelay); // wait 50 ms
delay(ledDelay); // wait 50 ms
delay(ledDelay); // wait 50 ms
delay(ledDelay); // wait 50 ms
delay(ledDelay); // wait 50 ms
delay(ledDelay); // wait 50 ms
delay(ledDelay); // wait 50 ms
}
if (password.evaluate())
activate();
deactivate();
else {
invalidCode();
password.reset();
lcd.clear();
lcd.setCursor(1,0);
lcd.setCursor(5,2);
lcd.print("TRY AGAIN!");
digitalWrite(greenLED, LOW);
digitalWrite(redLED, HIGH);
delay(2000);
digitalWrite(redLED, LOW);
delay(1000);
displayCodeEntryScreen();
void activate() // Activate the system if correct PIN entered and display message on
the screen
digitalWrite(redLED, HIGH);
digitalWrite(greenLED, LOW);
digitalWrite(2, HIGH);
lcd.setCursor(0,0);
lcd.print("SYSTEM ACTIVE!");
alarmActive = 1;
password.reset();
delay(2000);
else{
void deactivate()
{
//digitalWrite(camera, LOW);
alarmStatus = 0;
digitalWrite(redLED, LOW);
digitalWrite(greenLED, HIGH);
lcd.clear();
lcd.setCursor(0,0);
digitalWrite(speakerPin, LOW);
alarmActive = 0;
password.reset();
delay(5000);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
displayCodeEntryScreen();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter PIN:");
lcd.setCursor(0,2);
lcd.setCursor(0,3);
lcd.print("Christian Davies");
}