How to Make Smart Password Door Lock

Today we are going to build an eight digit password based security door lock. the system is based on Arduino. A 4×4 keypad is used to enter the passcode, eight LEDs are user to display the number of digits entered, a servo motor is used to lock and unlock the door latch. the system has a default passcode which is 1 2 3 4 5 6 7 8. We can change the passcode by first entering eight zeros and then we need to enter the current passcode and then we can enter the new passcode. the LEDs flashes differently for different options, if we enter enter correct passcode the LEDs flashes and servo motor starts. there are two Arduino codes one is to save the default passcode in the EPROM of the Arduino and the second one is the main code fist we need to upload default passcode sketch of Arduino the the main sketch. Now let’s build this interesting project.

Step 1 :

First we need to connect Arduino Nano you can use any Arduino,

 Then connect an LED and connect its anode to pin d2 of Arduino and its cathode to ground.

Then connect another LED and connect its anode to pin d3 of Arduino and its cathode to ground.

Then connect another LED and connect its anode to pin D4 of Arduino and its cathode to ground.

Then connect another LED and connect its anode to pin D5 of Arduino and its cathode to ground.

Then connect another LED and connect its anode to pin D6 of Arduino and its cathode to ground.

Then connect another LED and connect its anode to pin D7 of Arduino and its cathode to ground.

Then connect another LED and connect its anode to pin D8 of Arduino and its cathode to ground.

Then connect another LED and connect its anode to pin D9 of Arduino and its cathode to ground.

Then connect an 8×8 keypad and connect its pin number 1 to pin A5 of Arduino,

it’s pin number 2 to pin A4 of Arduino, it’s pin number 3 to pin A3 of Arduino,

it’s pin number 4 to pin A2 of Arduino, it’s pin number 5 to pin A1 of Arduino,

it’s pin number 6 to pin A0 of Arduino, it’s pin number 7 to pin D12 of Arduino,

it’s pin number 8 to pin d11 of Arduino.

Then connect servo motor and connect its positive pin to 5V of Arduino and its ground to ground of

Arduino and its signal pin to pin D13 of Arduino.

Step 2 :

 Now upload the code to Arduino, first we need to save the default passcode in the EPROM of Arduino for that upload this code to Arduino.

Default passcode sketch
#include <EEPROM.h>

void setup(){
  } 

void loop(){
  
    EEPROM.write(0, '1');
    
    EEPROM.write(1, '2');
    
    EEPROM.write(2, '3');
    
    EEPROM.write(3, '4');
    
    EEPROM.write(4, '5');
    
    EEPROM.write(5, '6');
    
    EEPROM.write(6, '7');
    
    EEPROM.write(7, '8');
}

Now upload the main code to the Arduino

Main sketch

#include <Keypad.h>

#include <EEPROM.h>

#include <Servo.h>

Servo myservo; 

char d,d1,d2,d3,d4,d5,d6,d7,d10,d11,d12,d13,d14,d15,d16,d17;

int c,cpa;

bool cp,np;

const byte ROWS = 4; //four rows

const byte COLS = 4; //three columns

char keys[ROWS][COLS] = {
  
  {'1','2','3','A'},
  
  {'4','5','6','B'},
  
  {'7','8','9','C'},
  
  {'*','0','#','D'}
  
};

byte rowPins[ROWS] = {11,12,14,15}; //connect to the row pinouts of the keypad

byte colPins[COLS] = {16,17,18,19}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){

  pinMode(2,OUTPUT);
  
  pinMode(3,OUTPUT);
  
  pinMode(4,OUTPUT);
  
  pinMode(5,OUTPUT);
  
  pinMode(6,OUTPUT);
  
  pinMode(7,OUTPUT);
  
  pinMode(8,OUTPUT);
  
  pinMode(9,OUTPUT);
  
  myservo.attach(13);
  
  myservo.write(0); 
  
  Serial.begin(9600);
  
  Serial.println( "ENTER PASSWORD   ");
 
  d= EEPROM.read(0);
  
  d1= EEPROM.read(1);
  
  d2= EEPROM.read(2);
  
  d3= EEPROM.read(3);
  
  d4= EEPROM.read(4);
  
  d5= EEPROM.read(5);

  d6= EEPROM.read(6);

  d7= EEPROM.read(7);

}
  
