A modern technology banner image

Password based door locking system using Arduino nano.

OBJECTIVE

The password door locking system aims to grant entry upon correct password input within 5 minutes of the door being locked.

MODULES REQUIRED

  • Arduino nano
  • LCD 16 x 2
  • Buzzer
  • Keypad
  • Servo
  • Potentiometer

SCHEMATIC DIAGRAM

Schematic diagram showing an Arduino connected to an LED and a push button.

SCHEMATIC CONNECTION

Connect keypad :

  • Connect the 1 to 8 of the keypad to the D1 to D7 pins on the Arduino nano.
  • Connect servo :

  • Connect the Gnd of the servo to the Gnd pin on the Arduino nano.
  • Connect the v+ of the servo to the 5V pin on the Arduino nano
  • Connect the pwm of the servo to the D9 pin on the Arduino.
  • Connect potentiometer :

  • Connect the Gnd of the potentiometer to the GND pin on the Arduino nano.
  • Connect the sig pin of the potentiometer to the V0 pin on the lcd display
  • Connect the vcc of the potentiometer to the 5v on the Arduino nano.
  • Connect Buzzer:

  • Connect the +ve pin of the buzzer to the D8 pin on the Arduino nano
  • Connect the -ve pin of the buzzer to the Gnd pin on the servo .
  • Connect Lcd:

  • Connect the vs pin of the Lcd to the GND pin on the Arduino nano.
  • Connect the VS pin and RW pin together and then connect them to the LCD.
  • Connect the RW pin and k pin together and then connect them to the LCD.
  • Connect the VDD pin and A pin together and then connect them to the LCD.
  • Connect the RS pin of the lcd to the A0 pin on the Arduino nano .
  • Connect the E pin of the lcd to the A1 pin on the Arduino nano .
  • Connect the D4 pin of the lcd to the A2 pin on the Arduino nano .
  • Connect the D5 pin of the lcd to the A3 pin on the Arduino nano .
  • Connect the D6 pin of the lcd to the A4 pin on the Arduino nano .
  • Connect the D7 pin of the lcd to the A5 pin on the Arduino nano .
  • To begin your project, click this template link:

    Simulate on Wokwi

    ARDUINO CODE

    
    #include (Keypad.h)
    #include (LiquidCrystal.h)
    #include (Servo.h)
    
    Servo myservo;
    LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);
    
    const byte rows = 4, cols = 3;
    char keys[rows][cols] = {
      {'1','2','3'}, {'4','5','6'}, {'7','8','9'}, {'*','0','#'}
    };
    byte rowPins[rows] = {1, 2, 3, 4};
    byte colPins[cols] = {5, 6, 7};
    Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);
    
    const char* password = "4567";
    int currentPos = 0, redLED = 10, greenLED = 11, buzzer = 8, failCount = 0;
    
    void setup() {
      Serial.begin(9600);
      lcd.begin(16, 2);
      myservo.attach(9);
      pinMode(redLED, OUTPUT);
      pinMode(greenLED, OUTPUT);
      pinMode(buzzer, OUTPUT);
      welcomeScreen();
    }
    
    void loop() {
      char key = keypad.getKey();
      if (key) {
        lcd.clear(); lcd.setCursor(0, 0);
        lcd.print("PASSWORD:");
        lcd.setCursor(0, 1);
        for (int i = 0; i <= currentPos; i++) lcd.print("*");
        beep();
    
        if (key == password[currentPos]) {
          currentPos++;
          if (currentPos == 4) {
            unlockDoor();
            currentPos = 0;
            failCount = 0;
          }
        } else {
          failCount++;
          wrongPassword();
          currentPos = 0;
          if (failCount == 5) waitPunishment(15000, "15 SECONDS");
          if (failCount == 8) waitPunishment(60000, "1 MINUTE");
        }
      }
    }
    
    void welcomeScreen() {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("*ENTER THE CODE*");
      lcd.setCursor(1, 1);
      lcd.print("TO _/_ (OPEN)!!");
    }
    
    void unlockDoor() {
      lcd.clear();
      lcd.print("Access Granted");
      lcd.setCursor(4, 1);
      lcd.print("WELCOME!!");
      buzzPattern();
      moveServo(90, 0);
      delay(2000);
      countdownBeep();
      moveServo(0, 90);
      welcomeScreen();
    }
    
    void moveServo(int start, int end) {
      int step = (start < end) ? 5 : -5;
      for (int pos = start; pos != end + step; pos += step) {
        myservo.write(pos);
        delay(15);
      }
    }
    
    void wrongPassword() {
      lcd.clear();
      lcd.setCursor(1, 0); lcd.print("CODE INCORRECT");
      lcd.setCursor(4, 1); lcd.print("GET AWAY!!!");
      Serial.println("Unauthorized access attempt.");
      digitalWrite(redLED, HIGH); digitalWrite(buzzer, HIGH);
      delay(2000);
      digitalWrite(redLED, LOW); digitalWrite(buzzer, LOW);
      welcomeScreen();
    }
    
    void beep() {
      digitalWrite(buzzer, HIGH); delay(50);
      digitalWrite(buzzer, LOW);
    }
    
    void buzzPattern() {
      for (int i = 0; i < 4; i++) {
        digitalWrite(buzzer, HIGH); delay(80);
        digitalWrite(buzzer, LOW); delay(80);
      }
    }
    
    void countdownBeep() {
      for (int i = 5; i > 0; i--) {
        lcd.clear();
        lcd.setCursor(2, 0); lcd.print("GET IN WITHIN:");
        lcd.setCursor(6, 1); lcd.print(i);
        digitalWrite(buzzer, HIGH); delay(100);
        digitalWrite(buzzer, LOW); delay(900);
      }
      for (int i = 0; i < 4; i++) {
        digitalWrite(buzzer, HIGH); delay(50);
        digitalWrite(buzzer, LOW); delay(50);
      }
      lcd.clear();
      lcd.print("RE-LOCKING...");
      delay(1000);
      lcd.clear(); lcd.setCursor(4, 0);
      lcd.print("LOCKED!");
      delay(1000);
    }
    
    void waitPunishment(unsigned long timeMs, const char* msg) {
      lcd.clear();
      lcd.setCursor(2, 0); lcd.print("WAIT FOR");
      lcd.setCursor(4, 1); lcd.print(msg);
      digitalWrite(buzzer, HIGH);
      delay(timeMs);
      digitalWrite(buzzer, LOW);
      lcd.clear();
      lcd.print("Enjoyed that?");
      delay(2000);
      welcomeScreen();
    }
    
    
    
    
    
    
    
    

    INSTRUCTIONS

  • Assemble the circuit by connecting all components as shown in the schematic diagram.
  • On the left side of the screen, open sketch.ino and write your Arduino code.
  • After completing the circuit and writing the code, click the green Play button to start the simulation.
  • Enter the correct password to unlock the door within 5 minutes after locking.
  • WORKING PRINCIPLE

  • The working principle of this project is that the door unlocks only when the correct password is entered within 5 minutes after it has been locked.

  • Project Link

    for your reference.

    `