├── .gitattributes └── Fingrprint___Hex_keypad_based_door_lock_system ├── fingerprint.h ├── enrol.h └── Fingrprint___Hex_keypad_based_door_lock_system.ino /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Fingrprint___Hex_keypad_based_door_lock_system/fingerprint.h: -------------------------------------------------------------------------------- 1 | 2 | // Replace with your SSID and Password 3 | const char* ssid = "SSID"; 4 | const char* password = "PASS"; 5 | 6 | // Necesarry Variables to make Attendance Sheet 7 | String Event_name = "fingerprint"; 8 | String Webhooks_key = "YOUR_WEBHOOKS_KEY"; 9 | 10 | //The Secret Code 11 | int Secret_Code = 1234; 12 | 13 | // Pin Definition 14 | int buzzer = 15; 15 | int Relay = 23; 16 | 17 | //Misc. Variables 18 | int i = 0; 19 | int k = 0; 20 | bool wrong_code = 1; 21 | uint8_t new_ID = 0; 22 | String NAME = ""; 23 | String ID = ""; 24 | char* response = " "; 25 | String res = ""; 26 | char* succ_code = "200 OK"; 27 | unsigned int p; 28 | 29 | 30 | // Maker Webhooks IFTTT 31 | String resource = "/trigger/" + Event_name + "/with/key/" + Webhooks_key; 32 | const char* server = "maker.ifttt.com"; 33 | 34 | unsigned int getFingerprintEnroll(); 35 | unsigned int readnumber(); 36 | unsigned int getFingerprintID(); 37 | 38 | 39 | void beep(int duration); 40 | void Door_control(); 41 | unsigned int getFingerprintEnroll(); 42 | unsigned int readnumber(); 43 | unsigned int getFingerprintID(); 44 | int getFingerprintIDez(); 45 | 46 | 47 | 48 | void setup_f() 49 | { 50 | Serial.begin(57600); 51 | pinMode(buzzer, OUTPUT); 52 | while (!Serial); 53 | delay(100); 54 | Serial.println("\n\nAdafruit finger detect test"); 55 | 56 | // set the data rate for the sensor serial port 57 | finger.begin(57600); 58 | delay(5); 59 | if (finger.verifyPassword()) { 60 | Serial.println("Found fingerprint sensor!"); 61 | } else { 62 | Serial.println("Did not find fingerprint sensor :("); 63 | int i; 64 | while (i < 7) { 65 | delay(10); 66 | Serial.print(".!F!."); 67 | i++; 68 | } 69 | } 70 | 71 | finger.getTemplateCount(); 72 | Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates"); 73 | Serial.println("Waiting for valid finger..."); 74 | // display.clearDisplay(); 75 | // display.setTextSize(2); // Normal 1:1 pixel scale 76 | // display.setTextColor(SSD1306_WHITE); // Draw white text 77 | // display.setCursor(0, 0); // Start at top-left corner 78 | // display.println(("Waiting \nfor \nvalid \nfinger...")); 79 | // display.display(); 80 | // delay(500); 81 | } 82 | 83 | void loop_f() // run over and over again 84 | { 85 | getFingerprintID(); 86 | delay(50); //don't ned to run this at full speed. 87 | } 88 | 89 | 90 | 91 | // Make an HTTP request to the IFTTT web service 92 | void makeIFTTTRequest() 93 | { 94 | Serial.print("Connecting to "); 95 | Serial.print(server); 96 | 97 | WiFiClient client; 98 | int retries = 5; 99 | while (!!!client.connect(server, 80) && (retries-- > 0)) { 100 | Serial.print("."); 101 | } 102 | Serial.println(); 103 | if (!!!client.connected()) { 104 | Serial.println("Failed to connect..."); 105 | } 106 | 107 | Serial.print("Request resource: "); 108 | Serial.println(resource); 109 | 110 | // Temperature in Celsius 111 | String jsonObject = String("{\"value1\":\"") + ID + "\"}"; 112 | client.println(String("POST ") + resource + " HTTP/1.1"); 113 | client.println(String("Host: ") + server); 114 | client.println("Connection: close\r\nContent-Type: application/json"); 115 | client.print("Content-Length: "); 116 | client.println(jsonObject.length()); 117 | client.println(); 118 | client.println(jsonObject); 119 | 120 | int timeout = 3 * 10; // 5 seconds 121 | while (!!!client.available() && (timeout-- > 0)) { 122 | delay(100); 123 | } 124 | if (!!!client.available()) { 125 | Serial.println("No response..."); 126 | } 127 | while (client.available()) 128 | { 129 | // Serial.write(client.read()); 130 | char add = client.read(); 131 | res = res + add; 132 | } 133 | response = &res[0]; 134 | Serial.println("======="); 135 | Serial.println(response); 136 | if (strstr(response, succ_code)) 137 | { 138 | Serial.println("Registered"); 139 | display.clearDisplay(); 140 | display.setTextSize(2); // Normal 1:1 pixel scale 141 | display.setTextColor(SSD1306_WHITE); // Draw white text 142 | display.setCursor(0, 30); // Start at top-left corner 143 | display.println(("Registered")); 144 | display.display(); 145 | delay(1000); 146 | } 147 | else 148 | { 149 | Serial.println("Not Registered"); 150 | display.clearDisplay(); 151 | display.setTextSize(2); // Normal 1:1 pixel scale 152 | display.setTextColor(SSD1306_WHITE); // Draw white text 153 | display.setCursor(30, 10); // Start at top-left corner 154 | display.println(("Not")); 155 | display.setCursor(0, 30); // Start at top-left corner 156 | display.println(("Registered")); 157 | display.display(); 158 | delay(1000); 159 | } 160 | response = ""; 161 | res = ""; 162 | Serial.println("\nclosing connection"); 163 | 164 | client.stop(); 165 | } 166 | 167 | // returns -1 if failed, otherwise returns ID # 168 | unsigned int getFingerprintID() 169 | { 170 | unsigned int p = finger.getImage(); 171 | switch (p) { 172 | case FINGERPRINT_OK: 173 | Serial.println("Image taken"); 174 | 175 | break; 176 | case FINGERPRINT_NOFINGER: 177 | Serial.println("No finger detected"); 178 | 179 | return p; 180 | case FINGERPRINT_PACKETRECIEVEERR: 181 | Serial.println("Communication error"); 182 | display.clearDisplay(); 183 | display.setTextSize(2); // Normal 1:1 pixel scale 184 | display.setTextColor(SSD1306_WHITE); // Draw white text 185 | display.setCursor(0, 0); // Start at top-left corner 186 | display.println(("Commun \nerror")); 187 | display.display(); 188 | beep(200); 189 | beep(200); 190 | beep(200); 191 | delay(200); 192 | return p; 193 | case FINGERPRINT_IMAGEFAIL: 194 | Serial.println("Imaging error"); 195 | return p; 196 | default: 197 | Serial.println("Unknown error"); 198 | return p; 199 | } 200 | 201 | // OK success! 202 | 203 | p = finger.image2Tz(); 204 | switch (p) { 205 | case FINGERPRINT_OK: 206 | Serial.println("Image converted"); 207 | break; 208 | case FINGERPRINT_IMAGEMESS: 209 | Serial.println("Image too messy"); 210 | return p; 211 | case FINGERPRINT_PACKETRECIEVEERR: 212 | Serial.println("Communication error"); 213 | return p; 214 | case FINGERPRINT_FEATUREFAIL: 215 | Serial.println("Could not find fingerprint features"); 216 | return p; 217 | case FINGERPRINT_INVALIDIMAGE: 218 | Serial.println("Could not find fingerprint features"); 219 | return p; 220 | default: 221 | Serial.println("Unknown error"); 222 | return p; 223 | } 224 | 225 | p = finger.fingerFastSearch(); 226 | if (p == FINGERPRINT_OK) { 227 | Serial.println("Found a print match!"); 228 | display.clearDisplay(); 229 | display.setTextSize(2); // Normal 1:1 pixel scale 230 | display.setTextColor(SSD1306_WHITE); // Draw white text 231 | display.setCursor(0, 0); // Start at top-left corner 232 | display.println(("Finger \nMatched !")); 233 | display.display(); 234 | beep(1000); 235 | //delay(1000); 236 | } else if (p == FINGERPRINT_PACKETRECIEVEERR) { 237 | Serial.println("Communication error"); 238 | return p; 239 | } else if (p == FINGERPRINT_NOTFOUND) { 240 | Serial.println("Did not find a match"); 241 | display.clearDisplay(); 242 | display.setTextSize(2); // Normal 1:1 pixel scale 243 | display.setTextColor(SSD1306_WHITE); // Draw white text 244 | display.setCursor(0, 0); // Start at top-left corner 245 | display.println(("Did not \nfind a \nmatch")); 246 | display.display(); 247 | beep(200); 248 | beep(200); 249 | delay(500); 250 | return p; 251 | } else { 252 | Serial.println("Unknown error"); 253 | return p; 254 | } 255 | 256 | // found a match! 257 | Serial.print("Found ID #"); Serial.print(finger.fingerID); 258 | display.clearDisplay(); 259 | display.setTextSize(2); // Normal 1:1 pixel scale 260 | display.setTextColor(SSD1306_WHITE); // Draw white text 261 | display.setCursor(50, 25); // Start at top-left corner 262 | display.println(("ID")); 263 | display.setCursor(50, 40); 264 | display.println((finger.fingerID)); 265 | display.display(); 266 | delay(500); 267 | Serial.print(" with confidence of "); Serial.println(finger.confidence); 268 | if (finger.confidence > 40) 269 | { 270 | Door_control(); 271 | ID = finger.fingerID; 272 | makeIFTTTRequest(); 273 | } 274 | return finger.fingerID; 275 | } 276 | // returns -1 if failed, otherwise returns ID # 277 | int getFingerprintIDez() { 278 | uint8_t p = finger.getImage(); 279 | if (p != FINGERPRINT_OK) return -1; 280 | 281 | p = finger.image2Tz(); 282 | if (p != FINGERPRINT_OK) return -1; 283 | 284 | p = finger.fingerFastSearch(); 285 | if (p != FINGERPRINT_OK) return -1; 286 | 287 | // found a match! 288 | Serial.print("Found ID #"); Serial.print(finger.fingerID); 289 | Serial.print(" with confidence of "); Serial.println(finger.confidence); 290 | 291 | return finger.fingerID; 292 | } 293 | void beep(int duration) 294 | { 295 | digitalWrite(buzzer, HIGH); 296 | delay(duration); 297 | digitalWrite(buzzer, LOW); 298 | delay(30); 299 | } 300 | 301 | void Door_control() 302 | { 303 | digitalWrite(Relay, HIGH); 304 | Serial.println("Opening the door"); 305 | display.clearDisplay(); 306 | display.setTextSize(2); // Normal 1:1 pixel scale 307 | display.setTextColor(SSD1306_WHITE); // Draw white text 308 | display.setCursor(0, 20); // Start at top-left corner 309 | display.println(("Opening \nthe door")); 310 | display.display(); 311 | delay(1000); 312 | Serial.println("Closing the door"); 313 | display.clearDisplay(); 314 | display.setTextSize(2); // Normal 1:1 pixel scale 315 | display.setTextColor(SSD1306_WHITE); // Draw white text 316 | display.setCursor(0, 20); // Start at top-left corner 317 | display.println(("Closing \nthe door")); 318 | display.display(); 319 | delay(2000); 320 | digitalWrite(Relay, LOW); 321 | } 322 | 323 | //} 324 | -------------------------------------------------------------------------------- /Fingrprint___Hex_keypad_based_door_lock_system/enrol.h: -------------------------------------------------------------------------------- 1 | #include //https://github.com/adafruit/Adafruit-Fingerprint-Sensor-Library 2 | #include //https://github.com/adafruit/Adafruit-GFX-Library 3 | #include //https://github.com/adafruit/Adafruit_SSD1306 4 | #include //https://www.arduinolibraries.info/libraries/keypad 5 | #include 6 | #include 7 | #include 8 | 9 | //Keypad Configurations 10 | const byte ROWS = 4; //four rows 11 | const byte COLS = 4; //four columns 12 | //define the cymbols on the buttons of the keypads 13 | char hexaKeys[ROWS][COLS] = { 14 | {'1', '2', '3', 'A'}, 15 | {'4', '5', '6', 'B'}, 16 | {'7', '8', '9', 'C'}, 17 | {'*', '0', '#', 'D'} 18 | }; 19 | byte rowPins[ROWS] = {13, 12, 14, 27}; //connect to the row pinouts of the keypad 20 | byte colPins[COLS] = {26, 25, 33, 32}; //connect to the column pinouts of the keypad 21 | Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 22 | 23 | 24 | void beep(int duration); 25 | 26 | //Display Configurations 27 | #define SCREEN_WIDTH 128 // OLED display width, in pixels 28 | #define SCREEN_HEIGHT 64 // OLED display height, in pixels 29 | // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) 30 | #define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin) 31 | Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); 32 | 33 | String ID_e; 34 | char customKey; 35 | int value; 36 | bool done_flag = 0; 37 | unsigned int id; 38 | int fingerprint_flag = 1; 39 | //initialize an instance of class NewKeypad 40 | 41 | 42 | Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial2); 43 | 44 | unsigned int getFingerprintEnroll(); 45 | unsigned int readnumber(void); 46 | unsigned int getFingerprintID(); 47 | int Keypad_Input(void); 48 | void state(void); 49 | 50 | 51 | void setup_e() 52 | { 53 | Serial.begin(57600); 54 | Serial2.begin(115200); 55 | while (!Serial); 56 | delay(100); 57 | Serial.println("\n\nAdafruit Fingerprint sensor enrollment"); 58 | 59 | // set the data rate for the sensor Serial port 60 | finger.begin(57600); 61 | 62 | if (finger.verifyPassword()) { 63 | Serial.println("Found fingerprint sensor!"); 64 | } else { 65 | Serial.println("Did not find fingerprint sensor :("); 66 | int i; 67 | while (i < 7) { 68 | delay(10); 69 | Serial.print(".!E!."); 70 | i++; 71 | } 72 | } 73 | } 74 | 75 | 76 | void loop_e() // run over and over again 77 | { 78 | Serial.println("Ready to enroll a fingerprint!"); 79 | Serial.println("Please type in the ID # (from 1 to 127) you want to save this finger as..."); 80 | id = readnumber(); 81 | if (id == 0) {// ID #0 not allowed, try again! 82 | return; 83 | } 84 | Serial.print("Enrolling ID #"); 85 | // Serial.println(id); 86 | 87 | while (1) { 88 | getFingerprintEnroll(); 89 | break; 90 | } 91 | } 92 | 93 | 94 | unsigned int readnumber() 95 | { 96 | Serial.println("Reading Number"); 97 | int i = 0; 98 | ID_e = ""; 99 | value = 0; 100 | while (1) 101 | { 102 | customKey = customKeypad.getKey(); 103 | 104 | if (customKey && i < 3) 105 | { 106 | ID_e = ID_e + customKey; 107 | value = ID_e.toInt(); 108 | Serial.println(value); 109 | display.setTextSize(2); // Normal 1:1 pixel scale 110 | display.setTextColor(SSD1306_WHITE); // Draw white text 111 | display.setCursor(50, 50); // Start at top-left corner 112 | display.println(value); 113 | display.display(); 114 | 115 | beep(100); 116 | i++; 117 | } 118 | if (customKey == '#') 119 | { 120 | beep(100); 121 | return (value); 122 | } 123 | if (customKey == 'B') 124 | { 125 | fingerprint_flag = 1; 126 | ID_e = ""; 127 | i = 0; 128 | beep(100); 129 | return (value); 130 | } 131 | 132 | } 133 | } 134 | 135 | 136 | 137 | unsigned int getFingerprintEnroll() 138 | { 139 | 140 | int p = -1; 141 | Serial.print("Waiting for valid finger to enroll as #"); 142 | display.clearDisplay(); 143 | display.setTextSize(2); // Normal 1:1 pixel scale 144 | display.setTextColor(SSD1306_WHITE); // Draw white text 145 | display.setCursor(20, 20); // Start at top-left corner 146 | display.println(("Place")); 147 | display.setCursor(15, 40); // Start at top-left corner 148 | display.println(("Finger")); 149 | display.display(); 150 | Serial.println(id); 151 | while (p != FINGERPRINT_OK) { 152 | p = finger.getImage(); 153 | switch (p) { 154 | case FINGERPRINT_OK: 155 | Serial.println("Image taken"); 156 | break; 157 | case FINGERPRINT_NOFINGER: 158 | Serial.println("."); 159 | break; 160 | case FINGERPRINT_PACKETRECIEVEERR: 161 | Serial.println("Communication error"); 162 | break; 163 | case FINGERPRINT_IMAGEFAIL: 164 | Serial.println("Imaging error"); 165 | break; 166 | default: 167 | Serial.println("Unknown error"); 168 | break; 169 | } 170 | } 171 | 172 | // OK success! 173 | 174 | p = finger.image2Tz(1); 175 | switch (p) { 176 | case FINGERPRINT_OK: 177 | Serial.println("Image converted"); 178 | break; 179 | case FINGERPRINT_IMAGEMESS: 180 | Serial.println("Image too messy"); 181 | return p; 182 | case FINGERPRINT_PACKETRECIEVEERR: 183 | Serial.println("Communication error"); 184 | return p; 185 | case FINGERPRINT_FEATUREFAIL: 186 | Serial.println("Could not find fingerprint features"); 187 | return p; 188 | case FINGERPRINT_INVALIDIMAGE: 189 | Serial.println("Could not find fingerprint features"); 190 | return p; 191 | default: 192 | Serial.println("Unknown error"); 193 | return p; 194 | } 195 | 196 | Serial.println("Remove finger"); 197 | display.clearDisplay(); 198 | display.setTextSize(2); // Normal 1:1 pixel scale 199 | display.setTextColor(SSD1306_WHITE); // Draw white text 200 | display.setCursor(18, 20); // Start at top-left corner 201 | display.println(("Remove")); 202 | display.setCursor(15, 40); // Start at top-left corner 203 | display.println(("Finger")); 204 | display.display(); 205 | delay(2000); 206 | p = 0; 207 | while (p != FINGERPRINT_NOFINGER) { 208 | p = finger.getImage(); 209 | } 210 | Serial.print("ID "); Serial.println(id); 211 | p = -1; 212 | Serial.println("Place same finger again"); 213 | display.clearDisplay(); 214 | display.setTextSize(2); // Normal 1:1 pixel scale 215 | display.setTextColor(SSD1306_WHITE); // Draw white text 216 | display.setCursor(30, 0); // Start at top-left corner 217 | display.println(("Place \n same \n Finger")); 218 | display.display(); 219 | while (p != FINGERPRINT_OK) { 220 | p = finger.getImage(); 221 | switch (p) { 222 | case FINGERPRINT_OK: 223 | Serial.println("Image taken"); 224 | break; 225 | case FINGERPRINT_NOFINGER: 226 | Serial.print("."); 227 | break; 228 | case FINGERPRINT_PACKETRECIEVEERR: 229 | Serial.println("Communication error"); 230 | break; 231 | case FINGERPRINT_IMAGEFAIL: 232 | Serial.println("Imaging error"); 233 | break; 234 | default: 235 | Serial.println("Unknown error"); 236 | break; 237 | } 238 | } 239 | 240 | // OK success! 241 | 242 | p = finger.image2Tz(2); 243 | switch (p) { 244 | case FINGERPRINT_OK: 245 | Serial.println("Image converted"); 246 | break; 247 | case FINGERPRINT_IMAGEMESS: 248 | Serial.println("Image too messy"); 249 | return p; 250 | case FINGERPRINT_PACKETRECIEVEERR: 251 | Serial.println("Communication error"); 252 | return p; 253 | case FINGERPRINT_FEATUREFAIL: 254 | Serial.println("Could not find fingerprint features"); 255 | return p; 256 | case FINGERPRINT_INVALIDIMAGE: 257 | Serial.println("Could not find fingerprint features"); 258 | return p; 259 | default: 260 | Serial.println("Unknown error"); 261 | return p; 262 | } 263 | 264 | // OK converted! 265 | Serial.print("Creating model for #"); 266 | 267 | Serial.println(id); 268 | 269 | p = finger.createModel(); 270 | if (p == FINGERPRINT_OK) { 271 | Serial.println("Prints matched!"); 272 | display.clearDisplay(); 273 | display.setTextSize(2); // Normal 1:1 pixel scale 274 | display.setTextColor(SSD1306_WHITE); // Draw white text 275 | display.setCursor(15, 20); // Start at top-left corner 276 | display.println(("Prints \nmatched")); 277 | display.display(); 278 | beep(2000); 279 | //delay(1000); 280 | } else if (p == FINGERPRINT_PACKETRECIEVEERR) { 281 | Serial.println("Communication error"); 282 | return p; 283 | } else if (p == FINGERPRINT_ENROLLMISMATCH) { 284 | Serial.println("Fingerprints did not match"); 285 | display.clearDisplay(); 286 | display.setTextSize(2); // Normal 1:1 pixel scale 287 | display.setTextColor(SSD1306_WHITE); // Draw white text 288 | display.setCursor(15, 0); // Start at top-left corner 289 | display.println((" Prints \n did not \n matched")); 290 | display.display(); 291 | beep(200); 292 | beep(200); 293 | delay(500); 294 | return p; 295 | } else { 296 | Serial.println("Unknown error"); 297 | return p; 298 | } 299 | 300 | Serial.print("ID "); Serial.println(id); 301 | p = finger.storeModel(id); 302 | if (p == FINGERPRINT_OK) { 303 | Serial.println("Stored!"); 304 | display.clearDisplay(); 305 | display.setTextSize(2); // Normal 1:1 pixel scale 306 | display.setTextColor(SSD1306_WHITE); // Draw white text 307 | display.setCursor(0, 0); // Start at top-left corner 308 | display.println((" Print \n stored to ID ")); 309 | display.println((id)); 310 | display.display(); 311 | delay(1000); 312 | // return; 313 | } else if (p == FINGERPRINT_PACKETRECIEVEERR) { 314 | Serial.println("Communication error"); 315 | return p; 316 | } else if (p == FINGERPRINT_BADLOCATION) { 317 | Serial.println("Could not store in that location"); 318 | return p; 319 | } else if (p == FINGERPRINT_FLASHERR) { 320 | Serial.println("Error writing to flash"); 321 | return p; 322 | } else { 323 | Serial.println("Unknown error"); 324 | return p; 325 | } 326 | 327 | } 328 | 329 | int Keypad_Input(void) 330 | { 331 | int i = 0; 332 | display.clearDisplay(); 333 | display.setTextSize(2); // Normal 1:1 pixel scale 334 | display.setTextColor(SSD1306_WHITE); // Draw white text 335 | display.setCursor(30, 0); // Start at top-left corner 336 | display.println(("Enter")); 337 | display.setCursor(35, 20); // Start at top-left corner 338 | display.println(("Code")); 339 | display.display(); 340 | i = 0; 341 | ID_e = ""; 342 | value = 0; 343 | while (1) 344 | { 345 | customKey = customKeypad.getKey(); 346 | 347 | if (customKey && i < 4) 348 | { 349 | ID_e = ID_e + customKey; 350 | value = ID_e.toInt(); 351 | Serial.println(value); 352 | display.setTextSize(2); // Normal 1:1 pixel scale 353 | display.setTextColor(SSD1306_WHITE); // Draw white text 354 | display.setCursor(i * 35, 50); // Start at top-left corner 355 | display.println(("*")); 356 | display.display(); 357 | beep(100); 358 | i++; 359 | } 360 | if (customKey == '#') 361 | { 362 | done_flag = 1; 363 | Serial.println("DONE"); 364 | i = 0; 365 | ID_e = ""; 366 | return (value); 367 | } 368 | if (customKey == 'B') 369 | { 370 | fingerprint_flag = 1; 371 | ID_e = ""; 372 | return (0); 373 | } 374 | } 375 | } 376 | -------------------------------------------------------------------------------- /Fingrprint___Hex_keypad_based_door_lock_system/Fingrprint___Hex_keypad_based_door_lock_system.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * This is the code for the Project 4 | * IoT Security Project using Fingerprint sensor & Hex Keypad. 5 | * 6 | * 7 | * This code was written by Sachin Soni and Joy Jacob for 8 | * project made for techiesms YouTube channel.You can 9 | * watch the full tutorial video for the project on the 10 | * channel. 11 | * 12 | * Anyone using this code for commercial purpose or replicating this 13 | * project on thier social medias should give credits to techiesms. 14 | * 15 | * 16 | * Channel Link :- http://www.youtube.com/techiesms 17 | * 18 | * 19 | * techiesms 20 | * explore | learn | share 21 | * 22 | */ 23 | 24 | 25 | 26 | 27 | 28 | #include "enrol.h" 29 | #include "fingerprint.h" 30 | 31 | // Icon of Fingerprint 32 | #define LOGO_HEIGHT 64 33 | #define LOGO_WIDTH 128 34 | static const unsigned char PROGMEM logo_bmp[] = 35 | { 36 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 38 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 39 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 40 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 41 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0x83, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 42 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 43 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x03, 0xff, 0xc0, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f, 0xff, 0xf8, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 46 | 0x00, 0x00, 0x00, 0x00, 0x01, 0xf0, 0xff, 0xff, 0xfe, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 47 | 0x00, 0x00, 0x00, 0x00, 0x01, 0xe1, 0xff, 0x00, 0xff, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 48 | 0x00, 0x00, 0x00, 0x00, 0x01, 0xc7, 0xf0, 0x00, 0x1f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 49 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x8f, 0xc0, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x03, 0xff, 0xc1, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 51 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x0f, 0xff, 0xf0, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 52 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x3f, 0xff, 0xfc, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 53 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x00, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 54 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xf1, 0xf8, 0x00, 0x1f, 0x8f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 55 | 0x00, 0x00, 0x00, 0x00, 0x01, 0xe3, 0xf0, 0x18, 0x0f, 0xc7, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 56 | 0x00, 0x00, 0x00, 0x00, 0x03, 0xc7, 0xc1, 0xff, 0x83, 0xe3, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 57 | 0x00, 0x00, 0x00, 0x00, 0x03, 0xc7, 0x87, 0xff, 0xe1, 0xf1, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 58 | 0x00, 0x00, 0x00, 0x00, 0x07, 0x8f, 0x1f, 0xff, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 59 | 0x00, 0x00, 0x00, 0x00, 0x07, 0x1e, 0x3f, 0x01, 0xf8, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 60 | 0x00, 0x00, 0x00, 0x00, 0x07, 0x1e, 0x7e, 0x00, 0x7c, 0x79, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 61 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x78, 0x00, 0x3e, 0x3d, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 62 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xf0, 0xff, 0x1f, 0x3d, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 63 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x79, 0xe1, 0xff, 0x8f, 0x1c, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 64 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xf1, 0xe3, 0xff, 0xc7, 0x1e, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 65 | 0x00, 0x00, 0x00, 0x00, 0x01, 0xe3, 0xc7, 0xc3, 0xc7, 0x9e, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 66 | 0x00, 0x00, 0x00, 0x00, 0x07, 0xe3, 0x8f, 0x01, 0xe7, 0x9e, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 67 | 0x00, 0x00, 0x00, 0x00, 0x0f, 0xc7, 0x8f, 0x00, 0xe3, 0x9e, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 68 | 0x00, 0x00, 0x00, 0x00, 0x0f, 0x8f, 0x9e, 0x18, 0xf3, 0x9e, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 69 | 0x00, 0x00, 0x00, 0x00, 0x0e, 0x0f, 0x1e, 0x38, 0xf3, 0x9e, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 70 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x3c, 0x38, 0xf3, 0x9e, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 71 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x3c, 0x78, 0xf7, 0x9c, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 72 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x78, 0x78, 0xe7, 0x9c, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 73 | 0x00, 0x00, 0x00, 0x00, 0x01, 0xf0, 0xf0, 0xf1, 0xe7, 0x9c, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 74 | 0x00, 0x00, 0x00, 0x00, 0x03, 0xe1, 0xf1, 0xe1, 0xe7, 0x3c, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 75 | 0x00, 0x00, 0x00, 0x00, 0x0f, 0xc3, 0xe3, 0xe3, 0xc7, 0x3c, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 76 | 0x00, 0x00, 0x00, 0x00, 0x0f, 0x87, 0xc3, 0xc3, 0xcf, 0x3c, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 77 | 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x87, 0x87, 0x8f, 0x3c, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 78 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x0f, 0x0f, 0x8f, 0x38, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 79 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x1f, 0x1f, 0x0f, 0x3c, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 80 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3e, 0x1e, 0x0f, 0x3d, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 81 | 0x00, 0x00, 0x00, 0x00, 0x01, 0xf0, 0x7c, 0x3c, 0xcf, 0x3c, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 82 | 0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0xf8, 0x79, 0xcf, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 83 | 0x00, 0x00, 0x00, 0x00, 0x0f, 0xc1, 0xf0, 0xf9, 0xcf, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 84 | 0x00, 0x00, 0x00, 0x00, 0x0f, 0x07, 0xe1, 0xf1, 0xc7, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 85 | 0x00, 0x00, 0x00, 0x00, 0x0e, 0x0f, 0xc3, 0xe3, 0xc7, 0x87, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 86 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x07, 0xc3, 0xc7, 0x87, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 87 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x1f, 0x83, 0xc3, 0xc3, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 88 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3e, 0x01, 0xc3, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 89 | 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x7c, 0x01, 0xc1, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 90 | 0x00, 0x00, 0x00, 0x00, 0x01, 0xf0, 0xf8, 0x01, 0xe0, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 91 | 0x00, 0x00, 0x00, 0x00, 0x01, 0xc3, 0xf3, 0xf8, 0xf0, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 92 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xe7, 0xfc, 0xf8, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 93 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xcf, 0xfe, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 94 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x1f, 0x1e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 95 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x3e, 0x0f, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 96 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x0f, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 97 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 98 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 99 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 100 | }; 101 | 102 | 103 | 104 | void setup() 105 | { 106 | // put your setup code here, to run once: 107 | 108 | pinMode(Relay, OUTPUT); 109 | digitalWrite(buzzer, LOW); 110 | 111 | // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally 112 | if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64 113 | Serial.println(F("SSD1306 allocation failed")); 114 | for (;;); // Don't proceed, loop forever 115 | } 116 | 117 | initWifi(); 118 | 119 | digitalWrite(buzzer, LOW); 120 | 121 | } 122 | 123 | 124 | 125 | void loop() { 126 | // put your main code here, to run repeatedly: 127 | 128 | char customKey = customKeypad.getKey(); 129 | 130 | if (customKey) 131 | { 132 | Serial.println(customKey); 133 | 134 | // Maze Lock Mode 135 | if (customKey == 'A') 136 | { 137 | Serial.println("A"); 138 | Serial.println("Maze Lock Mode"); 139 | display.clearDisplay(); 140 | display.setTextSize(2); // Normal 1:1 pixel scale 141 | display.setTextColor(SSD1306_WHITE); // Draw white text 142 | display.setCursor(10, 0); // Start at top-left corner 143 | display.println(("Maze Lock")); 144 | display.setCursor(35, 30); 145 | display.println(("Mode")); 146 | display.display(); 147 | beep(200); 148 | beep(200); 149 | delay(1000); 150 | 151 | Serial.println("Enter the \nFour Digit \nCode"); 152 | 153 | fingerprint_flag = 0; 154 | } 155 | 156 | // Enrollment Mode 157 | if (customKey == 'C') 158 | { 159 | beep(200); 160 | if (Keypad_Input() == Secret_Code) 161 | { 162 | Serial.println("D"); 163 | Serial.println("Enrollment mode"); 164 | display.clearDisplay(); 165 | display.setTextSize(2); // Normal 1:1 pixel scale 166 | display.setTextColor(SSD1306_WHITE); // Draw white text 167 | display.setCursor(0, 0); // Start at top-left corner 168 | display.println(("Enrollment")); 169 | display.setCursor(35, 30); 170 | display.println(("Mode")); 171 | display.display(); 172 | beep(200); 173 | beep(200); 174 | delay(1000); 175 | Serial.println("Enter ID"); 176 | display.clearDisplay(); 177 | display.setTextSize(2); // Normal 1:1 pixel scale 178 | display.setTextColor(SSD1306_WHITE); // Draw white text 179 | display.setCursor(35, 20); // Start at top-left corner 180 | display.println(("ID XXX")); 181 | display.display(); 182 | ID_e = ""; 183 | i = 0; 184 | fingerprint_flag = 2; 185 | setup_e(); 186 | loop_e(); 187 | fingerprint_flag = 1; 188 | } 189 | else 190 | { 191 | Serial.println("Wrong Code"); 192 | display.clearDisplay(); 193 | display.setTextSize(2); // Normal 1:1 pixel scale 194 | display.setTextColor(SSD1306_WHITE); // Draw white text 195 | display.setCursor(0, 20); // Start at top-left corner 196 | display.println(("Wrong Code")); 197 | display.display(); 198 | beep(200); 199 | beep(200); 200 | delay(1000); 201 | } 202 | } 203 | } 204 | 205 | 206 | if (fingerprint_flag == 1) 207 | { 208 | finger.fingerID = 0; 209 | delay(50); 210 | setup_f(); 211 | loop_f(); 212 | display.clearDisplay(); 213 | display.drawBitmap(0, 0, logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, 1); 214 | display.display(); 215 | customKey = customKeypad.getKey(); 216 | switch (customKey) { 217 | case 'C': 218 | break; 219 | case 'A': 220 | break; 221 | } 222 | break; 223 | delay(1000); 224 | } 225 | 226 | 227 | if (fingerprint_flag == 0) 228 | { 229 | if (Keypad_Input() == Secret_Code) 230 | { 231 | Serial.println("Correct Code"); 232 | display.clearDisplay(); 233 | display.setTextSize(2); // Normal 1:1 pixel scale 234 | display.setTextColor(SSD1306_WHITE); // Draw white text 235 | display.setCursor(0, 20); // Start at top-left corner 236 | display.println(("Correct Code")); 237 | beep(1000); 238 | display.display(); 239 | Door_control(); 240 | ID = 200; 241 | makeIFTTTRequest(); 242 | 243 | delay(1000); 244 | 245 | fingerprint_flag = 1; 246 | } 247 | else 248 | { 249 | Serial.println("Wrong Code"); 250 | display.clearDisplay(); 251 | display.setTextSize(2); // Normal 1:1 pixel scale 252 | display.setTextColor(SSD1306_WHITE); // Draw white text 253 | display.setCursor(0, 20); // Start at top-left corner 254 | display.println(("Wrong Code")); 255 | display.display(); 256 | beep(200); 257 | beep(200); 258 | delay(1000); 259 | display.clearDisplay(); 260 | display.setTextSize(2); // Normal 1:1 pixel scale 261 | display.setTextColor(SSD1306_WHITE); // Draw white text 262 | display.setCursor(35, 20); // Start at top-left corner 263 | display.println(("Code")); 264 | display.display(); 265 | } 266 | ID_e = ""; 267 | } 268 | } 269 | 270 | 271 | // Establish a Wi-Fi connection with your router 272 | void initWifi() 273 | { 274 | Serial.print("Connecting to: "); 275 | Serial.print(ssid); 276 | display.clearDisplay(); 277 | 278 | display.setTextSize(2); // Normal 1:1 pixel scale 279 | display.setTextColor(SSD1306_WHITE); // Draw white text 280 | display.setCursor(0, 0); // Start at top-left corner 281 | display.println(("Connecting")); 282 | display.setCursor(0, 50); 283 | display.println((ssid)); 284 | display.display(); 285 | delay(2000); 286 | WiFi.begin(ssid, password); 287 | 288 | int timeout = 10 * 4; // 10 seconds 289 | while (WiFi.status() != WL_CONNECTED && (timeout-- > 0)) { 290 | delay(250); 291 | Serial.print("."); 292 | } 293 | Serial.println(""); 294 | 295 | if (WiFi.status() != WL_CONNECTED) { 296 | Serial.println("Failed to connect, going back to sleep"); 297 | display.clearDisplay(); 298 | display.setTextSize(2); // Normal 1:1 pixel scale 299 | display.setTextColor(SSD1306_WHITE); // Draw white text 300 | display.setCursor(0, 30); // Start at top-left corner 301 | display.println(("Not \nConnected")); 302 | display.display(); 303 | } 304 | else 305 | { 306 | Serial.print("WiFi connected in: "); 307 | Serial.print(millis()); 308 | Serial.print(", IP address: "); 309 | Serial.println(WiFi.localIP()); 310 | display.clearDisplay(); 311 | display.setTextSize(2); // Normal 1:1 pixel scale 312 | display.setTextColor(SSD1306_WHITE); // Draw white text 313 | display.setCursor(0, 30); // Start at top-left corner 314 | display.println(("Connected")); 315 | display.display(); 316 | } 317 | delay(2000); 318 | } 319 | --------------------------------------------------------------------------------