void loop(){
  char key = keypad.getKey();
  
  if (key){
    
    c++;
    
    digitalWrite(c+1,HIGH);
    
    Serial.println(key);   
     
    //PRINT CHAR
     if(c==1)d10=key;
     
     if(c==2)d11=key;
     
     if(c==3)d12=key;
     
     if(c==4)d13=key;
     
     if(c==5)d14=key;
     
     if(c==6)d15=key;
     
     if(c==7)d16=key;
     
     if(c==8)d17=key; 
      
  }

  if(c==8&np==0){
    
    c=0;

    
  if(d==d10&d1==d11&d2==d12&d3==d13&d4==d14&d5==d15&d6==d16&d7==d17){
    
    if(cp==0){
      
        Serial.println( "PASSWORD ACCEPTED");
        
        
        delay(200);
        
        alloff();
        
        delay(200);
        
        allon();
        
        delay(200);
        
        alloff();
        
        delay(200);
        
        for (int i = 0; i <= 180; i += 1) { 

          myservo.write(i);   
                     
          delay(5);                       
  }
  
  delay(2000);
  
  for (int i = 180; i>= 0; i -= 1) { 
    
    myservo.write(i);  
                
    delay(5);                       
  }
  
    }
    
    if(cp==1){
   
      Serial.println( "NEW PASSWORD");
      
      alloff();
      
      delay(100);
      
      allon();
      
      delay(1000);
      
      alloff();
      
      delay(1000);
      
      np=1;
    
    }
    
    d10=d11=d12=d13=0,d14=d15=d16=d17=0;
   
     
    }else   if(d10=='0'&d11=='0'&d12=='0'&d13=='0',d14=='0'&d15=='0'&d16=='0'&d17=='0'){
        
        delay(50);
        
        alloff();
        
        delay(50);
        
        allon();
        
        delay(50);
        
        alloff();
        
        delay(50);
        
        allon();
        
        delay(50);
        
        alloff();
        
        delay(50);
        
        allon();
        
        delay(50);
        
        alloff();
        
        delay(50);
        
        allon();
        
        delay(50);
        
        alloff();
        
        delay(50);
        
        allon();
        
        delay(50);
        
        alloff();
        
        delay(50);
        
        Serial.println( "OLD PASSWORD");
     
      cp=1;
      
      }else{
      
    Serial.println( "WRONG PASSWORD");
    
      if(cp==1){
        
        cpa++;
        
        }
        
        
        delay(100);
        
        alloff();
        
        delay(100);
        
        allon();
        
        delay(100);
        
        alloff();
        
        delay(100);
        
        allon();
        
        delay(100);
        
        alloff();
        
        delay(100);
        
        allon();
        
        delay(100);
        
        alloff();
        
        delay(100);
        
        d10=d11=d12=d13=0,d14=d15=d16=d17=0;
     
      }
    
    }
  if(cpa==3){
      
      np=0;
      
      cp=0;
      
      cpa=0;
      
      c=0;
      
      d10=d11=d12=d13=d14=d15=d16=d17=0;
      
      alloff(); 
      
      Serial.println( "ENTER PASSWORD   ");
  }
    
  if(c==8&np==1){
      
      d=d10;
      
      d1=d11;
      
      d2=d12;
      
      
      d3=d13;
      
      d4=d14;
      
      d5=d15;
      
      d6=d16;
      
      d7=d17;
      
      EEPROM.write(0, d);
      
      EEPROM.write(1, d1);
      
      EEPROM.write(2, d2);
      
      EEPROM.write(3, d3);
    
      EEPROM.write(4, d4);
      
      EEPROM.write(5, d5);
      
      EEPROM.write(6, d6);
      
      EEPROM.write(7, d7);
      
      np=0;
      
      cp=0;
      
      c=0;
      
      d10=d11=d12=d13=d14=d15=d16=d17=0;
    
      alloff();
      
      Serial.println( "ENTER PASSWORD   ");
    
    }
    
}

void allon(){
  
  
  digitalWrite(2,HIGH);
  
  digitalWrite(3,HIGH);
  
  digitalWrite(4,HIGH);
  
  digitalWrite(5,HIGH);
  
  digitalWrite(6,HIGH);
  
  digitalWrite(7,HIGH);
  
  digitalWrite(8,HIGH);
  
  digitalWrite(9,HIGH); 
  
  }
void alloff(){
  
  digitalWrite(2,LOW);
  
  digitalWrite(3,LOW);
  
  digitalWrite(4,LOW);
  
  digitalWrite(5,LOW);
  
  digitalWrite(6,LOW);
  
  digitalWrite(7,LOW);
  
  digitalWrite(8,LOW);
  
  digitalWrite(9,LOW);

  }
Components :
Gerber Files
Icon

8 digit code - CADCAM 72.50 KB 44 downloads

...
Project Files
Icon

8 digit passcode 417.79 KB 56 downloads

...

1 thought on “How to Make Smart Password Door Lock”

  1. Yoᥙ actually make it seem so eаsy witһ ʏour presentation but I find
    this matter to be actuɑlly something that I think I wouⅼd never understand.
    It seems toߋ complicatеd and extremely broad for me.
    I am looking forward for your next post, I’ll try
    to get the hang of it!

    Feel frеe to vіsit my homepage; blueberry

    Reply

Leave a Comment