How to Make a Secure Arduino-Based Door Lock with Keypad and LCD Display

How to Make a Secure Arduino-Based Lock with Keypad and LCD Display

Hello and welcome back. In this project, we will learn How to Make a Secure Arduino-Based Door Lock with Keypad and LCD Display. You can use it to secure your office, rooms, or home safes. To lock and unlock the door, you’ll need to enter a password into the security system. This ensures that only authorized people can open and close the door. Please note that it is only a door lock model. We’ve designed it so that you can easily make it at home for a low cost. It includes a keypad for entering the password, an LCD display to show information, and a servo motor to control the lock. This is a great solution for a DIY electronic door lock, but feel free to modify it as you see fit.

Keypad Module

For this project, I used a 4*4 keypad module. If you’re interested in learning how these keypad modules work, you can follow this link for more information.

LCD Display

I used a 16*2 LCD screen in this project, which I connected to it an I2C module through soldering. This means we only need four jumper wires to control the display. For more information about the LCD display and I2C module, you can click on this link.

Servo motor

The SG90 servo motor has been used in this project. It depends on your lock size. I used a small door lock. Because that’s only structure.

Ok, let’s do this project step by step. The required components are given below.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, identify these components.

Step 2

Next, cut the Rigifoam, foamboard, or cardboard piece according to the following instructions. Keep in mind that this is just an example door model, so feel free to use this knowledge for your own projects.

Step 3

Thirdly, cut out the door part using the pictures below.

Step 4

Then, glue the support piece and door handle to your door model.

Step 5

Next, make two holes for the LCD screen and keypad module. For that, use the pictures below.

Step 6

And then, connect the door to the door holder using the hinges.

Step 7

Next, connect the door lock to the servo motor. For that, use an iron stick.

Step 8

Now, install the door lock and servo motor as follows.

Step 9

Next, place the Arduino Nano board and the buzzer on the breadboard. Then, connect the buzzer and the LCD screen to the Arduino Nano board. Use the circuit diagram below for that.

How to Make a Secure Arduino-Based Lock with Keypad and LCD Display

Step 10

Now, install the LCD screen and connect the servo motor to the Arduino board.

Step 11

Then, install the keypad module and connect it to the Arduino Nano board(For that, use a male pin header). After that, glue the breadboard to the back of the door.

Step 12

Now, connect the Arduino board to the computer and upload the program to it.

How to Make a Secure Arduino-Based Lock with Keypad and LCD Display
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <Password.h>

#define buzzer 12

Servo servo;
LiquidCrystal_I2C lcd(0x27, 16, 2);

String newPasswordString; //hold the new password
char newPassword[6]; //charater string of newPasswordString
byte a = 5;
bool value = true;

Password password = Password("1234"); //Enter your password

byte maxPasswordLength = 6;
byte currentPasswordLength = 0;
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns


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


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

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


void setup() {
  Serial.begin(9600);
  pinMode(buzzer, OUTPUT);
  servo.attach(11);
  servo.write(50);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(3, 0);
  lcd.print("WELCOME TO");
  lcd.setCursor(0, 1);
  lcd.print("DOOR LOCK SYSTEM");
  delay(3000);
  lcd.clear();
}

void loop() {
  lcd.setCursor(1, 0);
  lcd.print("ENTER PASSWORD");

  char key = keypad.getKey();
  if (key != NO_KEY) {
    delay(60);
    if (key == 'C') {
      resetPassword();
    } else if (key == 'D') {
      if (value == true) {
        doorlocked();
        value = false;
      } else if (value == false) {
        dooropen();
        value = true;
      }
    } else {
      processNumberKey(key);
    }
  }
}

void processNumberKey(char key) {
  lcd.setCursor(a, 1);
  lcd.print("*");
  a++;
  if (a == 11) {
    a = 5;
  }
  currentPasswordLength++;
  password.append(key);

  if (currentPasswordLength == maxPasswordLength) {
    doorlocked();
    dooropen();

  }
}

void dooropen() {
  if (password.evaluate()) {
    digitalWrite(buzzer, HIGH);
    delay(300);
    digitalWrite(buzzer, LOW);
    servo.write(50);
    delay(100);
    lcd.setCursor(0, 0);
    lcd.print("CORRECT PASSWORD");
    lcd.setCursor(0, 1);
    lcd.print("OPEN THE DOOR...");
    delay(2000);
    lcd.clear();
    a = 5;
  } else {
    digitalWrite(buzzer, HIGH);
    delay(200);
    digitalWrite(buzzer, LOW);
    delay(200);
    digitalWrite(buzzer, HIGH);
    delay(200);
    digitalWrite(buzzer, LOW);
    delay(200);
    digitalWrite(buzzer, HIGH);
    delay(200);
    digitalWrite(buzzer, LOW);
    delay(200);
    lcd.setCursor(0, 0);
    lcd.print("WRONG PASSWORD!");
    lcd.setCursor(0, 1);
    lcd.print("PLEASE TRY AGAIN");
    delay(2000);
    lcd.clear();
    a = 5;
  }
  resetPassword();
}

void resetPassword() {
  password.reset();
  currentPasswordLength = 0;
  lcd.clear();
  a = 5;
}

//void changePassword() {
//  newPasswordString = "1234";
//  newPasswordString.toCharArray(newPassword, newPasswordString.length() + 1); //convert string to char array
//  password.set(newPassword);
//  resetPassword();
//  lcd.clear();
//  lcd.setCursor(0, 0);
//  lcd.print("Password changed");
//  delay(1000);
//  lcd.clear();
//}

void doorlocked() {
  if (password.evaluate()) {
    digitalWrite(buzzer, HIGH);
    delay(300);
    digitalWrite(buzzer, LOW);
    servo.write(110);
    delay(100);
    lcd.setCursor(0, 0);
    lcd.print("CORRECT PASSWORD");
    lcd.setCursor(2, 1);
    lcd.print("DOOR LOCKED");
    delay(2000);
    lcd.clear();
    a = 5;
  } else {
    digitalWrite(buzzer, HIGH);
    delay(200);
    digitalWrite(buzzer, LOW);
    delay(200);
    digitalWrite(buzzer, HIGH);
    delay(200);
    digitalWrite(buzzer, LOW);
    delay(200);
    digitalWrite(buzzer, HIGH);
    delay(200);
    digitalWrite(buzzer, LOW);
    delay(200);
    lcd.setCursor(0, 0);
    lcd.print("WRONG PASSWORD!");
    lcd.setCursor(0, 1);
    lcd.print("PLEASE TRY AGAIN");
    delay(2000);
    lcd.clear();
    a = 5;
  }
  resetPassword();
}
  • Next, enter your password as you like. I have used “1234”
How to Make a Secure Arduino-Based Lock with Keypad and LCD Display
  • And then, select board and port. Finally, click the upload button.

Step 13

Lastly, remove the USB cable and provide an external power supply to the circuit. For that, use the above circuit diagram.

Now you can test this project using your password. Ok, enjoy this project. The full video guide is below.

How to Make a Secure Arduino-Based Lock with Keypad and LCD Display

How to Make a Secure Arduino-Based Lock with Keypad and LCD Display

Similar Posts

2 Comments

Leave a Reply

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