Arduino Smart Door Lock using Keypad, Servo & I2C LCD

In this project, we will build a Smart Door Lock System using Arduino, 4×4 Keypad, Servo Motor, Buzzer, and 16×2 I2C LCD Display. Users can enter a password using the keypad. If the password is correct, the servo motor unlocks the door. If the password is incorrect, the buzzer alerts the user.

This project is perfect for beginners learning:

  • Arduino
  • Keypad interfacing
  • Servo motor control
  • I2C LCD display
  • Password-based security systems

Components Required

ComponentQuantity
Arduino Uno/Nano1
4×4 Matrix Keypad1
SG90 Servo Motor1
16×2 I2C LCD Display1
Buzzer1
Jumper WiresAs required
Breadboard (Optional)1

Circuit Connections

🔢 Keypad Connections

Keypad PinArduino Pin
R19
R28
R37
R46
C15
C24
C33
C42

Servo Motor Connections

Servo WireArduino
Red5V
Brown/BlackGND
Orange/YellowPin 10

Buzzer Connections

BuzzerArduino
Positive (+)Pin 11
Negative (-)GND

I2C LCD Connections

I2C LCD PinArduino Uno/Nano
VCC5V
GNDGND
SDAA4
SCLA5

Important Notes

Servo Power Issue

Servo motors sometimes draw high current and may not work properly using only USB power.

Symptoms:

  • Servo jitter
  • Weak movement
  • Arduino reset

Recommended Solution

Use external 5V power for servo:

  • 4×AA battery pack
  • 5V adapter
  • Power bank

IMPORTANT:
Connect Arduino GND and external power GND together.


LCD Not Displaying Text?

If LCD does not display text:

  • Adjust the blue potentiometer on the I2C module
  • Try changing I2C address from 0x27 to 0x3F

Required Arduino Libraries

Install these libraries from Arduino IDE Library Manager:

  • Keypad
  • Servo
  • LiquidCrystal_I2C

How the Smart Door Lock Works

  1. LCD displays “Enter Password”
  2. User enters password using keypad and Press # key
  3. If password is correct, LCD shows Access Granted
  4. Servo rotates and unlocks the door
  5. After 5 seconds, door locks automatically
  6. If password is incorrect, LCD displays as “Wrong Password”
  7. Buzzer beeps 3 times, the press * key to clear entered password

Please Note – Default Password is 1234 but You can change it in code

Arduino Code:

#include <Keypad.h>
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// ===== LCD =====
LiquidCrystal_I2C lcd(0x27, 16, 2);

// ===== KEYPAD SETTINGS =====
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'}
};

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

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

// ===== SERVO =====
Servo lockServo;
int servoPin = 10;

// ===== BUZZER =====
int buzzerPin = 11;

// ===== PASSWORD =====
String correctPassword = "1234";
String enteredPassword = "";

void setup() {

  Serial.begin(9600);

  // ===== LCD START =====
  lcd.init();
  lcd.backlight();

  lcd.setCursor(0, 0);
  lcd.print("Smart Door Lock");

  lcd.setCursor(0, 1);
  lcd.print("Enter Password");

  // ===== SERVO =====
  lockServo.attach(servoPin);

  // ===== BUZZER =====
  pinMode(buzzerPin, OUTPUT);

  // ===== LOCK POSITION =====
  lockServo.write(0);

  delay(2000);

  lcd.clear();
  lcd.print("Enter Password");
}

void loop() {

  char key = keypad.getKey();

  if (key) {

    Serial.print("Pressed: ");
    Serial.println(key);

    // ===== DISPLAY * =====
    if (key != '#' && key != '*') {

      enteredPassword += key;

      lcd.setCursor(0, 1);

      for (int i = 0; i < enteredPassword.length(); i++) {
        lcd.print("*");
      }
    }

    // ===== CHECK PASSWORD =====
    if (key == '#') {

      lcd.clear();

      if (enteredPassword == correctPassword) {

        Serial.println("Access Granted");

        lcd.setCursor(0, 0);
        lcd.print("Access Granted");

        // Servo unlock
        lockServo.write(90);

        delay(5000);

        // Servo lock
        lockServo.write(0);

        lcd.clear();
        lcd.print("Door Locked");
      }

      else {

        Serial.println("Wrong Password");

        lcd.setCursor(0, 0);
        lcd.print("Wrong Password");

        // Buzzer alert
        for (int i = 0; i < 3; i++) {

          digitalWrite(buzzerPin, HIGH);
          delay(200);

          digitalWrite(buzzerPin, LOW);
          delay(200);
        }
      }

      enteredPassword = "";

      delay(2000);

      lcd.clear();
      lcd.print("Enter Password");
    }

    // ===== CLEAR PASSWORD =====
    if (key == '*') {

      enteredPassword = "";

      lcd.clear();
      lcd.print("Password Cleared");

      delay(1000);

      lcd.clear();
      lcd.print("Enter Password");
    }
  }
}

Future Improvements

You can upgrade this project by adding:

  • RFID module
  • Fingerprint sensor
  • ESP32 WiFi control
  • Solenoid lock
  • Mobile app unlock
  • OTP verification
  • Emergency exit button

Video Tutorial

You can also watch the complete video tutorial on my YouTube channel for step-by-step explanation and demonstration.