Arduino TutorialsProjects

How to make password based door lock with Arduino

In the last tutorial, we discussed at length how a 4X4 matrix membrane keypad works with Arduino, how to connect it with a liquid crystal display (LCD) using a I2C module, and we printed pressed keys on the Arduino IDE serial monitor as well as on the LCD. In this tutorial which comes with a video, we will discuss how to use the 4X4 matrix membrane keypad to design a password enabled entry.

watch video below:

password based door lock system

Materials for the project:

  • Arduino uno
  • 4X4 Matrix membrane keypad
  • 16X2 Liquid crystal display
  • I2C module
  • L298 H-Bridge motor driver breakout board
  • DVD tray with DC motor

See circuit diagram of the design is shown below

password enabled door lock system
Figure 1.0 password enabled door lock system

Suggested readings

How to use 4X4 matrix keypad with Arduino
interfacing LCD with Arduino
Arduino tutorial for beginners

I used a carton as an improvised house with the DVD tray as the door see the DVD being strapped to the carton.

Electronic door
Figure 2.0 DVD tray with DC motor as electronic door
connecting the various parts
Figure 3.0 Connecting the various parts
Password based door lock
Figure 4.0 Password based door lock

The Arduino code for the design is shown below

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>

#define Password_Length 5 

int signalPin1 = 10;
int signalPin2= 11; 

char Data[Password_Length]; 
char Master[Password_Length] = "3142"; 
byte data_count = 0, master_count = 0;
bool Pass_is_good;
char customKey;

const byte ROWS = 4;
const byte COLS = 4;

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

byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

LiquidCrystal_I2C lcd(0x27, 16, 2);  

void setup(){
  lcd.init(); 
  lcd.backlight();
  pinMode(signalPin1, OUTPUT);
  pinMode (signalPin2, OUTPUT);
}

void loop(){

  lcd.setCursor(0,0);
  lcd.print("Enter Password:");
  

  customKey = customKeypad.getKey();
  if (customKey){
    Data[data_count] = customKey; 
    lcd.setCursor(data_count,1); 
    lcd.print(Data[data_count]); 
    data_count++; 
    }

  if(data_count == Password_Length-1){
    lcd.clear();

    if(!strcmp(Data, Master)){
      lcd.print("Access Granted");
      digitalWrite(signalPin1,  LOW);
      digitalWrite(signalPin2,HIGH); 
      delay(5000);
      digitalWrite(signalPin1, HIGH);
      digitalWrite(signalPin2,LOW); 
      }
    else{
      lcd.print("Access Denied");
      delay(1000);
      }
    
    lcd.clear();
    clearData();  
  }
}

void clearData(){
  while(data_count !=0){
    Data[data_count--] = 0; 
  }
  return;
}

You can power the Arduino via your PC or using a battery. You can connect the battery to the Arduino by connecting the battery to a 2.1 mm barrel jack with terminal block, and then connecting the barrel jack to the Arduino board. See image below.

Arduino connected to a barrel jack barrel jack
Figure 5.0 Arduino connected to a barrel jack barrel jack

Operation

The programmed password is 3142, a number I picked from pi. Anyway, any 4 numbers will be fine for this project, you can change the numbers in the code on line 8. Please note that the password length variable on line four of the Arduino code should be one digit greater than the number of password digits you are programming with. For example, if your password is 909543, the, the password length on line four will be 7, if it is 3142, the password length on line four should be 5 (as I used) , if it is 452, the password length on line four should be 4, and so on.

When the device is on, “Enter password” will be displayed on the LCD, entering a four-digit password that is not “3142” will display “Access Denied,” but when you enter the correct password which is “3142”, the LCD will display Access Granted as the door opens and while remaining open for 5 seconds and then closes automatically. Watch the video below.

password based security door lock

Learning Further

As I was testing the design, a friend told me to incorporate a sensor to monitor if there is an obstruction while the door is closing, so, I’m considering doing that in one of my subsequent projects, so, to be notified when the project is ready, endeavor to subscribe to my YouTube channel and click the notification bell to be notified when the project is ready.

Meanwhile before then, check out these other Arduino project tutorials.

How to make robotic arm with Arduino
How to make a scrolling text display with Arduino
How to make a water level indicator and control with Arduino
How to make a remote controlled light switch with Arduino
How to make a distance measuring device with Arduino and Ultrasonic sensor

Tags

Related Articles

Leave a Reply

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

Back to top button
Close