Password Door Lock Using Arduino

Password Door Lock Using Arduino

Password Door Lock Using Arduino

In this project, we will create a Password Door Lock System using Arduino UNO, a 4x4 Keypad, LCD Display with I2C module, Servo Motor, Buzzer, and Jumper Wires. The system allows door access by entering a correct password via the keypad. If the correct password is entered, the servo motor will rotate and open the door by moving the latch, and a buzzer will beep to confirm access. If the entered password is incorrect, the servo remains locked and a different buzzer sound will indicate the wrong password. The LCD will display important system messages like welcome greetings, password entry status, access granted or denied.


Working Principle

The system operates using a 4-digit password (you can change the number of digits or the password itself by modifying the Arduino code). When the user enters the password through the keypad:

  • If the entered password matches the stored password:

    • The buzzer beeps once
    • The servo motor rotates to unlock the door latch
    • LCD displays "Correct Password" and "Door Opened" or "Door Locked" depending on action
  • If the password is incorrect:

    • The buzzer beeps multiple times
    • The servo motor stays locked
    • LCD displays "Wrong Password" and "Please Try Again"

A latch mechanism connected by a steel rod with the servo enables mechanical movement. All user interactions and system states are shown on the LCD screen.


Materials Required


Step-by-Step Assembly Guide

1. Place the Arduino UNO

On a flat surface or inside a suitable casing.

2. Connect the 4x4 Keypad

  • Connect keypad row and column pins to Arduino digital pins 2–9

3. Wire the LCD with I2C Module

  • Connect VCC and GND of I2C module to Arduino 5V and GND
  • Connect SDA to Arduino A4 and SCL to A5

4. Connect the Servo Motor

  • Connect servo's signal pin to Arduino pin 10
  • Power the servo using Arduino 5V and GND (or external power if servo is powerful)

5. Connect the Buzzer

  • Positive terminal of buzzer to Arduino digital pin 11
  • Negative terminal to Arduino GND

6. Upload the Code

  • Connect Arduino to PC
  • Upload the provided code via Arduino IDE

7. Mount the Mechanical Parts

  • Attach the latch to the servo using a steel linkage
  • Align latch movement properly for smooth door locking/unlocking action

8. Power ON the System

  • Use Arduino USB or a 9V adapter
  • Watch LCD display welcome messages and start using the lock system

Circuit Diagram

The complete circuit wiring and connection setup are demonstrated clearly in the project tutorial video.

🎥 Watch the video above for full wiring instructions and demonstration.

Please follow the video carefully for exact wire positioning and mechanical latch setup.


Arduino Code

Upload the following code to your Arduino UNO to operate the password door lock system.

#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; //hold the new password
char newPassword[6]; //charater string of newPasswordString
byte a = 5;
bool value = true;

Password password = Password("0123"); //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(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 {
    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 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();
}

Code Explanation:

Setup:

Initializes the LCD display, servo motor, buzzer, and keypad. Sets up the welcome message that displays for 3 seconds on startup. The default password is set to "0123" which can be changed in the code.

Loop:

Continuously monitors the keypad for input. When a password is entered, it displays asterisks (*) on the LCD for each character. When the password is complete (4 digits by default), it checks against the stored password. If correct, it opens the door (servo moves) and gives a confirmation beep. If incorrect, it gives an error beep pattern and displays a failure message.

Key Functions:

  • 'C' key resets the password entry
  • 'D' key toggles between locked and unlocked states when the correct password is entered
  • Other keys (0-9, A, B, #, *) are used for password entry

Why Choose This Design?

  • Simple yet Secure: Easy to build but provides a solid layer of basic security
  • 🔑 Customizable Passwords: You can modify password length and values directly from the Arduino code
  • 📺 Visual and Audio Feedback: LCD displays real-time system status, and buzzer gives immediate audio cues
  • 🚪 Mechanical Realism: Simulates real-world locking/unlocking using servo-powered latch movement
  • 🔄 Expandable: You can enhance this system with GSM modules, fingerprint sensors, RFID modules, or Bluetooth for more advanced security systems
  • 💰 Low Cost: All materials are easily available and affordable, making this a great project for students and DIY enthusiasts

Comments

Post a Comment

Popular posts from this blog

Arduino Code Car Parking System

Arduino Code