Password Based Door Lock Security System Using Arduino & Keypad
DIY Password Based Door Lock Security System Using Arduino, 4x4 Keypad, LCD Display, Servo Motor, Buzzer with Arduino C++ Code & Circuit
- Suitable forB.Tech/Diploma Arduino students
- Build time1-2 weeks
- LevelBeginner
- Available atAjvika Labs, Kakinada
About this project
Overview
In this project, we will make a
Password-Based Door Lock Security System
using Arduino, a keypad, a servo motor, an LCD, and a buzzer. With rising concerns about security, this digital password-based lock can be an effective way to safeguard homes or lockers.
This system will unlock the door only when the
correct password
is entered. It’s a simple and effective way to keep your home or valuables safe. Earlier we built,
RFID Security System
and also
Biometric Security Lock
using Arduino.
In Password Based Door Lock Security System, the Arduino controls the whole system. The keypad is used to enter the password, and the LCD shows messages like “
Enter Password
” or “
Access Granted
.” The buzzer makes sounds to give feedback, like when a button is pressed or the password is wrong. If the correct password is entered, the servo motor
unlocks the door
and locks it again after a few seconds. This project is easy to build and very useful for security.
Bill of Materials
Follows are the list of components that you need for this project. You can purchase all these components from Amazon at affordable price.
S.N.
Components
Quantity
Purchase Links
Arduino Nano Board
Amazon
AliExpress
4x4 Keypad Matrix
Amazon
AliExpress
16x2 LCD Display
Amazon
AliExpress
Potentiometer 10K
Amazon
AliExpress
SG90 Servo Motor
Amazon
AliExpress
Buzzer 5V
Amazon
AliExpress
LED Red
Amazon
AliExpress
LED Green
Amazon
AliExpress
Resistor 330 ohms
Amazon
AliExpress
Connecting Wires
Amazon
AliExpress
Breadboard
Amazon
AliExpress
Circuit: Password Based Door Lock Security System using Arduino
The Password-Based Door Lock Security System uses an Arduino Nano, a 4×4 keypad, a servo motor, an LCD, LEDs, and a buzzer.
Fig: Circuit of Password Based Door Lock Security System using Arduino
Below is an explanation of the connections:
Arduino Nano
:
The Nano acts as the brain of the system. It processes inputs from the keypad, compares passwords, and controls the servo motor, LCD, LEDs, and buzzer.
Keypad
:
The 4×4 keypad is used for entering passwords. It is connected to:
Row Pins (A0, A1, A2, A3)
of the Nano.
Column Pins (A4, A5, 9, 10)
of the Nano.
Servo Motor
:
The servo motor is responsible for locking and unlocking the door.
It is connected to
pin 8
of the Nano.
It receives commands from the Nano to rotate and unlock/lock the door.
LCD (16×2)
:
The LCD is used to display instructions and feedback messages like “Enter Password” or “Access Granted”. Its pins
, and
are connected to GND. The LCD pins
and
are connected to 5V of Arduino. A 10K potentiometer is connected to pin
of the LCD to control the LCD contrast.
The data pins of the LCD are connected as follows:
RS → pin 2
E → pin 3
D4 → pin 4
D5 → pin 5
D6 → pin 6
D7 → pin 7
Buzzer
:
The buzzer provides sound feedback for various actions like button presses, correct password, or incorrect password alerts.
It is connected to
pin 11
of the Nano.
Red LED
:
The red LED indicates incorrect password attempts.
It is connected to
pin 12
with a 330-ohms current-limiting resistor.
Green LED
:
The green LED indicates a successful password entry and access granted.
It is connected to
pin 13
with a 330-ohms current-limiting resistor.
The Arduino Nano is powered via USB or an external 5V supply. The components (servo, buzzer, LEDs) share a common ground with the Arduino Nano.
Fig: Breadboard Assembly of Password Security System Project
You can connect all the components on breadboard using jumper wires as per the circuit diagram above.
Source Code/Program
Here is the C++ Arduino code for our project. This code implements a
Password-Based Door Lock System
using an Arduino Nano, a 4×4 keypad, an LCD, a servo motor, a buzzer, and two LEDs.
The system allows users to set a password during the first boot, enter the password to unlock the door, and change the password by entering a master password. The keypad handles user input, while the LCD provides feedback such as “
Enter Password
” or “
Access Granted
.” The servo motor unlocks the door on a correct password, and the system relocks the door after a 10-second countdown.
The buzzer provides sound feedback for button presses,
incorrect passwords
, and access granted. The red LED indicates incorrect password attempts, while the green LED lights up on a successful password entry.
In the current code, the master password is set as “1234”. You may set your own Master password. The code also has a very well written comments which makes it very easy to understand each line of the code. Before uploading the code, please add the
Keypad Library
to the Arduino IDE to avoid compilation error.
Copy the following code and paste it on your Arduino IDE editor window.
#include <Keypad.h>
#include <LiquidCrystal.h>
#include <Servo.h>
// Define pins for various components
#define SERVO_PIN 8 // Servo motor pin
#define RED_LED_PIN 12 // Red LED pin (for incorrect password indication)
#define GREEN_LED_PIN 13 // Green LED pin (for access granted indication)
#define BUZZER_PIN 11 // Buzzer pin (for sound feedback)
Servo
myservo
;
// Servo object
LiquidCrystal
lcd
(
)
;
// LCD object with defined pins
// Keypad configuration
const
byte
rows
=
cols
=
;
// Keypad dimensions (4x4)
char
keys
[
rows
]
[
cols
]
=
{
// Keypad layout
{
'1'
'2'
'3'
'A'
}
{
'4'
'5'
'6'
'B'
}
{
'7'
'8'
'9'
'C'
}
{
'*'
'0'
'#'
'D'
}
}
;
byte
rowPins
[
rows
]
=
{
A0
A1
A2
A3
}
;
// Row pins connected to Arduino
byte
colPins
[
cols
]
=
{
A4
A5
}
;
// Column pins connected to Arduino
Keypad
keypad
=
Keypad
(
makeKeymap
(
keys
)
rowPins
colPins
rows
cols
)
;
// Keypad object
// Passwords
char
masterPassword
[
]
=
"1234"
;
// Master password for password change
char
savedPassword
[
]
=
""
;
// User-set password
char
enteredPassword
[
]
;
// Buffer for entering a password
int
currentPosition
=
;
// Tracks the number of entered digits
int
invalidCount
=
;
// Counts incorrect password attempts
// Flags for different modes
bool
isFirstBoot
=
true
;
// Indicates if it's the first time setting the password
bool
isSettingPassword
=
false
;
// Indicates if the system is in password setup mode
bool
isCheckingMaster
=
false
;
// Indicates if the system is verifying the master password
void
setup
(
)
{
lcd
begin
(
)
;
// Initialize LCD
pinMode
(
RED_LED_PIN
OUTPUT
)
;
// Set LED pins as outputs
pinMode
(
GREEN_LED_PIN
OUTPUT
)
;
pinMode
(
BUZZER_PIN
OUTPUT
)
;
// Set buzzer pin as output
myservo
attach
(
SERVO_PIN
)
;
// Attach servo to the defined pin
myservo
write
(
)
;
// Initial servo position (locked)
Serial
begin
(
9600
)
;
// Begin serial communication (for debugging)
// First boot behavior: prompt user to set the password
if
(
isFirstBoot
)
{
lcd
(
"Set Password:"
)
;
// Show setup message on LCD
isSettingPa
In this project, we will make a
Password-Based Door Lock Security System
using Arduino, a keypad, a servo motor, an LCD, and a buzzer. With rising concerns about security, this digital password-based lock can be an effective way to safeguard homes or lockers.
This system will unlock the door only when the
correct password
is entered. It’s a simple and effective way to keep your home or valuables safe. Earlier we built,
RFID Security System
and also
Biometric Security Lock
using Arduino.
In Password Based Door Lock Security System, the Arduino controls the whole system. The keypad is used to enter the password, and the LCD shows messages like “
Enter Password
” or “
Access Granted
.” The buzzer makes sounds to give feedback, like when a button is pressed or the password is wrong. If the correct password is entered, the servo motor
unlocks the door
and locks it again after a few seconds. This project is easy to build and very useful for security.
Bill of Materials
Follows are the list of components that you need for this project. You can purchase all these components from Amazon at affordable price.
S.N.
Components
Quantity
Purchase Links
Arduino Nano Board
Amazon
AliExpress
4x4 Keypad Matrix
Amazon
AliExpress
16x2 LCD Display
Amazon
AliExpress
Potentiometer 10K
Amazon
AliExpress
SG90 Servo Motor
Amazon
AliExpress
Buzzer 5V
Amazon
AliExpress
LED Red
Amazon
AliExpress
LED Green
Amazon
AliExpress
Resistor 330 ohms
Amazon
AliExpress
Connecting Wires
Amazon
AliExpress
Breadboard
Amazon
AliExpress
Circuit: Password Based Door Lock Security System using Arduino
The Password-Based Door Lock Security System uses an Arduino Nano, a 4×4 keypad, a servo motor, an LCD, LEDs, and a buzzer.
Fig: Circuit of Password Based Door Lock Security System using Arduino
Below is an explanation of the connections:
Arduino Nano
:
The Nano acts as the brain of the system. It processes inputs from the keypad, compares passwords, and controls the servo motor, LCD, LEDs, and buzzer.
Keypad
:
The 4×4 keypad is used for entering passwords. It is connected to:
Row Pins (A0, A1, A2, A3)
of the Nano.
Column Pins (A4, A5, 9, 10)
of the Nano.
Servo Motor
:
The servo motor is responsible for locking and unlocking the door.
It is connected to
pin 8
of the Nano.
It receives commands from the Nano to rotate and unlock/lock the door.
LCD (16×2)
:
The LCD is used to display instructions and feedback messages like “Enter Password” or “Access Granted”. Its pins
, and
are connected to GND. The LCD pins
and
are connected to 5V of Arduino. A 10K potentiometer is connected to pin
of the LCD to control the LCD contrast.
The data pins of the LCD are connected as follows:
RS → pin 2
E → pin 3
D4 → pin 4
D5 → pin 5
D6 → pin 6
D7 → pin 7
Buzzer
:
The buzzer provides sound feedback for various actions like button presses, correct password, or incorrect password alerts.
It is connected to
pin 11
of the Nano.
Red LED
:
The red LED indicates incorrect password attempts.
It is connected to
pin 12
with a 330-ohms current-limiting resistor.
Green LED
:
The green LED indicates a successful password entry and access granted.
It is connected to
pin 13
with a 330-ohms current-limiting resistor.
The Arduino Nano is powered via USB or an external 5V supply. The components (servo, buzzer, LEDs) share a common ground with the Arduino Nano.
Fig: Breadboard Assembly of Password Security System Project
You can connect all the components on breadboard using jumper wires as per the circuit diagram above.
Source Code/Program
Here is the C++ Arduino code for our project. This code implements a
Password-Based Door Lock System
using an Arduino Nano, a 4×4 keypad, an LCD, a servo motor, a buzzer, and two LEDs.
The system allows users to set a password during the first boot, enter the password to unlock the door, and change the password by entering a master password. The keypad handles user input, while the LCD provides feedback such as “
Enter Password
” or “
Access Granted
.” The servo motor unlocks the door on a correct password, and the system relocks the door after a 10-second countdown.
The buzzer provides sound feedback for button presses,
incorrect passwords
, and access granted. The red LED indicates incorrect password attempts, while the green LED lights up on a successful password entry.
In the current code, the master password is set as “1234”. You may set your own Master password. The code also has a very well written comments which makes it very easy to understand each line of the code. Before uploading the code, please add the
Keypad Library
to the Arduino IDE to avoid compilation error.
Copy the following code and paste it on your Arduino IDE editor window.
#include <Keypad.h>
#include <LiquidCrystal.h>
#include <Servo.h>
// Define pins for various components
#define SERVO_PIN 8 // Servo motor pin
#define RED_LED_PIN 12 // Red LED pin (for incorrect password indication)
#define GREEN_LED_PIN 13 // Green LED pin (for access granted indication)
#define BUZZER_PIN 11 // Buzzer pin (for sound feedback)
Servo
myservo
;
// Servo object
LiquidCrystal
lcd
(
)
;
// LCD object with defined pins
// Keypad configuration
const
byte
rows
=
cols
=
;
// Keypad dimensions (4x4)
char
keys
[
rows
]
[
cols
]
=
{
// Keypad layout
{
'1'
'2'
'3'
'A'
}
{
'4'
'5'
'6'
'B'
}
{
'7'
'8'
'9'
'C'
}
{
'*'
'0'
'#'
'D'
}
}
;
byte
rowPins
[
rows
]
=
{
A0
A1
A2
A3
}
;
// Row pins connected to Arduino
byte
colPins
[
cols
]
=
{
A4
A5
}
;
// Column pins connected to Arduino
Keypad
keypad
=
Keypad
(
makeKeymap
(
keys
)
rowPins
colPins
rows
cols
)
;
// Keypad object
// Passwords
char
masterPassword
[
]
=
"1234"
;
// Master password for password change
char
savedPassword
[
]
=
""
;
// User-set password
char
enteredPassword
[
]
;
// Buffer for entering a password
int
currentPosition
=
;
// Tracks the number of entered digits
int
invalidCount
=
;
// Counts incorrect password attempts
// Flags for different modes
bool
isFirstBoot
=
true
;
// Indicates if it's the first time setting the password
bool
isSettingPassword
=
false
;
// Indicates if the system is in password setup mode
bool
isCheckingMaster
=
false
;
// Indicates if the system is verifying the master password
void
setup
(
)
{
lcd
begin
(
)
;
// Initialize LCD
pinMode
(
RED_LED_PIN
OUTPUT
)
;
// Set LED pins as outputs
pinMode
(
GREEN_LED_PIN
OUTPUT
)
;
pinMode
(
BUZZER_PIN
OUTPUT
)
;
// Set buzzer pin as output
myservo
attach
(
SERVO_PIN
)
;
// Attach servo to the defined pin
myservo
write
(
)
;
// Initial servo position (locked)
Serial
begin
(
9600
)
;
// Begin serial communication (for debugging)
// First boot behavior: prompt user to set the password
if
(
isFirstBoot
)
{
lcd
(
"Set Password:"
)
;
// Show setup message on LCD
isSettingPa
Technologies used
Hardware components
- Arduino
- RFID
- Servo
- Servo Motor
Software & tools
- Arduino IDE
What you get
- Working project / hardware kit, tested before delivery
- Complete source code with explanation
- Project demo and guidance for your viva
- Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed.
Payment is in two parts:
• 50% advance to start the project
• Remaining 50% before delivery
Note:
• Documentation and PPT are not included by default
• If you need documentation/PPT, it can be arranged for extra time and cost
We'll confirm the exact timeline and cost with you after reviewing your requirements.