Automatic Door Lock System
Arduino UNO
Password-controlled smart door lock using a 4×4 keypad, 16×2 I2C LCD display, micro servo motor, and buzzer alert — all powered by Arduino UNO.
As the world moves toward smarter living spaces, the Automatic Door Lock System offers a practical solution combining security and automation. This project uses an Arduino UNO to create a fully functional password-based electronic door lock.
The user types a password on the 4×4 keypad. The 16×2 I2C LCD shows status messages, and when the correct password is entered, the micro servo rotates to unlock the door. An incorrect entry triggers the buzzer for a wrong-password alert. The default password is 0123 followed by D.
🧩 Components Required
⚡ How the System Works
Power On
LCD displays welcome message. System waits for user keypad input.
Type Password
User types the 4-digit code on the keypad. Each key press appears on LCD as *.
Press D to Submit
Press D key to confirm entry. Arduino compares input against stored password.
Lock / Unlock
Correct → servo unlocks. Wrong → buzzer sounds and LCD shows error.
🔐 Password Outcomes
Correct Password
Servo rotates to 90° (unlock position) for 3 seconds, then returns to 0° (locked).
Line 2: Door Unlocked :)
Wrong Password
Buzzer sounds for 1 second. Servo stays locked. LCD shows error message.
Line 2: Try Again...
⌨️ 4×4 Keypad Layout
Membrane Keypad — Default Password: 0 1 2 3 D
🟦 Number keys 🟪 Letters (A/B/C) 🟩 D = Confirm/Enter 🟧 * / # = Special
🔌 Circuit Diagram
📋 Pin Connection Table
| Component | Component Pin | Arduino Pin | Wire | Notes |
|---|---|---|---|---|
| LCD I2C | SDA | A4 | Yellow | I2C data — address 0x27 or 0x3F |
| LCD I2C | SCL | A5 | Yellow | I2C clock line |
| LCD I2C | VCC | 5V | Red | LCD power supply |
| LCD I2C | GND | GND | Black | Common ground |
| 4×4 Keypad | Row 1 | D2 | Purple | Keypad row scanning |
| 4×4 Keypad | Row 2 | D3 | Purple | Keypad row scanning |
| 4×4 Keypad | Row 3 | D4 | Purple | Keypad row scanning |
| 4×4 Keypad | Row 4 | D5 | Purple | Keypad row scanning |
| 4×4 Keypad | Col 1 | D6 | Blue | Keypad column scanning |
| 4×4 Keypad | Col 2 | D7 | Blue | Keypad column scanning |
| 4×4 Keypad | Col 3 | D8 | Blue | Keypad column scanning |
| 4×4 Keypad | Col 4 | D9 | Blue | Keypad column scanning |
| Servo Motor | Signal | D10 | Orange | PWM signal for servo control |
| Servo Motor | VCC | 5V | Red | Servo power |
| Servo Motor | GND | GND | Black | Common ground |
| Buzzer | Positive (+) | D11 | Red | Via 1kΩ resistor in series |
| Buzzer | Negative (–) | GND | Black | Common ground |
📝 Step-by-Step Instructions
Install Required Libraries
Open Arduino IDE → Sketch → Include Library → Manage Libraries. Install these three:
- Keypad by Mark Stanley & Alexander Brevig
- LiquidCrystal I2C by Frank de Brabander
- Servo (built-in — no install needed)
Find Your LCD I2C Address
Most 16×2 I2C LCDs use address 0x27 or 0x3F. Upload the I2C Scanner sketch (File → Examples → Wire → i2c_scanner) to find your exact address and update it in the code.
Wire the LCD I2C Display
- LCD SDA → Arduino A4
- LCD SCL → Arduino A5
- LCD VCC → Arduino 5V
- LCD GND → Arduino GND
- Adjust backlight contrast using the potentiometer on the I2C module
Wire the 4×4 Keypad (8 wires)
The keypad has 8 pins — 4 rows and 4 columns. Connect in order from left to right:
- Row 1→4 → Arduino D2, D3, D4, D5
- Col 1→4 → Arduino D6, D7, D8, D9
Wire the Servo Motor
- Servo Signal (orange) → Arduino D10
- Servo VCC (red) → Arduino 5V
- Servo GND (brown/black) → Arduino GND
- At 0° = door locked, 90° = door unlocked
Wire the Buzzer
- Buzzer positive (+) → 1kΩ resistor → Arduino D11
- Buzzer negative (–) → Arduino GND
- The resistor limits current to protect the Arduino digital pin
Upload the Code & Test
Select Tools → Board → Arduino UNO, choose your COM port, and upload. Open Serial Monitor at 9600 baud. Power on — LCD should show "Enter Password:". Type 0123D to unlock.
Change the Password
In the code, find the line char password[] = "0123"; and change "0123" to any 4-digit combination you want. Re-upload to activate the new password.
Default Password
The preset password is 0123. Press each digit then press D to submit. Press * or # to clear and reset input at any time.
🔧 Key LCD Functions Explained
Initialises the LCD interface and sets dimensions (16 cols, 2 rows). Must be called first before any other LCD command.
Positions the cursor at a specific column and row. E.g. lcd.setCursor(0,1) = start of second line.
Prints text or numbers to the LCD at the current cursor position. Works just like Serial.print().
Clears all text from the LCD screen and resets the cursor to the top-left (0,0) position.
Rotates the servo to the specified angle in degrees. write(0) = locked, write(90) = unlocked door position.
Pauses the program for the specified milliseconds. Used to keep the door unlocked briefly before re-locking automatically.
💻 Arduino Code
/* * Automatic Door Lock System – Arduino UNO * Components: 4x4 Keypad, 16x2 LCD I2C, Micro Servo, Buzzer * * Default Password: 0123 + D to confirm * Servo: 0° = Locked, 90° = Unlocked * * Tutorial: https://www.makemindz.com */ #include <Wire.h> #include <LiquidCrystal_I2C.h> #include <Keypad.h> #include <Servo.h> // LCD I2C setup (address 0x27 or 0x3F — use I2C scanner to find yours) LiquidCrystal_I2C lcd(0x27, 16, 2); // Servo Servo myServo; const int servoPin = 10; // Buzzer const int buzzerPin = 11; // Password — change this to your desired 4-digit code char password[] = "0123"; int passwordLength = 4; String enteredPassword = ""; // 4x4 Keypad setup const byte ROWS = 4; const byte COLS = 4; char keys[ROWS][COLS] = { {'1','2','3','A'}, {'4','5','6','B'}, {'7','8','9','C'}, {'*','0','#','D'} }; byte rowPins[ROWS] = {2, 3, 4, 5}; // Row pins → D2–D5 byte colPins[COLS] = {6, 7, 8, 9}; // Col pins → D6–D9 Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS); void setup() { Serial.begin(9600); pinMode(buzzerPin, OUTPUT); lcd.init(); lcd.backlight(); lcd.setCursor(0, 0); lcd.print(" Door Lock "); lcd.setCursor(0, 1); lcd.print(" System v1 "); delay(2000); myServo.attach(servoPin); myServo.write(0); // Start locked showEnterPrompt(); } void loop() { char key = keypad.getKey(); if (key) { if (key == '*' || key == '#') { // Reset input enteredPassword = ""; showEnterPrompt(); } else if (key == 'D') { // Confirm and check password checkPassword(); } else { // Append key to entered password if (enteredPassword.length() < passwordLength) { enteredPassword += key; lcd.setCursor(enteredPassword.length() - 1, 1); lcd.print("*"); // Show * for security } } } } void checkPassword() { if (enteredPassword == String(password)) { // Correct password — unlock lcd.clear(); lcd.setCursor(0, 0); lcd.print("Access Granted!"); lcd.setCursor(0, 1); lcd.print("Door Unlocked :)"); myServo.write(90); // Unlock position delay(3000); // Stay open 3 seconds myServo.write(0); // Re-lock } else { // Wrong password — alert lcd.clear(); lcd.setCursor(0, 0); lcd.print("Wrong Password!"); lcd.setCursor(0, 1); lcd.print("Try Again..."); digitalWrite(buzzerPin, HIGH); delay(1000); digitalWrite(buzzerPin, LOW); } enteredPassword = ""; delay(500); showEnterPrompt(); } void showEnterPrompt() { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Enter Password:"); lcd.setCursor(0, 1); lcd.print(" "); }
🚀 Try the Live Simulations
Test the full door lock system in your browser — type the password on the virtual keypad and watch the servo unlock!
✨ Key Features
Password-Based Access
Secure 4-digit password entry via membrane keypad with masked display (* characters)
I2C LCD Display
Real-time status messages for access granted, wrong password, and door state — only 2 wires needed
Auto Re-Lock
Servo automatically returns to locked position after 3 seconds — no manual re-lock needed
Wrong Password Alert
Buzzer sounds immediately for any incorrect password attempt — instant security feedback
Reset Anytime
Press * or # to clear the current input and start fresh without restarting
Easy to Customise
Change password, unlock duration, and servo angles with a single variable edit in the code

Comments
Post a Comment