Intrusion deterrent system with keypad disarm. (Arduino)

What will I learn

• You will learn function and how to implement a keypad membrane.

• You will learn function and how to use a motion sensor.

• You will learn how these parts fit together and form an anti intrusion system.

• You will get insight to the program code.

Requirement

• Arduino uno
U5dtoyGtwJRok5T3DS5vEUjtYy6EN5r_1680x8400.png
Image source

• 4×3 Keypad membrane
images (22).jpeg
Image source

• PIR motion sensor
images (16).jpeg
Image source

• LCD 16×02
lcd162b-300x250.jpg
Image source

• Buzzer
images (18).jpeg
Image source

• Connecting Cables
U5dt5djFAEAuDqbjgozt7zKyjgmgY4X_1680x8400.png
Image source

• USB cable Type A to B
U5drjk9gpB4HQ651LwmKgy1Jfc6uV6p_1680x8400.png
Image source

• Computer
U5dsj6pjLNN3JCs2zrY4VyDvsoekNVa_1680x8400 (1).png
Image source

Software

Arduino software/IDE

Knowledge

• Knowledge of electronic circuit

• Knowledge of programming

Difficulty

Intermediate.

Project description

The project is an embedded system comprising a microcontroller, LCD and motion sensor which can control the action of the buzzer depending on the presence of human detected within 6metres of its range. By using this project we can reduce the human effort in monitoring a valuable item or a keeping a home secured from intrusions.

Components description

• PIR motion sensor: senses/detects human motion within its range approximately within 6metres or 20feet.

• Keypad: allows user to interact with a microcontroller, for inputing of data for locking and unlocking the system

Tutorial content

Step 1: Gather all components together

IMG_20180319_100658_242.JPG

Step 2a: connect keypad to arduino

IMG_20180319_100450_309.JPG

Step 2b: connect pir motion sensor to arduino

Pin 1: 5V VCC. in Red

Pin 2: Output. in yellow

Pin 3: GND. in Black
IMG_20180319_100555_218.JPG

Step 2c: connect buzzer to arduino

Pin 1: 5V VCC. in Red

Pin 2: GND. in black

IMG_20180319_100514_764.JPG

Step 2d: connect LCD to arduino

IMG_20180319_100535_836.JPG

Full setup of connection is as shown below.

IMG_20180319_103111_634.JPG

Step 3: Programming

• Keypad library setup.
i. Download the keypad library here

ii. Unzip/extract the keypad library

iii. Install the keypad library in your arduino IDE by moving the unzipped folder to: Arduino\Libraries

iv. Restart your arduino IDE

• Connect the set up to the compter

U5du3hR1jwTk8kf7YEopdf5gMhhYWfy_1680x8400 (1).png

• Once done, open the arduino IDE, go to Tools>Board>then select Arduino/Genuino Uno
U5dtM5UwYx24di6YiusRo262xv5EVue_1680x8400.png

• Copy my code below and paste into your IDE.

 *
 * ONCE PIR DETECTES, ITS SOUND AN ALARM
 * ALARM IS DISABLED BY KEYING THE CORRECT PASSCODE.
 */
 
#include 
#include 
#include
LiquidCrystal lcd(12,11,10,9,8,7); //RS,E,DB4,DB5,DB6,DB7

Password password = Password("1234");
const byte ROWS = 4; //for rows
const byte COLS = 3;  //for columns


//Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {A0,A1,A2,A3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {A4,A5,2}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys),rowPins, colPins, ROWS, COLS);

const int BUZZER = 6;
const int PIR = 4;
const int button = 5;
const int LED = 3;
int val = 0;
String code="";

void setup() {
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.setCursor (2,0);
  lcd.print("ALARM SYSTEM");
  delay(2000);
  lcd.clear();
  pinMode(BUZZER, OUTPUT);
  pinMode(button, INPUT);  //the pin 4 will serve as switch, when it is ON the BURGLAR is ON.....it is connected as an ACTIVE HIGH
  pinMode(LED,OUTPUT);  //this serves as an indicator to show that the ALARM is active to sense motion
  pinMode(PIR, INPUT);
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
  // put your setup code here, to run once:
  digitalWrite(PIR, LOW);
  digitalWrite(LED,LOW);
  }

void loop() {
  while (digitalRead(button) == LOW){     //the while loop here is set in such a way that the below codes
  lcd.setCursor(1,0);                 //including the if statement depends on pin 4 being ON
  digitalWrite(LED, HIGH);
   
      val = digitalRead(PIR);
      if (val == HIGH){
         digitalWrite(BUZZER, HIGH);
          lcd.setCursor(0,0);
          lcd.print("  ALARM ON !!!  ");
          lcd.setCursor(0,1);
          lcd.print("PASSCODE:");
          delay(100);
        }
      
        keypad.getKey();
    }                                  //the while loop covers up to this point
  digitalWrite(LED, LOW);                 //if the digital pin 4 is not HIGH then pin 6 
  digitalWrite(BUZZER, LOW);
  lcd.setCursor(0,0);
  lcd.print("ALARM DIS-ARMED ");
  lcd.setCursor(0,1);
  lcd.print("                ");
  delay(200);
  //lcd.setCursor(1,1);
  //lcd.clear();
  if ( digitalRead(button) == LOW){
    lcd.clear();
  }
}

//take care of some special events
void keypadEvent(KeypadEvent eKey){
  switch (keypad.getState()){
    case PRESSED:
  switch (eKey){
    case '#': 
    checkPassword();
    break;
    
    case '*': 
    password.reset();
    code =""; 
    break;
    
    default: password.append(eKey);
    code += '*';
    lcd.setCursor(10,1);
    lcd.print(code);
    
    }
  }
}
void checkPassword(){
  if (password.evaluate()){
    lcd.clear();
    lcd.setCursor(1,0);
    lcd.print("PASSCODE OKAY ");
     digitalWrite(BUZZER, LOW);
     delay(5000);
    password.reset();
    code ="";
    //Add code to run if it works
  }else{
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("PASSCODE ERROR ");
     code ="";
    delay(2000);
    lcd.clear();
    password.reset();
    //add code to run if it did not work
  }
}


The program code does the following:

  1. It initializes the Microcontrollers
  2. It initializes the Keypad
  3. It asks you to Input New Password
  4. It asks you to confirm Password
  5. It initializes the Sensor PIR
  6. It initializes the LCD
  7. It Setups a Continuous loop
  8. It reads data from Sensor

• Condition 1

-. Is there any Motion?

A. If YES: It initiates a buzzer sound

B. If No: It continues the Loop

• Condition 2

-. Is Correct password inserted?

A. If YES: It deactivates buzzer

B. If No: It continues the Loop

Loop continues to 1.

• Type the code above into the sketch, save and compile the code.
Screenshot_2018-03-19-12-13-16.png

• This will check for errors in the code.

• If there are no errors found, upload the sketch unto the arduino board.

Step 4: Testing

• Having done all the above steps rightly. Power on the project. It will displays as shown below and ask for new user passward input.
IMG_20180319_105423_778.JPG



Posted on Utopian.io - Rewarding Open Source Contributors

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now