Components and supplies
9V battery (generic)
Grove - 12-Channel Capacitive Touch Keypad (ATtiny1616)
Arduino UNO
I2C 16x2 Arduino LCD Display Module
SG90 Micro-servo motor
Linear Regulator (7805)
Tools and machines
Premium Female/Male Extension Jumper Wires, 40 x 6" (150mm)
Servo Motor, Premium Male/Male Jumper Wires
Project description
Code
PROJECT CODE
arduino
1/* 2 Hello, welcome to my code world, my project today is the door security system project. 3 I am writing the codes on the project myself, 4 I may have deficiencies, you can correct me and improve me, 5 thank you in advance. 6 7 My nickname is gncmuh and my name is Sabri GENC 8 9 Good work on your code world :) 10 11*/ 12 13#include <Keypad.h> 14#include <LiquidCrystal_I2C.h> 15#include <Servo.h> 16#include <Wire.h> 17 18Servo servo; 19const byte servo_pin PROGMEM=3; 20const byte rows PROGMEM=4; 21const byte cols PROGMEM=4; 22 23struct pins { 24 const byte pinler[1]={2}; 25 byte row_pins[rows]={11,10,9,8}; 26 byte col_pins[cols]={7,6,5,4}; 27}; 28struct pins pin; 29char key_board[rows][cols]={ 30 {'1','2','3','A'}, //A this character left direction and B this character right direction 31 {'4','5','6','B'}, 32 {'7','8','9','C'}, 33 {'*','0','#','D'} 34}; 35LiquidCrystal_I2C lcd(0x27,16,2); 36Keypad key=Keypad(makeKeymap(key_board),pin.row_pins,pin.col_pins,rows,cols); 37char memory[4]; 38char direction_characters[4]={'<','>','N','Y'}; 39bool flag=false; 40char incoming_key; 41unsigned long timer=0; 42byte counter=7; 43byte memory_counter=0; 44char password[]="1998"; // <-- In this project in real password 45bool out_password=false; 46void setup() 47{ 48 Serial.begin(9600); 49 Wire.begin(); 50 servo.attach(servo_pin);servo.write(0); 51 screen_start(); 52} 53 54void loop() 55{ 56 screen_management(); 57 delay(1); 58 59 60} 61void screen_start() { 62 if(!bool(0)) 63 { 64 lcd.init();lcd.backlight();lcd.setCursor(1,0); 65 lcd.print(F("GNCMUH PROTECH")); 66 lcd.setCursor(4,1); 67 for(int i=1; i<=8; i++) 68 { 69 lcd.print(F("*"));delay(80); 70 } 71 delay(1000);lcd.clear(); 72 } 73} 74void screen_management() { 75 76 if(!bool(0)) 77 { 78 if(flag==false) 79 { 80 first_page(); 81 flag=!flag; 82 } 83 if(flag==true) 84 { 85 here2: 86 if(millis()-timer>2500) 87 { 88 timer=millis(); 89 lcd.setCursor(counter,1);lcd.blink(); 90 } 91 incoming_key=key.getKey(); 92 lcd.setCursor(counter,1); 93 if(incoming_key=='A' or incoming_key=='B' or incoming_key=='C' or incoming_key=='D') 94 { 95 if(incoming_key=='A') 96 { 97 counter--; 98 if(counter<6) counter=7; 99 } 100 if(incoming_key=='B') 101 { 102 counter++; 103 if(counter>8) counter=7; 104 } 105 if(incoming_key=='D' and counter==8) 106 { 107 here: 108 counter=7; 109 lcd.clear(); 110 lcd.setCursor(0,1);lcd.print(direction_characters[0]); 111 lcd.setCursor(6,1);lcd.print(direction_characters[2]); 112 lcd.setCursor(8,1);lcd.print(direction_characters[3]); 113 lcd.setCursor(15,1);lcd.print(direction_characters[1]); 114 lcd.setCursor(1,0); 115 lcd.print(F("ENTER PASSOWORD")); 116 do 117 { 118 incoming_key=key.getKey(); 119 lcd.setCursor(counter,1); 120 if(incoming_key=='A') 121 { 122 counter--; 123 if(counter<6) counter-=5; 124 else if(counter==14) counter=7; 125 } 126 if(incoming_key=='B') 127 { 128 counter++; 129 if(counter>8) counter+=6; 130 else if(counter==1) counter=7; 131 } 132 if(incoming_key=='D' and counter==8) 133 { 134 second_page(); 135 if(atoi(memory)==atoi(password)) 136 { 137 lcd.clear();lcd.print(F("CORRECT PASSWORD")); 138 delay(500);lcd.clear(); 139 lcd.print(F("DOOR OPEN")); 140 servo.write(90); 141 delay(3000); 142 lcd.clear();lcd.print(F("LOCKED")); 143 delay(1000); 144 first_page(); 145 goto here2; 146 } 147 else 148 { 149 lcd.clear();lcd.print(F("WRONG PASSWORD")); 150 delay(1000); 151 first_page(); 152 goto here2; 153 } 154 } 155 if(incoming_key=='D' and counter==6) 156 { 157 first_page(); 158 break; 159 } 160 if(incoming_key=='D' and counter==15) 161 { 162 counter=7; 163 lcd.clear();lcd.setCursor(1,0); 164 lcd.print(F("CHANGE PASSWORD")); 165 lcd.setCursor(0,1);lcd.print(direction_characters[0]); 166 lcd.setCursor(6,1); 167 for(int i=2; i<=3; i++) 168 { 169 lcd.print(direction_characters[i]);lcd.print(F(" ")); 170 } 171 if(!bool(0)) 172 { 173 while(true) 174 { 175 incoming_key=key.getKey(); 176 if(incoming_key=='A') 177 { 178 counter--; 179 if(counter<6) counter=0; 180 } 181 if(incoming_key=='B') 182 { 183 counter++; 184 if(counter>8) counter=7; 185 else if(counter==1) counter=7; 186 } 187 if(incoming_key=='D' and counter==0) 188 { 189 counter=7; 190 goto here; 191 } 192 if(incoming_key=='D' and counter==6) 193 { 194 counter=7; 195 goto here; 196 } 197 if(incoming_key=='D' and counter==8) 198 { 199 third_page(); 200 delay(2000); 201 counter=7; 202 first_page(); 203 goto here2; 204 } 205 lcd.setCursor(counter,1); 206 delay(1); 207 } 208 209 } 210 } 211 if(incoming_key=='D' and counter==0) 212 { 213 counter=7; 214 first_page(); 215 break; 216 } 217 delay(5); 218 219 }while(!bool(0)); 220 } 221 } 222 } 223 } 224} 225void first_page() { 226 servo.write(0);lcd.clear(); 227 lcd.setCursor(3,0); 228 lcd.print(F("HOME PAGE"));lcd.setCursor(6,1); 229 for(int i=0; i<4; i++) 230 { 231 if(i!=2 and i!=3) 232 { 233 lcd.print(direction_characters[i]);lcd.print(F(" ")); 234 } 235 delay(1); 236 } 237 lcd.blink(); 238} 239 240void second_page() { 241 lcd.clear();lcd.noBlink(); 242 lcd.setCursor(1,0); 243 lcd.print(F("ENTER PASSWORD")); 244 memory_counter=0; 245 if(!bool(0)) 246 { 247 while(memory_counter<4) 248 { 249 char incoming_character=key.getKey(); 250 if(incoming_character) 251 { 252 lcd.setCursor(memory_counter+5,1); 253 lcd.print(F("*")); 254 memory[memory_counter]=incoming_character; 255 memory_counter++; 256 } 257 delay(1); 258 } 259 memory_counter=0; 260 counter=7; 261 delay(300); 262 } 263} 264void third_page() { 265 memory_counter=0; 266 lcd.clear();lcd.noBlink(); 267 lcd.print(F("CURRENT PASSWORD")); 268 while(memory_counter<4) 269 { 270 char incoming_character=key.getKey(); 271 if(incoming_character) 272 { 273 lcd.setCursor(memory_counter+5,1); 274 lcd.print(F("*")); 275 memory[memory_counter]=incoming_character; 276 memory_counter++; 277 } 278 delay(1); 279 } 280 delay(300); 281 if(atoi(password)==atoi(memory)) 282 { 283 memory_counter=0; 284 lcd.clear();lcd.setCursor(1,0);lcd.print(F("CORRECT PASSWORD")); 285 delay(1000); 286 lcd.clear();lcd.print(F("NEW PASSWORD")); 287 while(memory_counter<4) 288 { 289 char incoming_character=key.getKey(); 290 if(incoming_character) 291 { 292 lcd.setCursor(memory_counter+5,1); 293 lcd.print(F("*")); 294 memory[memory_counter]=incoming_character; 295 memory_counter++; 296 } 297 delay(1); 298 } 299 for(int i=0; i<4; i++) 300 { 301 password[i]=memory[i]; 302 } 303 delay(300); 304 memory_counter=0; 305 delay(500); 306 lcd.clear();lcd.setCursor(0,0); 307 lcd.print(F("PASSWORD CHANGED"));counter=7; 308 } 309 else 310 { 311 lcd.clear();lcd.print(F("PASSWORD INCORRECT")); 312 delay(1000); 313 counter=7; 314 first_page(); 315 } 316} 317
Downloadable files
PROJECT CİRCUİT
PROJECT CİRCUİT
Comments
Only logged in users can leave comments
gncmuh
2 years ago
It is very important for me that you let me know about my shortcomings and enable me to improve, thank you very much. :)