This Arduino-based Smart Door Lock System is a simple and practical security project that uses a 4×4 matrix keypad, 16×2 I2C LCD, relay module, buzzer, and solenoid lock. Users can enter a password through the keypad to unlock the door, while the LCD provides real-time status messages. If an incorrect password is entered, the buzzer activates as an alert for unauthorized access attempts. The project demonstrates how embedded systems and automation can be combined to create a low-cost electronic security solution suitable for homes, offices, and IoT learning projects.
Recommended Components
- Arduino Uno
- 4×4 Matrix Keypad
- 16×2 I2C LCD
- Buzzer
- 5V relay module
- 12V solenoid lock
- 12V adapter
- 1N4007 diode (Optional)
Features:
- Enter password using keypad
- LCD displays prompts
- Relay unlocks solenoid lock when password is correct
- Buzzer beeps on wrong password
- Lock automatically closes after a few seconds
- Password can easily be changed in code
Required Libraries
Install these libraries from Arduino IDE Library Manager:
KeypadLiquidCrystal_I2C
Wire Connections:
4×4 Keypad
| Keypad Pin | Arduino Pin |
|---|---|
| R1 | 9 |
| R2 | 8 |
| R3 | 7 |
| R4 | 6 |
| C1 | 5 |
| C2 | 4 |
| C3 | 3 |
| C4 | 2 |
I2C LCD
| LCD Pin | Arduino |
|---|---|
| VCC | 5V |
| GND | GND |
| SDA | A4 |
| SCL | A5 |
(For Arduino Uno)
Relay Module
| Relay | Arduino |
|---|---|
| IN | 10 |
| VCC | 5V |
| GND | GND |
Buzzer
| Buzzer | Arduino |
|---|---|
| + | 11 |
| – | GND |
Important Solenoid Lock Note
Do NOT power the solenoid directly from Arduino.
Use:
- External 12V supply
- Relay module
- Flyback diode across solenoid
Typical setup:
- Relay switches 12V to solenoid lock
Arduino Code
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// LCD Address 0x27 is common
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Keypad setup
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);
// Relay and buzzer pins
const int relayPin = 10;
const int buzzerPin = 11;
// Password
String correctPassword = "1234";
String enteredPassword = "";
void setup()
{
pinMode(relayPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
digitalWrite(relayPin, LOW);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Door Lock");
lcd.setCursor(0, 1);
lcd.print("Enter Password");
delay(2000);
lcd.clear();
}
void loop()
{
char key = keypad.getKey();
if (key)
{
// Key press beep
tone(buzzerPin, 1000, 100);
// Display *
lcd.setCursor(enteredPassword.length(), 0);
lcd.print("*");
enteredPassword += key;
// Check password length
if (enteredPassword.length() == 4)
{
delay(300);
if (enteredPassword == correctPassword)
{
accessGranted();
}
else
{
accessDenied();
}
enteredPassword = "";
lcd.clear();
}
}
}
void accessGranted()
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Access Granted");
digitalWrite(relayPin, HIGH);
// Success beep
tone(buzzerPin, 1500, 200);
delay(300);
delay(5000);
digitalWrite(relayPin, LOW);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Door Locked");
delay(2000);
lcd.clear();
}
void accessDenied()
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Wrong Password");
// Alarm beeps
for (int i = 0; i < 3; i++)
{
tone(buzzerPin, 500, 300);
delay(400);
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Try Again");
delay(2000);
lcd.clear();
delay(2000);
lcd.print("Enter Password");
delay(2000);
}
How It Works
- User enters 4-digit password
- LCD shows
* - If password is correct:
- Relay activates
- Solenoid unlocks
- Door unlocks for 5 seconds
- If password is wrong:
- Buzzer alarm sounds
- LCD shows error
Please Note – Add a button to open Lock Manually.
Recommended Improvements
You can later add:
- RFID support
- Fingerprint sensor
- EEPROM password storage
- Change password option
- Wrong attempt counter
- GSM alerts
- ESP32 WiFi control
- Mobile app integration