Password Based Security System Using Arduino & Keypad
In this project, we will learn how to make the Password-Based Security System Using Arduino & Keypad. As thefts are increasing day by day security is becoming a major concern nowadays. So a digital code lock can secure your home or locker easily. It will open your door only when the right password is entered.
The circuit of this project is very simple which contains Arduino, keypad module, buzzer, Servo Motor, and LCD. Arduino controls the complete processes like taking a password from the keypad module, comparing passwords, driving buzzer, rotating servo motor, and sending status to the LCD display. The keypad is used for taking the password. The buzzer is used for indications. Servo motor is used for opening the gate while rotating and LCD is used for displaying status or messages on it.
You can check one of our previous security system project: RFID RC522 Based Security System
Components Required:
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 |
---|---|---|---|
1 | Arduino UNO Board | 1 | Amazon | AliExpress |
2 | 4x3 Keypad | 1 | Amazon | AliExpress |
3 | 16x2 LCD Display | 1 | Amazon | AliExpress |
4 | Potentiometer 10K | 1 | Amazon | AliExpress |
5 | SG90 Servo Motor | 1 | Amazon | AliExpress |
6 | Buzzer 5V | 1 | Amazon | AliExpress |
7 | Connecting Wires | 20 | Amazon | AliExpress |
8 | Breadboard | 1 | Amazon | AliExpress |
Circuit Diagram & Connections
The circuit or the schematic of Password Based Door Lock Security System is fairly simple. You can use the Fritzing Software to draw the schematic.
First of all, we will make a connection to the 4×3 Keypad. For connecting the keypad with the Arduino we are using digital pins D1 to D7. Connect all seven pins of the keypad to analog pins D1 ~ D7 of Arduino.
To connect the servo motor with the Arduino, use digital pin D9 of Arduino to output the PWM pin of the servo motor. Now connect the positive wire of the buzzer to the pin D10 of Arduino and the negative wire to the ground.
Now we will connect the 16×2 LCD to the Arduino.
1. Connect pin 1,3,5,16 of LCD to the GND.
2. Connect pin 2,15 of LCD to the VCC (5V).
3. Connect pin 4 of LCD to pin A0 of Arduino.
3. Connect pin 6 of LCD to pin A1 of Arduino.
3. Connect pin 11 of LCD to pin A2 of Arduino.
3. Connect pin 12 of LCD to pin A3 of Arduino.
3. Connect pin 13 of LCD to pin A4 of Arduino.
3. Connect pin 14 of LCD to pin A5 of Arduino.
Here is another version of the Schematic designed using EasyEDA software. The Arduino UNO Board is replaced by Arduino Nano Board.
Schematics, PCB & Gerber File + PCB Ordering Online
If you don’t want to assemble the circuit on breadboard and you want PCB for the project, then here is the PCB for you. The PCB Board for the project is designed using EasyEDA online Circuit Schematics & PCB designing tool. The front side and back side of the PCB is given below.
Now you can visit the PCBgogo official website by clicking here: https://www.pcbgogo.com/. So you will be directed to PCBgogo website. Register now to get 50$ coupon for new users
You can now upload the Gerber File to the Website and place an order. The PCB quality are of top class and brilliant. That is why most of the people trust PCBgogo for PCB & PCBA Services.
Working of Password Based Door Lock Security System
In this project, we have defined the default password “4567” in the Arduino. You can change it via coding. When we enter a password, it will match it with the password stored in the Arduino. If it is correct, then it will show ‘Access Granted, Welcome’ and then rotate the servo motor to 180 doors as the door is opened. It will then give 5 seconds time for entering via the door. Once 5 seconds is completed, the door will get locked automatically.
If the password is wrong, then it will show ‘Code Incorrect, Go Away’. The buzzer will also beep once when any key is pressed.
Source Code/Program
The code for Password Based Door Lock Security System Using Arduino & Keypad is given below. You can simply copy & paste the code using Arduino IDE. The simply compile it then finally upload it to the ATmega328 microcontroller.
Download the library for Keypad.h from below.
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 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
#include <Keypad.h> #include <LiquidCrystal.h> #include <Servo.h> Servo myservo; int pos=0; // LCD Connections LiquidCrystal lcd(A0,A1,A2,A3,A4,A5); const byte rows=4; const byte cols=3; char key[rows][cols]={ {'1','2','3'}, {'4','5','6'}, {'7','8','9'}, {'*','0','#'} }; byte rowPins[rows]={1,2,3,4}; byte colPins[cols]={5,6,7}; Keypad keypad= Keypad(makeKeymap(key),rowPins,colPins,rows,cols); char* password="4567"; int currentposition=0; int redled=10; int greenled=11; int buzz=8; int invalidcount=12; void setup() { displayscreen(); Serial.begin(9600); pinMode(redled, OUTPUT); pinMode(greenled, OUTPUT); pinMode(buzz, OUTPUT); myservo.attach(9); //SERVO ATTACHED// lcd.begin(16,2); } void loop() { if( currentposition==0) { displayscreen(); } int l ; char code=keypad.getKey(); if(code!=NO_KEY) { lcd.clear(); lcd.setCursor(0,0); lcd.print("PASSWORD:"); lcd.setCursor(7,1); lcd.print(" "); lcd.setCursor(7,1); for(l=0;l<=currentposition;++l) { lcd.print("*"); keypress(); } if (code==password[currentposition]) { ++currentposition; if(currentposition==4) { unlockdoor(); currentposition=0; } } else { ++invalidcount; incorrect(); currentposition=0; } if(invalidcount==5) { ++invalidcount; torture1(); } if(invalidcount==8) { torture2(); } } // LOOP ENDS!!!// } //********OPEN THE DOOR FUNCTION!!!!***********// void unlockdoor() { delay(900); lcd.setCursor(0,0); lcd.println(" "); lcd.setCursor(1,0); lcd.print("Access Granted"); lcd.setCursor(4,1); lcd.println("WELCOME!!"); lcd.setCursor(15,1); lcd.println(" "); lcd.setCursor(16,1); lcd.println(" "); lcd.setCursor(14,1); lcd.println(" "); lcd.setCursor(13,1); lcd.println(" "); unlockbuzz(); for(pos = 180; pos>=0; pos-=5) // goes from 180 degrees to 0 degrees { myservo.write(pos); // tell servo to go to position in variable 'pos' delay(5); // waits 15ms for the servo to reach the position } delay(2000); delay(1000); counterbeep(); delay(1000); for(pos = 0; pos <= 180; pos +=5) // goes from 0 degrees to 180 degrees { // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); currentposition=0; lcd.clear(); displayscreen(); } } //************WRONG CODE FUNCTION********// void incorrect() { delay(500); lcd.clear(); lcd.setCursor(1,0); lcd.print("CODE"); lcd.setCursor(6,0); lcd.print("INCORRECT"); lcd.setCursor(15,1); lcd.println(" "); lcd.setCursor(4,1); lcd.println("GET AWAY!!!"); lcd.setCursor(13,1); lcd.println(" "); Serial.println("CODE INCORRECT YOU ARE UNAUTHORIZED"); digitalWrite(redled, HIGH); digitalWrite(buzz, HIGH); delay(3000); lcd.clear(); digitalWrite(redled, LOW); digitalWrite(buzz,LOW); displayscreen(); } //************** CLEAR THE SCREEN!!!*************// void clearscreen() { lcd.setCursor(0,0); lcd.println(" "); lcd.setCursor(0,1); lcd.println(" "); lcd.setCursor(0,2); lcd.println(" "); lcd.setCursor(0,3); lcd.println(" "); } //**************KEYPRESS********************// void keypress() { digitalWrite(buzz, HIGH); delay(50); digitalWrite(buzz, LOW); } //********DISPALAY FUNCTION!!!*************// void displayscreen() { lcd.setCursor(0,0); lcd.println("*ENTER THE CODE*"); lcd.setCursor(1 ,1); lcd.println("TO _/_ (OPEN)!!"); } //*************** ARM SERVO***********// void armservo() { for (pos=180;pos<=180;pos+=50) { myservo.write(pos); delay(5); } delay(5000); for(pos=180;pos>=0;pos-=50) { myservo.write(pos); } } //**********UNLOCK BUZZ*************// void unlockbuzz() { digitalWrite(buzz, HIGH); delay(80); digitalWrite(buzz, LOW); delay(80); digitalWrite(buzz, HIGH); delay(80); digitalWrite(buzz, LOW); delay(200); digitalWrite(buzz, HIGH); delay(80); digitalWrite(buzz, LOW); delay(80); digitalWrite(buzz, HIGH); delay(80); digitalWrite(buzz, LOW); delay(80); } //**********COUNTER BEEP**********// void counterbeep() { delay(1200); lcd.clear(); digitalWrite(buzz, HIGH); lcd.setCursor(2,15); lcd.println(" "); lcd.setCursor(2,14); lcd.println(" "); lcd.setCursor(2,0); delay(200); lcd.println("GET IN WITHIN:::"); lcd.setCursor(4,1); lcd.print("5"); delay(200); lcd.clear(); lcd.setCursor(2,0); lcd.println("GET IN WITHIN:"); digitalWrite(buzz,LOW); delay(1000); //2 digitalWrite(buzz, HIGH); lcd.setCursor(2,0); lcd.println("GET IN WITHIN:"); lcd.setCursor(4,1); //2 lcd.print("4"); delay(100); lcd.clear(); lcd.setCursor(2,0); lcd.println("GET IN WITHIN:"); digitalWrite(buzz,LOW); delay(1000); //3 digitalWrite(buzz, HIGH); lcd.setCursor(2,0); lcd.println("GET IN WITHIN:"); lcd.setCursor(4,1); //3 lcd.print("3"); delay(100); lcd.clear(); lcd.setCursor(2,0); lcd.println("GET IN WITHIN:"); digitalWrite(buzz,LOW); delay(1000); //4 digitalWrite(buzz, HIGH); lcd.setCursor(2,0); lcd.println("GET IN WITHIN:"); lcd.setCursor(4,1); //4 lcd.print("2"); delay(100); lcd.clear(); lcd.setCursor(2,0); lcd.println("GET IN WITHIN:"); digitalWrite(buzz,LOW); delay(1000); // digitalWrite(buzz, HIGH); lcd.setCursor(4,1); lcd.print("1"); delay(100); lcd.clear(); lcd.setCursor(2,0); lcd.println("GET IN WITHIN::"); digitalWrite(buzz,LOW); delay(1000); //5 digitalWrite(buzz, HIGH); delay(40); digitalWrite(buzz,LOW); delay(40); digitalWrite(buzz, HIGH); delay(40); digitalWrite(buzz,LOW); delay(40); digitalWrite(buzz, HIGH); delay(40); digitalWrite(buzz,LOW); delay(40); digitalWrite(buzz, HIGH); delay(40); digitalWrite(buzz,LOW); lcd.clear(); lcd.setCursor(2,0); lcd.print("RE-LOCKING"); delay(500); lcd.setCursor(12,0); lcd.print("."); delay(500); lcd.setCursor(13,0); lcd.print("."); delay(500); lcd.setCursor(14,0); lcd.print("."); delay(400); lcd.clear(); lcd.setCursor(4,0); lcd.print("LOCKED!"); delay(440); } //*********TORTURE1***********// void torture1() { delay(1000); lcd.clear(); lcd.setCursor(2,0); lcd.print("WAIT FOR "); lcd.setCursor(5,1); lcd.print("15 SECONDS"); digitalWrite(buzz, HIGH); delay(15000); digitalWrite(buzz, LOW); lcd.clear(); lcd.setCursor(2,0); lcd.print("LOL.."); lcd.setCursor(1,1); lcd.print(" HOW WAS THAT??"); delay(3500); lcd.clear(); } //*****TORTURE2*****// void torture2() { delay(1000); lcd.setCursor(1,0); lcd.print(" "); lcd.setCursor(2,0); lcd.print("EAR DRUMS ARE"); lcd.setCursor(0,1); lcd.print(" PRECIOUS!! "); delay(1500); lcd.clear(); lcd.setCursor(1,0); lcd.print(" WAIT FOR"); lcd.setCursor(4,1); lcd.print(" 1 MINUTE"); digitalWrite(buzz, HIGH); delay(55000); counterbeep(); lcd.clear(); digitalWrite(buzz, LOW); lcd.setCursor(2,0); lcd.print("WANT ME TO"); lcd.setCursor(1,1); lcd.print("REDICULE MORE??"); delay(2500); lcd.clear(); lcd.setCursor(2,0); lcd.print("Ha Ha Ha Ha"); delay(1700); lcd.clear(); } |
23 Comments
What happens if the key pad fails or if someone forgets password
The door won’t open simply.
What if after locking battery gets dead?
You dc power supply from adapter
Is their any solution for above mentioned problems
i want to detect coin, when i put the coin in loadcell…after i put 1 more coin, the system detect total nominal of all coins…for example coin 100(2 grams)+ 200(3 grams)= 300(5 grams)…can you help me with my project??
thank you very much,,,
can i use 4×4 keypad instead of 3×4??
yes, you can. modification in code is required too
WHAT IS TORTURE 1 & 2 ??
Can’t find the library file keypad.h for downlaod
can’t find the library file keypad.h for download
sir
I need simple Eletronice cabinet doors lock keypad password control circuits digram or P. C.B perches give me ida’s
Thanks
Sir LCD not work.. plzs help me?
Hey dude. The Keypad.h library is not available anymore on that link. Can you share some other link where it can be downloaded? Thanks!
the servo is moving before the password is entered
YES PLEASE TELL ME WHAT IS PROBLEM I AM USING 4*4 KEYPAD THARE 1,2,3,A,B,C,D button will not work please resolve my problem as soon as possible
Why keypress and unlock door function are not coming on my IDE
Any body can need this project plese call me 8401016135
thank you
it is not a build in function we have to define
f (code==password[currentposition])
{
++currentposition;
if(currentposition==4)
{
unlockdoor();
currentposition=0;
}
}
else
{
++invalidcount;
incorrect();
currentposition=0;///////////////////////////////////////////
}
if(invalidcount==5)
{
++invalidcount;
torture1();
}
if(invalidcount==8)
{
torture2();
}
}
anyone explain what happing here exactly
SIR I WANT TO INTERFACE IT WITH LM35 SENSOR….MEANS THAT IF A CERTAIN TEMPERATURE IS SET THEN ONLY THE PASSWORD IS ENTERED OTHERWISE NOT….
SIR PLEASE HELP ME WITH THIS….ITS VERY IMPORTANT……
How can i add a pushbutton code to open the servo in this program
can you use a ESP32 too?