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

by Webotricks in Circuits > Arduino

2 Views, 0 Favorites, 0 Comments

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

Untitled design (59).png

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.


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.


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.

Supplies

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



Arduino Nano board x 1 — BUY NOW


Immagine

16 X 2 LCD display - Buy Now




I2C module x 1 — BUY NOW


Immagine

5V Passive Buzzer - Buy Now



1 Breadboard - Buy Now



1 Jumper Wires - BUY NOW



Relay module x 1 — BUY NOW



Keypad module



Door lock


Screenshot 2025-04-17 164421.png

Firstly, identify these components.


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.

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

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

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

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

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

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


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.

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

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.

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

Next, enter your password as you like. I have used “1234”

And then, select board and port. Finally, click the upload button.

#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();
}

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.