Password Door
Lock System
Build a fully functional keypad-controlled door lock with an Arduino UNO, 4×4 keypad, I²C LCD, servo motor, and buzzer. Visual + audio feedback, servo-powered latch, real-time status on display.
How It Works
The system uses a 4-digit password stored in firmware. The user enters digits via the keypad — each keypress shows an asterisk on the LCD. On completion, the Arduino checks the entry and responds immediately with servo movement and audio feedback.
- Buzzer beeps once (300 ms)
- Servo motor rotates to unlock latch
- LCD shows "CORRECT PASSWORD" + "DOOR OPENED"
- D key toggles lock/unlock state
- Buzzer triple-beeps (200 ms each)
- Servo stays locked at 110°
- LCD shows "WRONG PASSWORD!" + "PLEASE TRY AGAIN"
- Password entry resets automatically
A latch mechanism connected by a steel rod to the servo enables mechanical movement. All system states are reflected on the LCD in real-time.
Components Required
Six key components — all widely available, beginner-friendly, and budget-conscious.
Step-by-Step Build
Follow these steps in order for a clean, reliable build. Complete wiring details are in the video below.
Place the Arduino UNO
Mount on a flat surface or inside a project casing. Ensure full pin access on both sides.
Connect the 4×4 Keypad
Row and column pins connect to Arduino digital pins 2 through 9 in order.
Wire the LCD with I2C
VCC → 5V, GND → GND, SDA → A4, SCL → A5. I2C address is 0x27 by default.
Connect the Servo Motor
Signal wire → pin 10. Power servo from Arduino 5V/GND or an external supply for heavier servos.
Connect the Buzzer
Positive terminal → pin 11, negative → GND. Active buzzer recommended.
Upload the Code
Open Arduino IDE, paste the code below, select the correct port, and upload.
Mount Mechanical Parts
Attach the latch via a steel linkage rod to the servo horn. Align for smooth lock/unlock travel.
Power On & Test
Use USB or a 9V adapter. LCD shows welcome message, then prompts for password entry.
Circuit Diagram
Complete wiring and connection details are shown clearly in the tutorial video. Click the diagram to view full resolution.
Full assembly tutorial above — exact wire positions, I2C address setup, mechanical latch alignment, and live demo of lock/unlock cycles.
Follow the video carefully for exact wire positioning and the mechanical latch configuration.
Arduino Code
Upload this sketch to your UNO. Default password is 0123 — change it inside the Password password = Password("0123"); line.
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <Password.h>
#define buzzer 11
Servo servo;
LiquidCrystal_I2C lcd(0x27, 16, 2);
String newPasswordString;
char newPassword[6];
byte a = 5;
bool value = true;
Password password = Password("0123"); // ← Change your password here
byte maxPasswordLength = 6;
byte currentPasswordLength = 0;
const byte ROWS = 4;
const byte COLS = 4;
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(10);
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("DOOR OPENED ");
delay(2000);
lcd.clear();
a = 5;
} else {
for (int i = 0; i < 3; i++) {
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 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 {
for (int i = 0; i < 3; i++) {
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();
}
setup()
Initializes LCD, servo at 50°, buzzer pin, and keypad. Shows 3-second welcome message. Default password: 0123.
loop()
Polls keypad continuously. Displays asterisks for each digit. After max digits, automatically triggers doorlocked → dooropen sequence.
dooropen() / doorlocked()
Evaluates password, moves servo to 50° (open) or 110° (locked), plays appropriate buzzer pattern, updates LCD.
| Key | Function |
|---|---|
| C | Reset / clear current password entry |
| D | Toggle lock ↔ unlock state (requires correct password) |
| 0–9, A, B, #, * | Password character input (displayed as * on LCD) |
Why Choose This Design?
A practical balance of security, feedback, and expandability — perfect for learning embedded systems.
Simple yet Secure
Easy to build but provides a solid layer of basic access control.
Customizable Password
Change length and value directly in the code — no hardware changes needed.
Visual + Audio Feedback
LCD shows real-time state. Buzzer gives distinct tones for success and failure.
Mechanical Realism
Servo-powered steel rod latch simulates a real-world door mechanism.
Expandable
Add GSM, fingerprint sensor, RFID, or Bluetooth for advanced security layers.
Low Cost
All parts under ₹500 combined. Great for students and DIY enthusiasts.
not working
ReplyDeleteHi
Deletewhat is the pin for this code
ReplyDeletethe code is incorrect
ReplyDeleteThis code is not working
ReplyDeleteUse it wisely
DeleteCode is not working ðŸ˜
ReplyDeleteCode is not work 😔
Deletecode not working
ReplyDeletecode nor working
ReplyDeletecode is not working bro
ReplyDeletekeypad is no keyword
ReplyDeleteCode is not working
ReplyDeletecode is not working well
ReplyDelete