Password Based Digital Door Lock Security System Using Arduino and Keypad

Share This

Hello friends! Welcome back to ElectroDuino. This blog is based on Password Based Digital Door Lock Security System Using Arduino,  4×4 Keypad module, and Servo motor. Here we will discuss Introduction to Password-Based Digital Door Lock Security System, Project Concept, Block Diagram, components required, circuit diagram, working principle, and Arduino code.

Introduction

Always we want a personal room, where nobody can’t enter this room without our permission. Nowadays security is the most important thing. So, we need to secure a room at our home and office for protecting our important accessories and documents. For that reason, in this project, we design the Password-Based Digital Door Lock Security System Using Arduino,  4×4 Keypad module, and a Servo motor. This Device is a digital Password or Pin code based Door Lock Security System. Which does not allow the user to open the Dore without entering the correct Password or Pincode.

Project Concept

In this project, we will enter a password using the keypad to open the door lock using servo motor. Password-Based Digital Door Lock Security System is consists of Arduino, 4 x 4 keypad module, servo motor, LCD display, and two switches. The Arduino is the brain of the project, that controls the whole system. Here we will use Arduino nano but you can choose any other version of the Arduino board which is based on the ATmega328. The 4X4 Keypad module is used to type the password or pin. Open button and close buttons are used to open and close the door lock from inside the room. The servo motor is used to push (lock) or pull (unlock) the latch on the door. The LCD display is used to show the message to the user. The buzzer is used for indications.

Block diagram

Component Required

Components NameQuantity
Arduino Nano1
4 x 4 matrix keypad1
SG90 Servo motor1
16 x 2 LCD Display1
Buzzer1
Push Button Switch2
1k Resistor2
9 Volt Power Supply1
Connecting wiresAs per required in the circuit diagram

 We need to download the KeyPad library: CLICK

Circuit Diagram of Digital Door Lock Security System Using Arduino,  4×4 Keypad module, and Servo motor

Password Based Digital Door Lock Security System Using Arduino & Keypad Circuit Diagram
Password Based Digital Door Lock Security System Using Arduino & Keypad Circuit Diagram

Circuit Wiring

Components PinArduino pin

SG90 Servo motor  Vcc,

LCD  Display (Vdd, LED +),

Push Button 1 terminal-1 

Push Button 2 terminal-1

Arduino 5V Pin

SG90 Servo motor  GND,

LCD  Display (Vss, Rw, LED -) pin,

Buzzer terminal-2

GND (ground) Pin
Push Button 1 terminal-3 and Push Button 2 terminal-3Both are connected to GND (ground) Pin through 1k resistor
4 x 4 Keypad module R1, R2, R3, R4, C1, C2, C3, and C4 PinsRespectively  Digital Pin “D2”, “D3”, “D4”, “D5”, “D6”, “D7”, “D8” and “D9”.
LCD  Display RS, E, D4, D5, D6, D7Respectively  Analog Pin “A0”, “A1”, “A2”, “A3”, “A4”, “A5”
LCD  Display V0 pin  10k Potentiometer Signal pin, Potentiometer one pin is connected to 5V and another pin is connected to GND(ground)
SG90 Servo motor  PWM pin
Digital Pin “D10”
Push Button 1 and Push Button 2 data pins are the junction point of the both button’s terminal-2 and resistorRespectively  Digital Pin “D12”, and “D11”
Buzzer terminal-1Digital Pin “D13”
9v Power Supply positive (+) terminalConnected to VIN Pin through a Slide Switch for external DC Power supply to operating Arduino.
9v Power Supply negative (+) terminalGND (ground) Pin

Working of Password-Based Door Lock Security System

Password-Based Door Lock Security System’s working principle is very simple. First of all, we must need to have defined a Password or Pin code in the Arduino code. Here the predefined Pin code is ” 2306 “. Also, define two keypad letters button one is “Enter button” to submit the password or pin code and another one is the “Close button” to lock the Door. Here the “Enter button” is Keypad letters “D” and the “Close button” is Keypad letters “C”.

When we enter a password and submit it using the “Enter button” in the Keypad module. Then Arduino read this password or pin, and match it with the predefined password stored in the Arduino. If the password or pin is matched then the LCD display will show “WELCOME ELECTRODUINO” massage and buzzer make a sound for 1 second. Then Arduino sends a command to the Servo motor to move the shaft at the 180-degree position, now the door is unlocked. When we will press the button “C” then Arduino sends a command to Servo motor to move the shaft at the 90-degree position, now the door is again locked. The LCD display will show “DOOR CLOSE” massage and buzzer make a sound for 1 second.

This circuit is included two push button switches. These are used to open and close the door lock from inside the room. The Pushbutton 1 is used to open (unlock) the door lock and The Pushbutton 2 is used to close (lock) the door lock. Pushbutton 1 and Pushbutton 2 both switch’s terminal 3 are connected to ground through the 1k pulldown resistor for getting stable input. When we will press the “Pushbutton1 ” then Arduino reads the data and sends a command to Servo motor to move the shaft at the 180-degree position, now the door is unlocked. The buzzer makes the sound for 1 second. When we will press the “Pushbutton2 ” then Arduino reads the data and sends a command to Servo motor to move the shaft at the 90-degree position, now the door is again locked. The buzzer makes the sound for 1 second.

Arduino Code for Password-Based Door Lock Security System

//LCD config
#include <LiquidCrystal.h>
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);

#include <Servo.h>
#include <Keypad.h>

//Variables
int Lock = 90;   //min servo angle  (set yours)
int Unlock = 180; //Max servo angle   (set yours)
int character = 0;
int activated =0;
char Str[16] = {' ', ' ', ' ', ' ', ' ', ' ', '-', '*', '*', '*', ' ', ' ', ' ', ' ', ' ', ' '};  

