Password Based Digital Door Lock Security System Using Arduino and Keypad
Hello friends! Welcome back to ElectroDuino. This blog is based on Password Based Digital Door Lock Security System Using Arduino, 4×4 Keypad module, and Servo motor. Here we will discuss Introduction to Password-Based Digital Door Lock Security System, Project Concept, Block Diagram, components required, circuit diagram, working principle, and Arduino code.
Introduction
Always we want a personal room, where nobody can’t enter this room without our permission. Nowadays security is the most important thing. So, we need to secure a room at our home and office for protecting our important accessories and documents. For that reason, in this project, we design the Password-Based Digital Door Lock Security System Using Arduino, 4×4 Keypad module, and a Servo motor. This Device is a digital Password or Pin code based Door Lock Security System. Which does not allow the user to open the Dore without entering the correct Password or Pincode.
Project Concept
In this project, we will enter a password using the keypad to open the door lock using servo motor. Password-Based Digital Door Lock Security System is consists of Arduino, 4 x 4 keypad module, servo motor, LCD display, and two switches. The Arduino is the brain of the project, that controls the whole system. Here we will use Arduino nano but you can choose any other version of the Arduino board which is based on the ATmega328. The 4X4 Keypad module is used to type the password or pin. Open button and close buttons are used to open and close the door lock from inside the room. The servo motor is used to push (lock) or pull (unlock) the latch on the door. The LCD display is used to show the message to the user. The buzzer is used for indications.
Block diagram
Component Required
Components Name | Quantity |
Arduino Nano | 1 |
4 x 4 matrix keypad | 1 |
SG90 Servo motor | 1 |
16 x 2 LCD Display | 1 |
Buzzer | 1 |
Push Button Switch | 2 |
1k Resistor | 2 |
9 Volt Power Supply | 1 |
Connecting wires | As per required in the circuit diagram |
We need to download the KeyPad library: CLICK
Circuit Diagram of Digital Door Lock Security System Using Arduino, 4×4 Keypad module, and Servo motor

