Arduino UNO-Based Smart Door Lock System with Keypad and LCD Display
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is a door lock system that uses an Arduino UNO microcontroller to control a servo motor, a 16x2 I2C LCD, a 4x4 membrane matrix keypad, and a buzzer. The system allows users to enter a password via the keypad, which is then evaluated by the Arduino. If the password is correct, the servo motor unlocks the door, and the LCD displays a message. If the password is incorrect, the buzzer sounds an alert, and the LCD prompts the user to try again.
Component List
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
4x4 Membrane Matrix Keypad
- Description: A keypad with 4 rows and 4 columns.
- Pins: R1, R2, R3, R4, C1, C2, C3, C4
Servo
- Description: A servo motor used to lock and unlock the door.
- Pins: gnd, vcc, pulse
16x2 I2C LCD
- Description: A 16x2 character LCD with I2C interface.
- Pins: GND, VCC, SDA, SCL
Buzzer
- Description: A piezoelectric buzzer used for audio alerts.
- Pins: PIN, GND
Wiring Details
Arduino UNO
- 3.3V connected to Servo vcc
- 5V connected to 16x2 I2C LCD VCC
- GND connected to:
- 16x2 I2C LCD GND
- Servo gnd
- Buzzer GND
- A4 connected to 16x2 I2C LCD SDA
- A5 connected to 16x2 I2C LCD SCL
- D11 connected to Buzzer PIN
- D10 connected to Servo pulse
- D9 connected to 4x4 Membrane Matrix Keypad R1
- D8 connected to 4x4 Membrane Matrix Keypad R2
- D7 connected to 4x4 Membrane Matrix Keypad R3
- D6 connected to 4x4 Membrane Matrix Keypad R4
- D5 connected to 4x4 Membrane Matrix Keypad C1
- D4 connected to 4x4 Membrane Matrix Keypad C2
- D3 connected to 4x4 Membrane Matrix Keypad C3
- D2 connected to 4x4 Membrane Matrix Keypad C4
4x4 Membrane Matrix Keypad
- R1 connected to Arduino UNO D9
- R2 connected to Arduino UNO D8
- R3 connected to Arduino UNO D7
- R4 connected to Arduino UNO D6
- C1 connected to Arduino UNO D5
- C2 connected to Arduino UNO D4
- C3 connected to Arduino UNO D3
- C4 connected to Arduino UNO D2
Servo
- vcc connected to Arduino UNO 3.3V
- gnd connected to Arduino UNO GND
- pulse connected to Arduino UNO D10
16x2 I2C LCD
- VCC connected to Arduino UNO 5V
- GND connected to Arduino UNO GND
- SDA connected to Arduino UNO A4
- SCL connected to Arduino UNO A5
Buzzer
- PIN connected to Arduino UNO D11
- GND connected to Arduino UNO GND
Code Documentation
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <Password.h>
#define buzzer 11
Servo servo;
LiquidCrystal_I2C lcd(0x27, 16, 2);
String newPasswordString; //hold the new password
char newPassword[6]; //charater string of newPasswordString
byte a = 5;
bool value = true;
Password password = Password("0123"); //Enter your password
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'},
};
byte rowPins[ROWS] = {2, 3, 4, 5};
byte colPins[COLS] = {6, 7, 8, 9};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
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");
char key = keypad.getKey();
if (key != NO_KEY) {
delay(60);
if (key == 'C') {
resetPassword();
} else if (key == 'D') {
if (value == true) {
doorlocked();
value = false;
} else if (value == false) {
dooropen();
value = true;
}
} else {
processNumberKey(key);
}
}
}
void processNumberKey(char key) {
lcd.setCursor(a, 1);
lcd.print("*");
a++;
if (a == 11) {
a = 5;
}
currentPasswordLength++;
password.append(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 {
digitalWrite(buzzer, HIGH);
delay(200);
digitalWrite(buzzer, LOW);
delay(200);
digitalWrite(buzzer, HIGH);
delay(200);
digitalWrite(buzzer, LOW);
delay(200);
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();
a = 5;
}
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 {
digitalWrite(buzzer, HIGH);
delay(200);
digitalWrite(buzzer, LOW);
delay(200);
digitalWrite(buzzer, HIGH);
delay(200);
digitalWrite(buzzer, LOW);
delay(200);
digitalWrite(buzzer, HIGH);
delay(200);
digitalWrite(buzzer, LOW);
delay(200);
digitalWrite(buzzer, HIGH);
delay(200);
digitalWrite(buzzer, LOW);
delay(200);
lcd.setCursor(0, 0);
lcd.print("WRONG PASSWORD!");
lcd.setCursor(0, 1);
lcd.print