How to Build a Keypad Controlled Door Lock System Using Arduino

How to Build a Keypad Controlled Door Lock System Using Arduino
0
0
3 min read

Introduction

Security is a growing concern in both personal and industrial applications. From home automation systems to industrial access control, ensuring that only authorized users can access certain areas or devices is critical. One simple and cost-effective way to implement security is through a Keypad Controlled Lock System.

In this project, you will build a secure digital lock system using an Arduino and a 4×4 matrix keypad. When a predefined password is entered via the keypad, the system will trigger a lock mechanism (represented by an LED or servo motor). If the wrong code is entered, the system will deny access and can be extended to trigger an alarm.

This project is ideal for beginners to intermediate Arduino enthusiasts who want to explore real-world applications involving user input, conditional logic, and output control.

Real-World Applications:

  • Home door lock systems
  • Secure drawers and lockers
  • Employee-only access in offices
  • Remote-controlled security systems

Skill Level: Intermediate
Expected Outcome: Build a functioning security lock system using a keypad and Arduino


Components Required

ComponentQuantityDescriptionLink
Arduino UNO with Cable1Main micro controllerBuy Now
4×4 Keypad1For password entryBuy Now
5V Relay Module1To control the lock (or substitute with LED/Servo)Buy Now
Breadboard1For circuit prototypingBuy Now
Jumper Wires10+For connectionsBuy Now
5V LED / Servo Motor1Simulates locking mechanismBuy Now
Buy Now

Circuit Diagram + Explanation

Connections:

  • Keypad:
    • R1 to Arduino pin 9
    • R2 to pin 8
    • R3 to pin 7
    • R4 to pin 6
    • C1 to pin 5
    • C2 to pin 4
    • C3 to pin 3
    • C4 to pin 2
  • Relay IN to Arduino pin 13(Connect the relay input pin to control the lock)
  • Relay VCC to 5V
  • Relay GND to GND
  • Lock/LED/Servo connected as per the output mechanism

Arduino Code

#include <Keypad.h>

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] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};

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

String password = "1234";
String input = "";

int relayPin = 13;

void setup() {
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, LOW);
  Serial.begin(9600);
}

void loop() {
  char key = keypad.getKey();
  if (key) {
    Serial.println(key);
    if (key == '#') {
      if (input == password) {
        Serial.println("Access Granted");
        digitalWrite(relayPin, HIGH);
        delay(5000);
        digitalWrite(relayPin, LOW);
      } else {
        Serial.println("Access Denied");
      }
      input = "";
    } else if (key == '*') {
      input = "";
    } else {
      input += key;
    }
  }
}

Working Explanation

This project is a classic application of input verification and output control using Arduino:

  • The 4×4 keypad is used to capture the password input.
  • The Keypad library simplifies the process of reading key presses.
  • The password is stored as a string and compared when the # key is pressed.
  • If correct, the relay is turned ON (representing unlocking).
  • A 5-second delay keeps the lock open before resetting it.
  • Any incorrect entry simply prints “Access Denied.”

Demo / Output Preview


Troubleshooting & Tips

  • Double-check keypad wiring. Wrong rows/columns cause false readings.
  • Confirm your keypad layout matches the keymap.
  • Ensure you debounce long passwords with adequate delay.
  • Always test the relay separately before integration.
  • Use pull-down resistors or software debounce if keys get stuck.

Project Expansion Ideas

  • Add an LCD display to show password attempts or system status.
  • Incorporate EEPROM to save passwords permanently.
  • Use a servo motor for actual lock simulation instead of a relay.
  • Introduce a buzzer alarm for wrong password entries.
  • Add a Bluetooth or WiFi module for remote control or logging.

Conclusion

You’ve just created your own Keypad Controlled Lock System using Arduinoβ€”a simple, scalable, and secure system perfect for DIY home automation or school projects. This hands-on project not only helps you grasp input/output control but also opens doors to building more secure and smarter systems.

Ready to enhance your security project? πŸ”

βœ… Buy the complete kit from Elecsynergy

Share your feedback or project enhancements in the comments and don’t forget to subscribe to stay updated with more DIY Arduino projects!

Leave a Reply