Mini project Arduino Door Lock
Mini project Arduino Door Lock
Lab code & Name : 21ECO106J- Embedded system design using Arduino
Reg. No
Mark split up RA2211051010012
1
PASSWORD BASED DOOR LOCK SYSTEM
OBJECTIVE:
The primary goal of this project is to create a password-based door lock system using an
Arduino Uno. The lock system allows users to secure doors with an existing locking
mechanism by entering a user-defined password on a 4x4 hex keypad. The system employs
a servo motor and wire contraption to actuate the lock, making it compatible with existing
door locks, rather than relying solely on new locks.
ABSTRACT:
This password-based door lock system using Arduino Uno is designed to secure doors
while being cost-effective and adaptable to existing locks. The system operates with a 4x4
hex keypad for password input and a servo motor for locking and unlocking, replacing the
need for a solenoid lock. One key advantage of this system is its ability to work with
existing door mechanisms, offering flexibility for various applications.
Additionally, the integrated 5V buzzer provides audio feedback to indicate the opening and
closing of the door, enhancing user awareness. The system remains inactive when not in
use, conserving energy and enhancing battery life. It also allows users to set and modify
passwords as needed. Simple to assemble, the system provides an affordable solution for
securing doors in homes, offices, and other locations.
INTRODUCTION:
Security is a major concern in both residential and commercial settings, and electronic
locks are one of the most efficient ways to control access. Market solutions for electronic
locks tend to be costly, so this project demonstrates how to build a low-cost,
password-based door lock system using Arduino. By using an Arduino Uno as the
processing unit, a 4x4 keypad for input, and a servo motor for actuation, this system offers
a secure, reliable, and customizable solution for door locking mechanisms.
HARDWARE REQUIREMENT/DESCRIPTION:
Arduino Uno: Acts as the processing unit that controls the entire lock system. It receives
input from the keypad and controls the servo motor based on the correct password.
4x4 Hex Keypad: A matrix keypad used for entering the password. It is connected to the
Arduino via 8 pins to detect which button is pressed.
Servo Motor: Responsible for locking and unlocking the door. A wire contraption
connected to the servo motor pulls or releases the existing lock's mechanism, offering a
more adaptable solution than using a solenoid lock.
I2C Module: Facilitates communication between microcontrollers and various peripherals,
allowing for efficient data transfer in a multi-device environment.
16×2 LCD : Displays the status of the system, such as "Enter Password" or "Access
Granted."
Jumper Wires and Breadboard: Connect the components together without the need for
permanent soldering.
5V Buzzer: Provides audio feedback for the lock system, signaling events such as
incorrect password entries or successful access with sound notifications.
2
CIRCUIT/COMPONENT SPECIFICATIONS:
Arduino Uno: 14 digital I/O pins, 6 analog input pins, operating voltage 5V.
SG92R Servo Motor: 4.8-6V operation, typically moves 0-180 degrees, torque of 2.5
kg·cm at 6V, suitable for lightweight applications.
4x4 Keypad: Consists of 16 buttons arranged in a 4-row, 4-column matrix, operates by
short-circuiting corresponding row and column pins upon pressing a button.
I2C Module: Operates at 3.3V to 5V, facilitating multi-device communication with up to
400 kHz speed.
5V Buzzer: Active buzzer operating at 5V, consuming 20-30 mA with sound output
around 70-100 dB.
16x2 LCD: Alphanumeric display showing system prompts.
CIRCUIT DIAGRAM:
3
DESIGN ISSUES:
● Ensuring correct detection of password inputs from the keypad is critical for system
functionality.
● Handling incorrect password attempts is necessary to prevent unauthorized access.
● Managing potential power fluctuations is important to maintain system stability.
● The servo motor must be properly powered and calibrated to ensure smooth
operation of the locking mechanism.
● The wire contraption needs to be robust and correctly aligned to avoid slippage.
● Preventing mechanical failure when actuating existing locks is essential for reliable
performance.
APPROACH/METHODOLOGY:
Hardware Assembly:
● Connect the Arduino Uno to the 4x4 hex keypad, servo motor, 5V buzzer, and
optional components such as a 16×2 LCD.
● Ensure the servo motor is positioned to manipulate the lock mechanism using a
wire contraption.
● Integrate the buzzer to signal audio notifications for door opening and closing
events.
Code Implementation:
● Write the Arduino code to manage inputs from the keypad, store the password, and
control the servo motor and buzzer based on password correctness.
● Implement a simple if-else structure to compare the entered password with the
stored one, activating the servo motor and buzzer upon correct entry.
● Include functions for password reset, automatic locking after a set duration, and
audio notifications for door status changes.
● Test the system by entering various passwords and observe the motor's response
and buzzer sounds for successful or failed attempts.
● Debug any issues related to keypad inputs, motor actuation, or buzzer functionality.
● Ensure the system correctly locks the door automatically and responds to password
reset requests.
● Upon system activation, the user is prompted to enter a password using the keypad.
● The Arduino compares the entered password to the stored one. If correct, the servo
motor unlocks the door, and the buzzer sounds a notification.
● After a brief delay or upon entering a specific command, the system locks the door
again, signaling with the buzzer.
● Users can reset the password as needed, enhancing the system’s flexibility and
security.
This structured approach ensures a reliable and user-friendly password-based door locking
system, integrating both hardware and software components effectively.
4
CODE:
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#ifndef PASSWORD_H
#define PASSWORD_H
class Password {
public:
Password(char* pass);
void set(char* pass);
bool is(char* pass);
bool append(char character);
void reset();
bool evaluate();
private:
char* target;
char guess[MAX_PASSWORD_LENGTH];
byte currentIndex;
};
#endif
Password::Password(char* pass) {
set(pass);
reset();
}
5
bool Password::append(char character) {
if (currentIndex + 1 == MAX_PASSWORD_LENGTH) {
return false;
} else {
guess[currentIndex++] = character;
guess[currentIndex] = STRING_TERMINATOR; // ensure a valid C string
}
return true;
}
void Password::reset() {
currentIndex = 0;
guess[currentIndex] = STRING_TERMINATOR;
}
bool Password::evaluate() {
char pass = target[0];
char guessed = guess[0];
6
#define buzzer 11
Servo servo;
LiquidCrystal_I2C lcd(0x27, 16, 2);
byte maxPasswordLength = 6;
byte currentPasswordLength = 0;
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
char keys[ROWS][COLS] = {
{'D', 'C', 'B', 'A'},
{'#', '9', '6', '3'},
{'0', '8', '5', '2'},
{'*', '7', '4', '1'},
};
void setup() {
Serial.begin(9600);
pinMode(buzzer, OUTPUT);
servo.attach(10);
servo.write(50);
lcd.init();
lcd.backlight();
lcd.setCursor(3, 0);
lcd.print("WELCOME TO");
lcd.setCursor(0, 1);
lcd.print("DOOR LOCK SYSTEM");
delay(3000);
lcd.clear();
}
void loop() {
lcd.setCursor(1, 0);
lcd.print("ENTER PASSWORD");
7
if (key == 'C') {
resetPassword();
} else if (key == 'B') {
if (value == true) {
doorlocked();
value = false;
} else if (value == false) {
dooropen();
value = true;
}
} else {
processNumberKey(key);
}
}
}
if (currentPasswordLength == maxPasswordLength) {
doorlocked();
dooropen();
}
}
void dooropen() {
if (password.evaluate()) {
digitalWrite(buzzer, HIGH);
delay(300);
digitalWrite(buzzer, LOW);
servo.write(50);
delay(100);
lcd.setCursor(0, 0);
lcd.print("CORRECT PASSWORD");
lcd.setCursor(0, 1);
lcd.print("DOOR OPENED");
delay(2000);
lcd.clear();
a = 5;
} else {
for (int i = 0; i < 3; i++) {
digitalWrite(buzzer, HIGH);
delay(200);
digitalWrite(buzzer, LOW);
delay(200);
8
}
lcd.setCursor(0, 0);
lcd.print("WRONG PASSWORD!");
lcd.setCursor(0, 1);
lcd.print("PLEASE TRY AGAIN");
delay(2000);
lcd.clear();
}
resetPassword();
}
void resetPassword() {
password.reset();
currentPasswordLength = 0;
lcd.clear();
a = 5;
}
void doorlocked() {
if (password.evaluate()) {
digitalWrite(buzzer, HIGH);
delay(300);
digitalWrite(buzzer, LOW);
servo.write(110);
delay(100);
lcd.setCursor(0, 0);
lcd.print("CORRECT PASSWORD");
lcd.setCursor(2, 1);
lcd.print("DOOR LOCKED");
delay(2000);
lcd.clear();
a = 5;
} else {
for (int i = 0; i < 4; i++) {
digitalWrite(buzzer, HIGH);
delay(200);
digitalWrite(buzzer, LOW);
delay(200);
}
lcd.setCursor(0, 0);
lcd.print("WRONG PASSWORD!");
lcd.setCursor(0, 1);
lcd.print("PLEASE TRY AGAIN");
delay(2000);
lcd.clear();
}
resetPassword();
}
9
RESULTS:
CONCLUSIONS:
This project offers a cost-effective and flexible password-based door lock system using
Arduino, providing enhanced security and compatibility with existing locks.
REFERENCES:
1. https://simplecircuitslol.blogspot.com/2024/03/password-door-lock-using-tinkercad
.html
2. https://simplecircuitslol.blogspot.com/2024/03/circuit-diagram-keypad-lock.html
3. Monk, S. (2019). Programming Arduino: Getting Started with Sketches (2nd ed.).
McGraw-Hill Education.
4. Banzi, M., & Shiloh, M. (2020). Getting Started with Arduino: The Open Source
Electronics Prototyping Platform (4th ed.). Maker Media.
APPENDIX:
ARDUINO UNO:
The Arduino Uno typically uses a USB Type-A to USB Type-B cable, commonly known
as a printer cable, for connecting to a computer. This cable allows for both data transfer
and power supply to the board during programming and operation.
10
SERVO MOTOR:
Servo motor that precisely controls the locking mechanism of the door by turning at
specific angles. It offers a reliable solution for locking and unlocking, replacing traditional
solenoid locks.
5V BUZZER:
5V buzzer that provides audible alerts for system notifications, such as door opening and
closing events.
SOLDERING IRON :
A tool that heats up to melt solder, used to join electronic components to a circuit board.
11
SOLDERING WIRE:
A thin metal wire, often containing flux, used to create electrical connections between
components by melting with a soldering iron.
HOOKUP WIRE:
16 X 2 LCD:
A display module with two rows of 16 characters, often used to show data from
microcontrollers like Arduino.
12
JUMPER WIRES:
Pre-cut and pre-stripped wires with pin connectors used for quick connections on
breadboards or between components.
4X4 KEYPAD:
4x4 hex keypad used for entering passwords in the door lock system, allowing user input
through a matrix of buttons. It connects to the Arduino to detect which key is pressed,
facilitating secure access control.
I2C MODULE:
I2C module that enables seamless communication between the Arduino and multiple
peripherals. It allows for efficient data transfer over just two wires, simplifying
connections in multi-device setups.
13
PASSWORD BASED DOOR LOCK SYSTEM USING ARDUINO
14