Circuit Wiring
Components Pin | Arduino pin |
SG90 Servo motor Vcc, LCD Display (Vdd, LED +), Push Button 1 terminal-1 Push Button 2 terminal-1 | Arduino 5V Pin |
SG90 Servo motor GND, LCD Display (Vss, Rw, LED -) pin, Buzzer terminal-2 | GND (ground) Pin |
Push Button 1 terminal-3 and Push Button 2 terminal-3 | Both are connected to GND (ground) Pin through 1k resistor |
4 x 4 Keypad module R1, R2, R3, R4, C1, C2, C3, and C4 Pins | Respectively Digital Pin “D2”, “D3”, “D4”, “D5”, “D6”, “D7”, “D8” and “D9”. |
LCD Display RS, E, D4, D5, D6, D7 | Respectively Analog Pin “A0”, “A1”, “A2”, “A3”, “A4”, “A5” |
LCD Display V0 pin | 10k Potentiometer Signal pin, Potentiometer one pin is connected to 5V and another pin is connected to GND(ground) |
SG90 Servo motor PWM pin | Digital Pin “D10” |
Push Button 1 and Push Button 2 data pins are the junction point of the both button’s terminal-2 and resistor | Respectively Digital Pin “D12”, and “D11” |
Buzzer terminal-1 | Digital Pin “D13” |
9v Power Supply positive (+) terminal | Connected to VIN Pin through a Slide Switch for external DC Power supply to operating Arduino. |
9v Power Supply negative (+) terminal | GND (ground) Pin |
Working of Password-Based Door Lock Security System
Password-Based Door Lock Security System’s working principle is very simple. First of all, we must need to have defined a Password or Pin code in the Arduino code. Here the predefined Pin code is ” 2306 “. Also, define two keypad letters button one is “Enter button” to submit the password or pin code and another one is the “Close button” to lock the Door. Here the “Enter button” is Keypad letters “D” and the “Close button” is Keypad letters “C”.
When we enter a password and submit it using the “Enter button” in the Keypad module. Then Arduino read this password or pin, and match it with the predefined password stored in the Arduino. If the password or pin is matched then the LCD display will show “WELCOME ELECTRODUINO” massage and buzzer make a sound for 1 second. Then Arduino sends a command to the Servo motor to move the shaft at the 180-degree position, now the door is unlocked. When we will press the button “C” then Arduino sends a command to Servo motor to move the shaft at the 90-degree position, now the door is again locked. The LCD display will show “DOOR CLOSE” massage and buzzer make a sound for 1 second.
This circuit is included two push button switches. These are used to open and close the door lock from inside the room. The Pushbutton 1 is used to open (unlock) the door lock and The Pushbutton 2 is used to close (lock) the door lock. Pushbutton 1 and Pushbutton 2 both switch’s terminal 3 are connected to ground through the 1k pulldown resistor for getting stable input. When we will press the “Pushbutton1 ” then Arduino reads the data and sends a command to Servo motor to move the shaft at the 180-degree position, now the door is unlocked. The buzzer makes the sound for 1 second. When we will press the “Pushbutton2 ” then Arduino reads the data and sends a command to Servo motor to move the shaft at the 90-degree position, now the door is again locked. The buzzer makes the sound for 1 second.
Arduino Code for Password-Based Door Lock Security System
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | //LCD config #include <LiquidCrystal.h> LiquidCrystal lcd(A0, A1, A2, A3, A4, A5); #include <Servo.h> #include <Keypad.h> //Variables int Lock = 90; //min servo angle (set yours) int Unlock = 180; //Max servo angle (set yours) int character = 0; int activated =0; char Str[16] = {' ', ' ', ' ', ' ', ' ', ' ', '-', '*', '*', '*', ' ', ' ', ' ', ' ', ' ', ' '}; //Pins Servo myservo; int buzzer = 13; //pin for the buzzer beep int Emergency_open = 12; //pin to inside emergency_open int Close_Button = 11; //pin to inside Close_Button //Keypad config const byte ROWS = 4; //four rows const byte COLS = 4; //four columns //define the cymbols on the buttons of the keypads char hexaKeys[ROWS][COLS] = { {'1','4','7','*'}, {'2','5','8','0'}, {'3','6','9','#'}, {'A','B','C','D'} }; byte rowPins[ROWS] = {2, 3, 4, 5}; //connect to the row pinouts of the keypad byte colPins[COLS] = {6, 7, 8, 6}; //connect to the column pinouts of the keypad //initialize an instance of class NewKeypad Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); void setup(){ myservo.attach(10); //attach the servo to pin D10 pinMode(buzzer,OUTPUT); pinMode(Emergency_open,INPUT); pinMode(Close_Button,INPUT); //Init the screen and print the first text lcd.begin(16, 2); lcd.clear(); lcd.print(" PASSWORD"); lcd.setCursor(0,1); lcd.print(" -*** "); //put the servo in the close position first myservo.write(Lock); } void loop(){ ///////////////EMERGENCY OPEN/CLOSE///////// if (digitalRead(Emergency_open)) { myservo.write(Unlock); lcd.clear(); lcd.setCursor(2,0); lcd.print("INSIDE OPEN"); activated = 2; analogWrite(buzzer,240); delay(250); analogWrite(buzzer,200); delay(250); analogWrite(buzzer,180); delay(250); analogWrite(buzzer,250); delay(250); analogWrite(buzzer,LOW); lcd.clear(); lcd.setCursor(0,0); lcd.print(" WELLCOME "); lcd.setCursor(0,1); lcd.print(" ELECTRODUINO "); lcd.clear(); lcd.setCursor(3,0); lcd.print("DOOR OPEN"); lcd.setCursor(2,1); lcd.print("ELECTRODUINO"); delay(500); } if (digitalRead(Close_Button)) { myservo.write(Lock); activated = 0; character=0; Str[6]= '-'; Str[7]= '*'; Str[8]= '*'; Str[9]= '*'; Str[10]= ' '; lcd.clear(); lcd.setCursor(0,0); lcd.print(" PASSWORD"); lcd.setCursor(0,1); lcd.print(Str); } ///////////////KEYPAD OPEN/CLOSE//////////// char customKey = customKeypad.getKey(); //this function reads the presed key if (customKey){ if (character ==0) { Serial.println(customKey); Str[6]= customKey; lcd.clear(); lcd.setCursor(0,0); lcd.print(" PASSWORD"); lcd.setCursor(0,1); lcd.print(Str); } if (character ==1) { Serial.println(customKey); Str[7]= customKey; lcd.clear(); lcd.setCursor(0,0); lcd.print(" PASSWORD"); lcd.setCursor(0,1); lcd.print(Str); } if (character ==2) { Serial.println(customKey); Str[8]= customKey; lcd.clear(); lcd.setCursor(0,0); lcd.print(" PASSWORD"); lcd.setCursor(0,1); lcd.print(Str); } if (character ==3) { Serial.println(customKey); Str[9]= customKey; lcd.clear(); lcd.setCursor(0,0); lcd.print(" PASSWORD"); lcd.setCursor(0,1); lcd.print(Str); } if (character ==4) { Serial.println(customKey); Str[10]= customKey; activated=1; } character=character+1; } if (activated == 1) { /*Change your password below!!! Change each of Str[6], Str[7], Str[8], Str[9]*/ if(Str[10]='D' && character==5 && Str[6]=='2' && Str[7]=='3' && Str[8]=='0' && Str[9]=='6' ) { myservo.write(Unlock); lcd.clear(); lcd.setCursor(4,0); lcd.print("ACCEPTED"); activated = 2; analogWrite(buzzer,240); delay(250); analogWrite(buzzer,200); delay(250); analogWrite(buzzer,180); delay(250); analogWrite(buzzer,250); delay(250); analogWrite(buzzer,LOW); delay(1000); lcd.clear(); lcd.setCursor(4,0); lcd.print("WELLCOME"); delay(500); lcd.setCursor(2,1); lcd.print("ELECTRODUINO"); delay(1000); lcd.clear(); lcd.setCursor(3,0); lcd.print("DOOR OPEN"); lcd.setCursor(2,1); lcd.print("ELECTRODUINO"); } else { lcd.clear(); lcd.setCursor(1,0); lcd.print("PASSWORD ERROR"); lcd.setCursor(3,1); lcd.print("TRY AGAIN"); analogWrite(buzzer,150); delay(3000); analogWrite(buzzer,LOW); character=0; Str[6]= '-'; Str[7]= '*'; Str[8]= '*'; Str[9]= '*'; Str[10]= ' '; activated = 0; lcd.clear(); lcd.setCursor(4,0); lcd.print("PASSWORD"); lcd.setCursor(0,1); lcd.print(Str); } } if (activated == 2) { if(customKey == 'C' ) { myservo.write(Lock); activated = 0; character=0; Str[6]= '-'; Str[7]= '*'; Str[8]= '*'; Str[9]= '*'; Str[10]= ' '; lcd.clear(); lcd.setCursor(0,0); lcd.print(" PASSWORD"); lcd.setCursor(0,1); lcd.print(Str); } } } |