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
Component | Quantity | Description | Link |
---|---|---|---|
Arduino UNO with Cable | 1 | Main micro controller | Buy Now |
4×4 Keypad | 1 | For password entry | Buy Now |
5V Relay Module | 1 | To control the lock (or substitute with LED/Servo) | Buy Now |
Breadboard | 1 | For circuit prototyping | Buy Now |
Jumper Wires | 10+ | For connections | Buy Now |
5V LED / Servo Motor | 1 | Simulates locking mechanism | Buy 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!