Class 6 - Simple Digital Door Lock

May 15, 2025

🔐 Build a Simple Digital Door Lock Using 8051 and BuddyKit

Hi buddies! 👋

In this class, we’re building a simple digital door lock system using the Buddy51 Mini development board. This project uses a 4×4 matrix keypad to enter a password and a relay connected to a digital pin to control the lock. The status of the door (Locked or Opened) is displayed on a 16×2 LCD screen.

📌 What You’ll Learn

  • How to define and use digital pins to control relays
  • Storing and comparing passwords using arrays
  • How to use LCD to show real-time door status
  • Using keypad input securely with masked characters

⚙️ Hardware Used

  • Buddy51 Mini Board
  • 4×4 Matrix Keypad
  • 16×2 LCD Display
  • Relay Module (connected to P1.0)
  • Connecting wires and 5V power

📺 LCD Function Recap

We’re using the same LCD4 library from our previous classes, which includes the following functions:

  • LCD_Init() – Initialize the LCD
  • LCD_Command() – Send commands to the LCD
  • LCD_Data() – Display single character
  • LCD_Puts() – Display strings
  • LCD_Clear(row, col, len) – Clear specific section

🔒 Project Overview

We’ll use P1.0 to control a relay module, which will physically lock/unlock a door. A variable called isLocked keeps track of the door state – 1 means locked, and 0 means open.

The # key will be used to lock the door, and the A key will unlock it. On locking, the user is asked to set a 6-digit password. To unlock, the entered password is verified with the stored one. If it matches, the door opens. Otherwise, it shows “Denied!”.

🧠 Logic Flow

  1. Initialize LCD and relay pin (P1.0)
  2. Set initial status to unlocked
  3. When # is pressed and door is open → ask user to set password
  4. When A is pressed and door is locked → verify entered password
  5. If correct, unlock the door; else display denied

💡 Program Code

🧠 Code Explanation

  • RELAY_PIN is defined for easy control of door lock.
  • getPassword() function takes 6-digit input and stores it as masked (‘*’) characters on display.
  • checkPassword() compares saved and entered passwords.
  • updateStatus() refreshes the LCD with current door status.
  • Main loop handles locking and unlocking based on keypress (# for lock, A for unlock).

Once uploaded to Buddy51 Mini, power the board and try locking and unlocking using your keypad. If you enter the correct password, the relay turns off, unlocking the door!

📺 Output

  • # Key → Set password and lock door
  • A Key → Enter password to unlock
  • Wrong password → Shows “Denied!”

❓ Have Doubts?

If you have any questions about the digital lock logic, relay handling, or keypad interfacing, drop them in the comments or our forum at BuddyKit.io.

Happy Learning! 💡
– Team BuddyKit

Leave a reply
Class 5 – 4×4 Matrix Keypad & LCDUltrasonic Sensor Distance Calculation – BuddyKit

Leave Your Reply