//Pins
Servo myservo;
int buzzer = 13;     //pin for the buzzer beep
int Emergency_open = 12; //pin to inside emergency_open
int Close_Button = 11; //pin to inside Close_Button

//Keypad config
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'1','4','7','*'},
  {'2','5','8','0'},
  {'3','6','9','#'},
  {'A','B','C','D'}
};
byte rowPins[ROWS] = {2, 3, 4, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6, 7, 8, 6}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

void setup(){
  myservo.attach(10); //attach the servo to pin D10
  pinMode(buzzer,OUTPUT); 
  pinMode(Emergency_open,INPUT);
  pinMode(Close_Button,INPUT); 
  
  //Init the screen and print the first text
  lcd.begin(16, 2);
  lcd.clear();
  lcd.print("    PASSWORD");
  lcd.setCursor(0,1);
  lcd.print("      -***     ");
  //put the servo in the close position first
  myservo.write(Lock);  
  
}
  
void loop(){
///////////////EMERGENCY OPEN/CLOSE/////////
  if (digitalRead(Emergency_open))
  {
     myservo.write(Unlock);
      lcd.clear();
      lcd.setCursor(2,0);
      lcd.print("INSIDE  OPEN");
      activated = 2;
      analogWrite(buzzer,240);
      delay(250);
      analogWrite(buzzer,200);
      delay(250);
      analogWrite(buzzer,180);
      delay(250);
      analogWrite(buzzer,250);
      delay(250);
      analogWrite(buzzer,LOW);
     
      
      lcd.clear();    
      lcd.setCursor(0,0);
      lcd.print("    WELLCOME    ");
      
      lcd.setCursor(0,1);
      lcd.print("  ELECTRODUINO  ");
      

      lcd.clear();    
      lcd.setCursor(3,0);
      lcd.print("DOOR  OPEN");
      lcd.setCursor(2,1);
      lcd.print("ELECTRODUINO");
      delay(500);
    
  }

  if (digitalRead(Close_Button))
  {
    myservo.write(Lock);
    activated = 0;
    character=0;
    Str[6]= '-';
    Str[7]= '*'; 
    Str[8]= '*'; 
    Str[9]= '*';
    Str[10]= ' ';   
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("    PASSWORD");    
    lcd.setCursor(0,1);
    lcd.print(Str);
  }
    
///////////////KEYPAD OPEN/CLOSE////////////  
  char customKey = customKeypad.getKey(); //this function reads the presed key
  
  if (customKey){

    if (character ==0)
    {  
    Serial.println(customKey);
    Str[6]= customKey;   
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("    PASSWORD");    
    lcd.setCursor(0,1);
    lcd.print(Str);
   
    }

    if (character ==1)
    {  
    Serial.println(customKey);
    Str[7]= customKey;   
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("    PASSWORD");    
    lcd.setCursor(0,1);
    lcd.print(Str);
   
    }

    if (character ==2)
    {  
    Serial.println(customKey);
    Str[8]= customKey;   
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("    PASSWORD");    
    lcd.setCursor(0,1);
    lcd.print(Str);
   
    }

    if (character ==3)
    {  
    Serial.println(customKey);
    Str[9]= customKey;   
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("    PASSWORD");    
    lcd.setCursor(0,1);
    lcd.print(Str);
   
    }

    if (character ==4)
    {  
    Serial.println(customKey);
    Str[10]= customKey;
    activated=1;
   
    }
    character=character+1;
  }

  if (activated == 1)
    {
/*Change your password below!!! 
Change each of Str[6], Str[7], Str[8], Str[9]*/

    if(Str[10]='D' && character==5 && Str[6]=='2' && Str[7]=='3' && Str[8]=='0' && Str[9]=='6' )
    {
      myservo.write(Unlock);
      lcd.clear();
      lcd.setCursor(4,0);
      lcd.print("ACCEPTED");
      activated = 2;
      analogWrite(buzzer,240);
      delay(250);
      analogWrite(buzzer,200);
      delay(250);
      analogWrite(buzzer,180);
      delay(250);
      analogWrite(buzzer,250);
      delay(250);
      analogWrite(buzzer,LOW);
      delay(1000);
      
      lcd.clear();    
      lcd.setCursor(4,0);
      lcd.print("WELLCOME");
      delay(500);
      lcd.setCursor(2,1);
      lcd.print("ELECTRODUINO");
      delay(1000);

      lcd.clear();    
      lcd.setCursor(3,0);
      lcd.print("DOOR  OPEN");
      lcd.setCursor(2,1);
      lcd.print("ELECTRODUINO");
      
    }
    else
    {
      lcd.clear();    
      lcd.setCursor(1,0);
      lcd.print("PASSWORD ERROR");
      lcd.setCursor(3,1);
      lcd.print("TRY  AGAIN");
      analogWrite(buzzer,150);
      delay(3000);
      analogWrite(buzzer,LOW);
      character=0;
      Str[6]= '-';
      Str[7]= '*'; 
      Str[8]= '*'; 
      Str[9]= '*';
      Str[10]= ' ';
      activated = 0;
      lcd.clear();    
      lcd.setCursor(4,0);
      lcd.print("PASSWORD");
      lcd.setCursor(0,1);
      lcd.print(Str);   
    }
  }
  if (activated == 2)
    {
    if(customKey == 'C' )
    {
      myservo.write(Lock);
      activated = 0;
      character=0;
      Str[6]= '-';
      Str[7]= '*'; 
      Str[8]= '*'; 
      Str[9]= '*';
      Str[10]= ' ';   
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("    PASSWORD");    
      lcd.setCursor(0,1);
      lcd.print(Str);
     
    }
  }  
}

 

Share This

Leave a Reply

Your email address will not be published. Required fields are marked *