Author: Sanjay S
My project is a Basic door lock system using Arduino. In this project, Arduino is interfaced with Electronic door lock, LCD, and Keypad. The user is requested to enter the passcode using the keypad. Only when the passcode is correct the door opens, else it activates an alarm.
WORKING:
- The default PIN is stored in the EEPROM memory of Arduino.
- The number of attempts for entering the pin is 3. Using the function getkey(), the current pin is entered using the keypad.
- For each key entered a ‘*’ character is displayed in LCD. If the pin is correct, “Correct pin” will be displayed in LCD and a green LED will glow and a buzzer will buzz and a DC motor will rotate in the clockwise direction
- If the pin is incorrect, “Incorrect pin” is displayed in LCD, red LED will blink and a buzzer will beep, “Rem attempts” along with no of attempts is displayed on LCD.
- If the attempts are over, “Attempts over” will be displayed in LCD, red LED will blink and buzzer will buzz.
- If ‘#’ key is pressed on the keypad, it will trigger the change function. Then “Enter Current PIN” will be displayed on LCD. After the current pin is entered using the keypad, ”Enter New PIN” will be displayed on LCD. The new PIN is updated in the EEPROM memory.
HEADER FILES REQUIRED FOR ARDUINO:
Keypad.h,LiquidCrystal.h,EEPROM.h
CONNECTIONS :
CODE:
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 | //Include the keypad headerfile #include <Keypad.h> //Include the LiquidCrystal headerfile #include<LiquidCrystal.h> //Include the EEPROM headerfile #include <EEPROM.h> int dpass[20]={'1','2','3','4'}; //Default password int upass[20];//User password const byte ROWS = 4; //4 rows const byte COLS = 4; //4 columns char keys[ROWS][COLS] = { {'1','2','3','A'}, {'4','5','6','B'}, {'7','8','9','C'}, {'*','0','#','D'} }; byte rowPins[ROWS] = {A0, A1, A2, A3}; //connect to the row pinouts of the keypad byte colPins[COLS] = {A4, A5, 13,12 }; //connect to the column pinouts of the keypad int temp=0; int i,j,k=0; char key; int atm=3; int addr=1; int ch; Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); LiquidCrystal lcd(2, 3, 4, 5, 6, 7); void(* resetFunc) (void) = 0;//declare reset function at address 0 void setup() { lcd.begin(16, 2); pinMode(8,OUTPUT);//PIN 8 as output pinMode(9,OUTPUT);//PIN 9 as output pinMode(10,OUTPUT);//PIN 10 as output pinMode(11,OUTPUT);//PIN 11 as output } void getkey()//Function for getting input from keypad { j=0; temp=0; ch=EEPROM.read(10); if(ch==1) { addr=1; for( i=0;i<4;i++) { dpass[i]= EEPROM.read(addr); addr++; } } lcd.setCursor(0,0); lcd.print("Enter your PIN"); delay(1000); lcd.clear(); lcd.setCursor(0,0); lcd.print("# to Change");//Changing the default PIN delay(1000); lcd.setCursor(0,1); while(1) { key = keypad.getKey(); if(key=='#') { change(); resetFunc(); } if(key) { lcd.print('*'); } if(!key) { continue; } upass[j]=key; j++; if(j==4) break; } for(i=0;i<4;i++) { if(dpass[i]!=upass[i]) { temp=1; break; } } } void loop() { getkey(); l: if(temp==0) { lcd.clear(); lcd.setCursor(1,0); lcd.print("Correct PIN"); digitalWrite(8,HIGH); digitalWrite(11,HIGH); digitalWrite(10,HIGH); delay(2000); digitalWrite(8,LOW); digitalWrite(10,LOW); digitalWrite(11,LOW); resetFunc(); } if(temp==1&&(atm>1)) { lcd.clear(); lcd.setCursor(1,0); lcd.print("Incorrect PIN"); digitalWrite(11,HIGH); delay(200); digitalWrite(11,LOW); delay(200); digitalWrite(11,HIGH); delay(200); digitalWrite(11,LOW); delay(200); digitalWrite(9,HIGH); delay(2000); digitalWrite(9,LOW); lcd.setCursor(0,0); lcd.print("Rem attempts "); atm--; lcd.print(atm); delay(2000); getkey(); lcd.clear(); goto l; } else { lcd.setCursor(0,0); lcd.print("Attempts over"); digitalWrite(11,HIGH); delay(200); digitalWrite(11,LOW); delay(200); digitalWrite(11,HIGH); delay(200); digitalWrite(11,LOW); delay(200); digitalWrite(11,HIGH); delay(200); digitalWrite(11,LOW); delay(200); digitalWrite(11,HIGH); delay(200); digitalWrite(11,LOW); delay(200); digitalWrite(9,HIGH); delay(6000); digitalWrite(9,LOW); resetFunc(); } } void change()//For changing default PIN { lcd.clear(); lcd.setCursor(0,0); lcd.print("Enter Current PIN"); lcd.setCursor(0,1); while(1) { key = keypad.getKey(); if(key) { lcd.print('*'); } if(!key) { continue; } upass[j]=key; j++; if(j==4) break; } for(i=0;i<4;i++) { if(dpass[i]!=upass[i]) { temp=1; break; } } if(temp==0) { lcd.clear(); lcd.setCursor(0,0); lcd.print("Enter New PIN"); delay(1000); lcd.setCursor(0,1); while(1) { key=keypad.getKey(); if(key) { dpass[k]=key; k++; lcd.print('*'); } if(k==4) { addr=1; for( i=0;i<4;i++) { EEPROM.write(addr, dpass[i]); addr++; } EEPROM.write(10, 1); break; } } } if(temp==1) { lcd.clear(); lcd.setCursor(1,0); lcd.print("Incorrect PIN"); digitalWrite(9,HIGH); delay(2000); digitalWrite(9,LOW); resetFunc(); } } |
OUTPUT:
THANK YOU
SHARE THIS!!!