AUTOMATIC DOOR LOCKING SYSTEM USING ARDUINO UNO

Automatic Door Lock System – Arduino UNO + Keypad + Servo + LCD | MakeMindz
🔐 Security & Automation Project

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.

🔲 Arduino UNO ⌨️ 4×4 Keypad 🖥️ 16×2 LCD I2C ⚙️ Micro Servo 🔔 Buzzer 🔐 Password Lock

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

🔲Arduino UNOMain microcontroller — runs all logic
⌨️4×4 Keypad16-key membrane matrix for password input
🖥️LCD 16×2 (I2C)Displays status messages over I2C (only 2 wires)
⚙️Micro ServoSG90 rotates to lock/unlock the door mechanism
🔔BuzzerAudible alert for wrong password attempts
Resistor (1kΩ)Current limiting for buzzer circuit
🧪BreadboardFor prototyping connections
🔌Arduino USB CablePower and programming via USB port

How the System Works

🔌BOOT

Power On

LCD displays welcome message. System waits for user keypad input.

⌨️INPUT

Type Password

User types the 4-digit code on the keypad. Each key press appears on LCD as *.

CONFIRM

Press D to Submit

Press D key to confirm entry. Arduino compares input against stored password.

🔓OUTPUT

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 1: Access Granted!
Line 2: Door Unlocked :)
🔒

Wrong Password

Buzzer sounds for 1 second. Servo stays locked. LCD shows error message.

Line 1: Wrong Password!
Line 2: Try Again...

⌨️ 4×4 Keypad Layout

Membrane Keypad — Default Password: 0 1 2 3 D

1
2
3
A
4
5
6
B
7
8
9
C
*
0
#
D

🟦 Number keys   🟪 Letters (A/B/C)   🟩 D = Confirm/Enter   🟧 * / # = Special




🔌 Circuit Diagram

Arduino UNO – Keypad + LCD I2C + Servo + Buzzer – Wiring Diagram Arduino UNO A4/SDA (LCD) A5/SCL (LCD) D2 (KP R1) D3 (KP R2) D4 (KP R3) D5 (KP R4) D6 (KP C1) D7 (KP C2) D8 (KP C3) D9 (KP C4) D10 (Servo) D11 (Buzzer) 5V GND 3.3V (LCD VCC) LCD 16×2 I2C Enter Password: _ _ _ _ SDA → SCL → 4×4 Keypad 12 3A 45 6B 78 9C *0 #D R1→R4 C1→C4 Micro Servo SG90 PWM → 0° LOCK 90° = UNLOCKED Buzzer 🔔 Wrong password alert Power 5V → Servo, Buzzer 3.3V → LCD VCC Common GND WIRE LEGEND: I2C (SDA/SCL) Keypad Rows Keypad Cols Servo / GND 5V / Buzzer 1kΩ resistor in series with buzzer · LCD VCC uses 3.3V pin 🔑 Default Password 0 1 2 3 D Press D to confirm · Change in code: char password[] = "0123"

📋 Pin Connection Table

ComponentComponent PinArduino PinWireNotes
LCD I2CSDAA4YellowI2C data — address 0x27 or 0x3F
LCD I2CSCLA5YellowI2C clock line
LCD I2CVCC5VRedLCD power supply
LCD I2CGNDGNDBlackCommon ground
4×4 KeypadRow 1D2PurpleKeypad row scanning
4×4 KeypadRow 2D3PurpleKeypad row scanning
4×4 KeypadRow 3D4PurpleKeypad row scanning
4×4 KeypadRow 4D5PurpleKeypad row scanning
4×4 KeypadCol 1D6BlueKeypad column scanning
4×4 KeypadCol 2D7BlueKeypad column scanning
4×4 KeypadCol 3D8BlueKeypad column scanning
4×4 KeypadCol 4D9BlueKeypad column scanning
Servo MotorSignalD10OrangePWM signal for servo control
Servo MotorVCC5VRedServo power
Servo MotorGNDGNDBlackCommon ground
BuzzerPositive (+)D11RedVia 1kΩ resistor in series
BuzzerNegative (–)GNDBlackCommon ground

📝 Step-by-Step Instructions

1

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)
2

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.

3

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
4

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
5

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
6

Wire the Buzzer

  • Buzzer positive (+) → 1kΩ resistor → Arduino D11
  • Buzzer negative (–) → Arduino GND
  • The resistor limits current to protect the Arduino digital pin
7

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.

8

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

lcd.begin()

Initialises the LCD interface and sets dimensions (16 cols, 2 rows). Must be called first before any other LCD command.

lcd.setCursor()

Positions the cursor at a specific column and row. E.g. lcd.setCursor(0,1) = start of second line.

lcd.print()

Prints text or numbers to the LCD at the current cursor position. Works just like Serial.print().

lcd.clear()

Clears all text from the LCD screen and resets the cursor to the top-left (0,0) position.

myservo.write()

Rotates the servo to the specified angle in degrees. write(0) = locked, write(90) = unlocked door position.

delay()

Pauses the program for the specified milliseconds. Used to keep the door unlocked briefly before re-locking automatically.

💻 Arduino Code

ARDUINO C++  ·  AutoDoorLock.ino
/*
 * 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

🏭 Applications

🏠 Home Door Security 🔐 Cabinet / Safe Lock 🏫 School Lab Access Control 🏭 Equipment Room Lock 🎓 STEM Exhibition Project 🔬 Science Fair Demo 🤖 Robotics Entry Gate 📚 Embedded Systems Learning

© 2026 MakeMindz · Automatic Door Lock System – Arduino UNO Tutorial · All rights reserved

Comments

try for free