Door Unlock using 4*3 keypad
Arduino Based door unlock system with helps in security of homws
Components and supplies
1
SG90 Micro-servo motor
1
Arduino UNO
1
Keypad 4*3
1
Alphanumeric LCD, 16 x 2
1
Rotary potentiometer (generic)
Project description
Code
CODE
csharp
just upload in Arduino and run it
1#include <Keypad.h> 2 3#include<LiquidCrystal.h> 4 5#include<EEPROM.h> 6#include <Servo.h> 7Servo myservo; // create servo object to control a servo 8// twelve servo objects can be created on most boards 9 10 11LiquidCrystal liquid_crystal_display(12,11,5,4,3,2); 12 13char password[4]; 14 15char initial_password[4],new_password[4]; 16 17int i=0; 18 19 20 21char key_pressed=0; 22 23const byte rows = 4; 24 25const byte columns = 3; 26 27char hexaKeys[rows][columns] = { 28 29{'1','2','3'}, 30 31{'4','5','6'}, 32 33{'7','8','9'}, 34 35{'*','0','#'} 36 37}; 38 39byte row_pins[rows] = {0,1,6,7}; 40 41byte column_pins[columns] = {8,10,13}; 42 43 44Keypad keypad_key = Keypad( makeKeymap(hexaKeys), row_pins, column_pins, rows, columns); 45 46 47 48 49void setup() 50 51{ 52 myservo.attach(9); 53 54 55 liquid_crystal_display.begin(16,2); 56 57 58 59 liquid_crystal_display.print("keypad doorLock "); 60 61 delay(2000); 62 63 liquid_crystal_display.clear(); 64 65 liquid_crystal_display.print("Enter Password"); 66 67 liquid_crystal_display.setCursor(0,1); 68 69 initialpassword(); 70} 71 72 73 74 75void loop() 76 77{ 78 79 80 81 key_pressed = keypad_key.getKey(); 82 83 if(key_pressed=='*') 84 85 change(); 86 87 if (key_pressed) 88 89 { 90 91 password[i++]=key_pressed; 92 93 liquid_crystal_display.print(key_pressed); 94 95 } 96 97 if(i==4) 98 99 { 100 101 delay(200); 102 103 for(int j=0;j<4;j++) 104 105 initial_password[j]=EEPROM.read(j); 106 107 if(!(strncmp(password, initial_password,4))) 108 109 { 110 111 liquid_crystal_display.clear(); 112 113 liquid_crystal_display.print("Pass Accepted"); 114 115 open_t(); 116 117 118 delay(2000); 119 120 liquid_crystal_display.setCursor(0,1); 121 122 liquid_crystal_display.print("Pres * to change"); 123 124 delay(2000); 125 126 liquid_crystal_display.clear(); 127 128 liquid_crystal_display.print("Enter Password:"); 129 130 liquid_crystal_display.setCursor(0,1); 131 132 i=0; 133 134 135 136 137 } 138 139 else 140 141 { 142 143 144 145 146 liquid_crystal_display.clear(); 147 148 liquid_crystal_display.print("Wrong Password"); 149 150 liquid_crystal_display.setCursor(0,1); 151 152 liquid_crystal_display.print("Pres * to Change"); 153 154 delay(2000); 155 156 liquid_crystal_display.clear(); 157 158 liquid_crystal_display.print("Enter Password"); 159 160 liquid_crystal_display.setCursor(0,1); 161 162 i=0; 163 164 165 166 167 } 168 169 } 170 171} 172 173void change() 174 175{ 176 177 int j=0; 178 179 liquid_crystal_display.clear(); 180 181 liquid_crystal_display.print("Current Password"); 182 183 liquid_crystal_display.setCursor(0,1); 184 185 while(j<4) 186 187 { 188 189 char key=keypad_key.getKey(); 190 191 if(key) 192 193 { 194 195 new_password[j++]=key; 196 197 liquid_crystal_display.print(key); 198 199 200 201 } 202 203 key=0; 204 205 } 206 207 delay(500); 208 209 210 211 212 if((strncmp(new_password, initial_password, 4))) 213 214 { 215 216 liquid_crystal_display.clear(); 217 218 liquid_crystal_display.print("Wrong Password"); 219 220 liquid_crystal_display.setCursor(0,1); 221 222 liquid_crystal_display.print("Try Again"); 223 224 delay(1000); 225 226 } 227 228 else 229 230 { 231 232 j=0; 233 234 liquid_crystal_display.clear(); 235 236 liquid_crystal_display.print("New Password:"); 237 238 liquid_crystal_display.setCursor(0,1); 239 240 while(j<4) 241 242 { 243 244 char key=keypad_key.getKey(); 245 246 if(key) 247 248 { 249 250 initial_password[j]=key; 251 252 liquid_crystal_display.print(key); 253 254 EEPROM.write(j,key); 255 256 j++; 257 258 259 260 } 261 262 } 263 264 liquid_crystal_display.print("Pass Changed"); 265 266 delay(1000); 267 268 } 269 270 liquid_crystal_display.clear(); 271 272 liquid_crystal_display.print("Enter Password"); 273 274 liquid_crystal_display.setCursor(0,1); 275 276 key_pressed=0; 277 278} 279 280 281 282 283void initialpassword(){ 284 285 for(int j=0;j<4;j++) 286 287 EEPROM.write(j, j+49); 288 289 for(int j=0;j<4;j++) 290 291 initial_password[j]=EEPROM.read(j); 292 293} 294void open_t() { 295 int pos=0; 296 297 298 for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees 299 // in steps of 1 degree 300 myservo.write(pos); // tell servo to go to position in variable 'pos' 301 delay(15); // waits 15 ms for the servo to reach the position 302 } 303 liquid_crystal_display.setCursor(0,1); 304 liquid_crystal_display.print("closing.."); 305 delay(1000); 306 for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees 307 myservo.write(pos); // tell servo to go to position in variable 'pos' 308 delay(15); // waits 15 ms for the servo to reach the position 309 } 310}
Downloadable files
Schematic
Schematic

Schematic
Schematic

Comments
Only logged in users can leave comments