Fingerprint door lock based on Arduino and FPM10A optical fingerprint sensor
Hello, and welcome to this project, actually it includes two projects but they’re pretty much the same, it’s a door lock system based on an Arduino UNO board, FPM10A optical fingerprint sensor and a LCD iĀ²c screen, but for the other version we include a keypad. Check below, you’ll find links that help you start with different modules used here
Different modules we’ll use for this project
And sure don’t forget about the locking system that you’re willing to control, and following this your wiring and codes may change but don’t worry it would be easy.
That’s the system I’m using, I bought it for 10$ from Aliexpress as always, but here I’m only using the lock unit and not the included keypad.
So the system has a DC motor inside, and should be controlled to turn clockwise and anti-clock wise since it doesn’t have a return spring, that’s why in my project I add a L298n H-Bridge module, you can use a little IC H-Bridge it will be nice, but I had to use what I have in my hand for the moment.
You can use a solenoid lock instead of the mechanism seen above, and control it by a transistor from the Arduino, your wiring then will need only one pin to control the transistor and a fewer lines.
Without further ado… know how your system works and adapt it.
Before you continue make sure you know how to use all the elements mentioned above, as it will make your project easy to adapt and spot any problem:
- Arduino uno + 4Ć4 Keypad Matrix + LCD i2c screen
- Interfacing FPM10A (50DY) Fingerprint sensor with Arduino
- Arduino LCD I2C simple use and direct write from serial monitor
- Step by step on how to use the L298n dual H-bridge driver with Arduino
Version 1:
The first version uses: LCD + fingerprint sensor + l298n (to control the system) + push button with a resistor (I used 1k).
For the first version, you need to upload the “Enroll” code first from the fingerprint library (down bellow), and use it to add a fingerprint, upload it and open the serial monitor then type the ID and press “Enter” then follow the steps as in the fingerprint tutorial. Then upload the second code and add the names you want for each user, upload the code and here we go, the fingerprint templates are stored in the modules internal flash drive.
Once the code begin working, the Arduino is constantly waiting for a finger to place on the sensor, otherwise if you’re inside just press the button to open, if the finger is valid (is in the database) it will opens the lock and shows a message and the name related to the fingerprint ID, if the ID isn’t paired with a name it will show some strange things :D…
Wiring:
Ā Ā Ā Ā Ā That’s pretty much my wiring, so you won’t be confused by the push button, actually instead of getting the high level from the Arduino 5v pin which requires me to add other wires (and it will be more messy) I just put the pin 8 on High and I read the button state from pin 9 which has a pull-down resistor.
Version 2:
Ā Ā Ā Ā Ā Ā Ā As you can see in the 1st version you have to use a computer (or whatever you use to program you Arduino) in order to add new templates to the module flash drive, that’s why I made this more embedded version that requires only power source to work, and the new templates are now added via a keypad (which meant to stay on the inside as this project is based on access by fingerprint only, you can combine it withĀ my other project based on keypad only, you’ll have to do some modification but they’re easy).
Ā Ā Ā Ā Ā The keypad is placed inside which means you can open the lock by pressing a button here I’ve chosed ‘B’ as ‘A’ is for adding a new person.
Ā Ā Ā Ā Ā Ā Ā Ā To add new finger template press ‘A’ it will ask you for password that’s already in the code ‘1’ ‘2’ ‘3’ ‘4’, you can modify it there, you enter the code then you enter the ID number as a 3 digits format, examples “001” , “021” or “115” you can enter IDs from 1 to 127, after tapping the ID it will ask you to place the finger, remove it and place it again…Job done.
And as the first version it waits for a valid fingerprint to open the lock.
Wiring:
Ā Ā Ā This is the wiring for the second version, I removed the push button as the opening from inside is done now by ‘B’ button, as of course the keypad unit stays inside and it serves to enroll new fingerprints.
Libraries:
- Download LCD i2c NewLiquidCrystal library.
- Download keypad library.
- Download FPM10A optical fingerprint sensor from Github Or download it here.
Codes:
Code 1: Scanner i2c
Download i2c Scanner in case you have a different address for your LCD.
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 |
#include <Wire.h> void setup() { Wire.begin(); Serial.begin(9600); while (!Serial); //wait for serial monitor Serial.println("\nI2C Scanner"); } void loop() { byte error, address; int nDevices; Serial.println("Scanning..."); nDevices = 0; for(address = 1; address < 127; address++ ) { // The i2c_scanner uses the return value of // the Write.endTransmisstion to see if // a device did acknowledge to the address. Wire.beginTransmission(address); error = Wire.endTransmission(); if (error == 0) { Serial.print("I2C device found at address 0x"); if (address<16) Serial.print("0"); Serial.print(address,HEX); Serial.println(" !"); nDevices++; } else if (error==4) { Serial.print("Unknow error at address 0x"); if (address<16) Serial.print("0"); Serial.println(address,HEX); } } if (nDevices == 0) Serial.println("No I2C devices found\n"); else Serial.println("done\n"); delay(5000); // wait 5 seconds for next scan } |
Code 2: FPM10A Fingerprint sensor library example – Enroll
As you can see in the video tutorial, this code serves to add new fingerprint templates to the sensor memory.
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 |
/*************************************************** This is an example sketch for our optical Fingerprint sensor Designed specifically to work with the Adafruit BMP085 Breakout These displays use TTL Serial to communicate, 2 pins are required to interface Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Written by Limor Fried/Ladyada for Adafruit Industries. BSD license, all text above must be included in any redistribution ****************************************************/ #include <Adafruit_Fingerprint.h> #if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__) // For UNO and others without hardware serial, we must use software serial... // pin #2 is IN from sensor (GREEN wire) // pin #3 is OUT from arduino (WHITE wire) // Set up the serial port to use softwareserial.. SoftwareSerial mySerial(2, 3); #else // On Leonardo/M0/etc, others with hardware serial, use hardware serial! // #0 is green wire, #1 is white #define mySerial Serial1 #endif Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); uint8_t id; void setup() { Serial.begin(9600); while (!Serial); // For Yun/Leo/Micro/Zero/... delay(100); Serial.println("\n\nAdafruit Fingerprint sensor enrollment"); // set the data rate for the sensor serial port finger.begin(57600); if (finger.verifyPassword()) { Serial.println("Found fingerprint sensor!"); } else { Serial.println("Did not find fingerprint sensor :("); while (1) { delay(1); } } Serial.println(F("Reading sensor parameters")); finger.getParameters(); Serial.print(F("Status: 0x")); Serial.println(finger.status_reg, HEX); Serial.print(F("Sys ID: 0x")); Serial.println(finger.system_id, HEX); Serial.print(F("Capacity: ")); Serial.println(finger.capacity); Serial.print(F("Security level: ")); Serial.println(finger.security_level); Serial.print(F("Device address: ")); Serial.println(finger.device_addr, HEX); Serial.print(F("Packet len: ")); Serial.println(finger.packet_len); Serial.print(F("Baud rate: ")); Serial.println(finger.baud_rate); } uint8_t readnumber(void) { uint8_t num = 0; while (num == 0) { while (! Serial.available()); num = Serial.parseInt(); } return num; } void loop() // run over and over again { Serial.println("Ready to enroll a fingerprint!"); Serial.println("Please type in the ID # (from 1 to 127) you want to save this finger as..."); id = readnumber(); if (id == 0) {// ID #0 not allowed, try again! return; } Serial.print("Enrolling ID #"); Serial.println(id); while (! getFingerprintEnroll() ); } uint8_t getFingerprintEnroll() { int p = -1; Serial.print("Waiting for valid finger to enroll as #"); Serial.println(id); while (p != FINGERPRINT_OK) { p = finger.getImage(); switch (p) { case FINGERPRINT_OK: Serial.println("Image taken"); break; case FINGERPRINT_NOFINGER: Serial.println("."); break; case FINGERPRINT_PACKETRECIEVEERR: Serial.println("Communication error"); break; case FINGERPRINT_IMAGEFAIL: Serial.println("Imaging error"); break; default: Serial.println("Unknown error"); break; } } // OK success! p = finger.image2Tz(1); switch (p) { case FINGERPRINT_OK: Serial.println("Image converted"); break; case FINGERPRINT_IMAGEMESS: Serial.println("Image too messy"); return p; case FINGERPRINT_PACKETRECIEVEERR: Serial.println("Communication error"); return p; case FINGERPRINT_FEATUREFAIL: Serial.println("Could not find fingerprint features"); return p; case FINGERPRINT_INVALIDIMAGE: Serial.println("Could not find fingerprint features"); return p; default: Serial.println("Unknown error"); return p; } Serial.println("Remove finger"); delay(2000); p = 0; while (p != FINGERPRINT_NOFINGER) { p = finger.getImage(); } Serial.print("ID "); Serial.println(id); p = -1; Serial.println("Place same finger again"); while (p != FINGERPRINT_OK) { p = finger.getImage(); switch (p) { case FINGERPRINT_OK: Serial.println("Image taken"); break; case FINGERPRINT_NOFINGER: Serial.print("."); break; case FINGERPRINT_PACKETRECIEVEERR: Serial.println("Communication error"); break; case FINGERPRINT_IMAGEFAIL: Serial.println("Imaging error"); break; default: Serial.println("Unknown error"); break; } } // OK success! p = finger.image2Tz(2); switch (p) { case FINGERPRINT_OK: Serial.println("Image converted"); break; case FINGERPRINT_IMAGEMESS: Serial.println("Image too messy"); return p; case FINGERPRINT_PACKETRECIEVEERR: Serial.println("Communication error"); return p; case FINGERPRINT_FEATUREFAIL: Serial.println("Could not find fingerprint features"); return p; case FINGERPRINT_INVALIDIMAGE: Serial.println("Could not find fingerprint features"); return p; default: Serial.println("Unknown error"); return p; } // OK converted! Serial.print("Creating model for #"); Serial.println(id); p = finger.createModel(); if (p == FINGERPRINT_OK) { Serial.println("Prints matched!"); } else if (p == FINGERPRINT_PACKETRECIEVEERR) { Serial.println("Communication error"); return p; } else if (p == FINGERPRINT_ENROLLMISMATCH) { Serial.println("Fingerprints did not match"); return p; } else { Serial.println("Unknown error"); return p; } Serial.print("ID "); Serial.println(id); p = finger.storeModel(id); if (p == FINGERPRINT_OK) { Serial.println("Stored!"); } else if (p == FINGERPRINT_PACKETRECIEVEERR) { Serial.println("Communication error"); return p; } else if (p == FINGERPRINT_BADLOCATION) { Serial.println("Could not store in that location"); return p; } else if (p == FINGERPRINT_FLASHERR) { Serial.println("Error writing to flash"); return p; } else { Serial.println("Unknown error"); return p; } return true; } |
Code 3: Version 1
Code for the version 1: Download here or check below.
The code I made for the first version is based on “Fingerprint” example from the library just instead of showing the ID on the Serial monitor (which means that the finger print template is in the database) it triggers the whole opening sequence otherwise (which means that the module failed to find match in the database) it shows a simple message on the screen.
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 |
/* This code works with FPM10A optical fingerprint sensor + LCD i2c screen + L298n and a push button * It's main function is to scan a fingerprint then trigger the opening lock sequence if the finger is recognized * It's based on the "fingerprint" example from the Adafruit_fingerprint library * Refer to http://www.SurtrTech.com for more details * The L298n H-bridge module is required for the door lock type used you could need something else */ #include <Adafruit_Fingerprint.h> //Libraries needed #include <SoftwareSerial.h> #include <LCD.h> #include <LiquidCrystal_I2C.h> #define I2C_ADDR 0x27 //LCD i2c stuff #define BACKLIGHT_PIN 3 #define En_pin 2 #define Rw_pin 1 #define Rs_pin 0 #define D4_pin 4 #define D5_pin 5 #define D6_pin 6 #define D7_pin 7 int in1 = 5; // In1 and In2 for the L298n H bridge module int in2 = 4; int But1=8; // In order to add a push button I got the 5v from the pin 8 instead of "5v" arduino pin int But2=9; String Names[] = { "Yassine", "Surtr", "Tech",}; //Those are the names affected to the fingertemplates IDs //The first on which is Names[0] : Yassine has the ID 1 in the fingerprint sensor SoftwareSerial mySerial(2, 3); //Fingerprint sensor wiring RX 3, TX 2 LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin); //LCD declaring Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); //Fingerprint sensor declaring void setup() { pinMode(in1, OUTPUT); pinMode(in2, OUTPUT); pinMode(But1, OUTPUT); //Push button stuff, I made the pin 8 permanent HIGH level digitalWrite(But1,HIGH); pinMode(But2,INPUT); //And I read the button state on pin 9 Serial.begin(9600); //Serial begin incase you need to see something on the serial monitor finger.begin(57600); //Sensor baude rate lcd.begin (16,2); lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); lcd.setBacklight(HIGH); lcd.home (); finger.getTemplateCount(); //Counts the number of templates stored in the sensor flash memory delay(2000); lcd.setCursor(0,0); lcd.print("Place finger"); CloseDoor(); //As we don't know the state of the lock system, first we make sure it's closed } void loop() { getFingerprintIDez(); //This function keeps looping and waiting for a fingerprint to be put on the sensor delay(50); bool Button1=digitalRead(But2); //Reading the state of the pushbutton if(Button1==HIGH){ //If the button is pressed it opens the doorlock as the button is meant to be inside OpenDoor(); //And once more it depends on your system, mine requires an electrical signal to open delay(5000); //Opening delay 5s CloseDoor(); //Closing sequence requires electrical signal otherwise it stays open } } //Main function taken from the "fingerprint" example and modified //Only the modifications are commented int getFingerprintIDez() { uint8_t p = finger.getImage(); //Image scanning if (p != FINGERPRINT_OK) return -1; p = finger.image2Tz(); //Converting if (p != FINGERPRINT_OK) return -1; p = finger.fingerFastSearch(); //Looking for matches in the internal memory if (p != FINGERPRINT_OK){ //if the searching fails it means that the template isn't registered lcd.clear(); //And here we write a message or take an action for the denied template lcd.print("Access denied"); delay(2000); lcd.clear(); lcd.print("Place finger"); return -1; } //If we found a match we proceed in the function lcd.clear(); lcd.print("Welcome"); //Printing a message for the recognized template lcd.setCursor(2,1); lcd.print(Names[finger.fingerID-1]); //Then print the name we gave it and the -1 is to remove the shift as the ID starts from "1" but the array from "0" OpenDoor(); //Opening and closing sequence delay(5000); CloseDoor(); lcd.clear(); lcd.print("Place finger"); return finger.fingerID; } /*The two following functions depends on your locking system *mine has a DC motor that should turn in both ways for opening and closing *that's why I'm using H bridge, you could have a solenoid with a transistor *then you'll need only opening sequence but controlling the transistor *as the closing is spring loaded... */ void OpenDoor(){ digitalWrite(in1, LOW); //Turn in a direction for 100ms and stops digitalWrite(in2, HIGH); //it's not the delay for the whole sequence delay(100); // the sequence delay is above (5000) 5s digitalWrite(in1, LOW); //If I stop the motor, the lock holds its place either open or closed digitalWrite(in2, LOW); } void CloseDoor(){ digitalWrite(in1, HIGH); //Turn in other direction for 100ms and stops digitalWrite(in2, LOW); delay(100); digitalWrite(in1, LOW); digitalWrite(in2, LOW); } |
Code 4: Version 2
Code for Version 2: Download here or check below.
The code for the second version is based on both “Fingerprint” and “Enroll” examples, and just like the first version but this time I added the “Enrolling” feature and you can add the ID from the keypad instead of the Serial monitor.
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 |
/* This code works with FPM10A optical fingerprint sensor + LCD i2c screen + L298n and a 4*4 Keypad matrix * It's main function is to scan a fingerprint then trigger the opening lock sequence if the finger is recognized * And add new finger templates if the user is willing to by intriducing a password * It's based on the "fingerprint" and "Enroll" examples from the Adafruit_fingerprint library * Refer to http://www.SurtrTech.com for more details * The L298n H-bridge module is required for the door lock type used you could need something else */ #include <Adafruit_Fingerprint.h> //Libraries needed #include <SoftwareSerial.h> #include <Keypad.h> #include <LiquidCrystal_I2C.h> #define I2C_ADDR 0x27 //defining the LCD pins #define BACKLIGHT_PIN 3 #define En_pin 2 #define Rw_pin 1 #define Rs_pin 0 #define D4_pin 4 #define D5_pin 5 #define D6_pin 6 #define D7_pin 7 LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin); SoftwareSerial mySerial(2, 3); //Fingerprint sensor wiring RX 3, TX 2 const byte numRows= 4; //number of rows on the keypad const byte numCols= 4; //number of columns on the keypad char keypressed; char code[]={'1','2','3','4'}; //Passcode needed you can change it just keep the format "4 digits as char array" char c[4]; //Array to get the code from the user int ij; int in1 = 5; // In1 and In2 for the L298n H bridge module int in2 = 4; //keymap defines the key pressed according to the row and columns just as appears on the keypad char keymap[numRows][numCols]= { {'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', 'C'}, {'*', '0', '#', 'D'} }; byte rowPins[numRows] = {13,12,11,10}; //Rows 0 to 3 //if you modify your pins you should modify this too byte colPins[numCols]= {9,8,7,6}; //Columns 0 to 3 //initializes an instance of the Keypad class Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols); Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); uint8_t id; void setup() { Serial.begin(9600); pinMode(in1, OUTPUT); //L298n H bridge pinmodes pinMode(in2, OUTPUT); finger.begin(57600); lcd.begin (16,2); lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); lcd.setBacklight(HIGH); lcd.home (); lcd.clear(); lcd.print("Standby"); delay(2000); } void loop() { getFingerprintIDez(); //Waiting for a fingerprint to scan if it's valid or not keypressed = myKeypad.getKey(); //Reading the buttons typed by the keypad if(keypressed == 'A'){ //If it's 'A' it triggers "Adding new template" sequence ij=0; //ij is set to 0 lcd.clear(); lcd.setCursor(0,0); lcd.print("Enter Password"); getPassword(); //Getting the passcode function if(ij==4){ //If the passcode is correct we can start enrolling new finger template Enrolling(); //Enrolling function delay(2000); lcd.clear(); } else{ //If the code is wrong we can't add new users (templates) lcd.setCursor(0,0); lcd.print("Wrong code"); delay(2000); lcd.clear(); } } if(keypressed == 'B') //As the keypad is meant to stay inside the 'B' button opens the door lock { //Because the system I used needs an electrical signal to open OpenDoor(); delay(5000); //Opening delay CloseDoor(); } lcd.setCursor(0,0); lcd.print("Place finger"); //Constant showing message delay(50); } //Getting password (code) function, it gets the characters typed //and store them in c[4] array void getPassword(){ for (int i=0 ; i<4 ; i++){ c[i]= myKeypad.waitForKey(); lcd.setCursor(i,1); lcd.print("*"); } lcd.clear(); for (int j=0 ; j<4 ; j++){ //comparing the code entred with the code stored if(c[j]==code[j]) ij++; //Everytime the char is correct we increment the ij until it reaches 4 which means the code is correct } //Otherwise it won't reach 4 and it will show "wrong code" as written above } //The Enrolling and getFingerprintEnroll functions are mainly based on the "Enroll" example code from the library //Only the modifications will be commented, return to the example to see each step in details, as here it's shortened void Enrolling() { keypressed = NULL; lcd.clear(); lcd.print("Enroll New"); delay(2000); lcd.clear(); lcd.setCursor(0,0); lcd.print("Enter new ID"); id = readnumber(); //This function gets the Id it was meant to get it from the Serial monitor but we modified it if (id == 0) {// ID #0 not allowed, try again! return; } while (! getFingerprintEnroll() ); } //Enrolling function only the modifications are commented uint8_t getFingerprintEnroll() { int p = -1; lcd.clear(); lcd.print("Enroll ID:"); //Message to print for every step lcd.setCursor(10,0); lcd.print(id); lcd.setCursor(0,1); lcd.print("Place finger"); //First step while (p != FINGERPRINT_OK) { p = finger.getImage(); } // OK success! p = finger.image2Tz(1); switch (p) { case FINGERPRINT_OK: break; case FINGERPRINT_IMAGEMESS: return p; case FINGERPRINT_PACKETRECIEVEERR: return p; case FINGERPRINT_FEATUREFAIL: return p; case FINGERPRINT_INVALIDIMAGE: return p; default: return p; } lcd.clear(); lcd.setCursor(0,0); lcd.print("Remove finger"); //After getting the first template successfully lcd.setCursor(0,1); lcd.print("please !"); delay(2000); p = 0; while (p != FINGERPRINT_NOFINGER) { p = finger.getImage(); } p = -1; lcd.clear(); lcd.setCursor(0,0); lcd.print("Place same"); //We launch the same thing another time to get a second template of the same finger lcd.setCursor(0,1); lcd.print("finger please"); while (p != FINGERPRINT_OK) { p = finger.getImage(); } // OK success! p = finger.image2Tz(2); switch (p) { case FINGERPRINT_OK: break; case FINGERPRINT_IMAGEMESS: return p; case FINGERPRINT_PACKETRECIEVEERR: return p; case FINGERPRINT_FEATUREFAIL: return p; case FINGERPRINT_INVALIDIMAGE: return p; default: return p; } p = finger.createModel(); if (p == FINGERPRINT_OK) { } else if (p == FINGERPRINT_PACKETRECIEVEERR) { return p; } else if (p == FINGERPRINT_ENROLLMISMATCH) { return p; } else { return p; } p = finger.storeModel(id); if (p == FINGERPRINT_OK) { lcd.clear(); //if both images are gotten without problem we store the template as the Id we entred lcd.setCursor(0,0); lcd.print("Stored in"); //Print a message after storing and showing the ID where it's stored lcd.setCursor(0,1); lcd.print("ID: "); lcd.setCursor(5,1); lcd.print(id); delay(3000); lcd.clear(); } else if (p == FINGERPRINT_PACKETRECIEVEERR) { return p; } else if (p == FINGERPRINT_BADLOCATION) { return p; } else if (p == FINGERPRINT_FLASHERR) { return p; } else { return p; } } //This function gets the ID number as 3 digits format like 001 for ID 1 //And return the number to the enrolling function uint8_t readnumber(void) { uint8_t num = 0; while (num == 0) { char keey = myKeypad.waitForKey(); int num1 = keey-48; lcd.setCursor(0,1); lcd.print(num1); keey = myKeypad.waitForKey(); int num2 = keey-48; lcd.setCursor(1,1); lcd.print(num2); keey = myKeypad.waitForKey(); int num3 = keey-48; lcd.setCursor(2,1); lcd.print(num3); delay(1000); num=(num1*100)+(num2*10)+num3; keey=NO_KEY; } return num; } //Main function taken from the "fingerprint" example and modified //Only the modifications are commented //This function waits for a fingerprint, scan it and give it access if recognised int getFingerprintIDez() { uint8_t p = finger.getImage(); //Image scanning if (p != FINGERPRINT_OK) return -1; p = finger.image2Tz(); //Converting if (p != FINGERPRINT_OK) return -1; p = finger.fingerFastSearch(); //Looking for matches in the internal memory if (p != FINGERPRINT_OK){ //if the searching fails it means that the template isn't registered lcd.clear(); //And here we write a message or take an action for the denied template lcd.print("Access denied"); delay(2000); lcd.clear(); lcd.print("Place finger"); return -1; } //If we found a match we proceed in the function lcd.clear(); lcd.print("Welcome"); //Printing a message for the recognized template lcd.setCursor(2,1); lcd.print("ID: "); lcd.setCursor(5,1); lcd.print(finger.fingerID); //And the ID of the finger template OpenDoor(); delay(5000); CloseDoor(); lcd.clear(); lcd.print("Place finger"); return finger.fingerID; } /*The two following functions depends on your locking system *mine has a DC motor that should turn in both ways for opening and closing *that's why I'm using H bridge, you could have a solenoid with a transistor *then you'll need only opening sequence but controlling the transistor *as the closing is spring loaded... */ void OpenDoor(){ digitalWrite(in1, LOW); //Turn in a direction for 100ms and stops digitalWrite(in2, HIGH); //it's not the delay for the whole sequence delay(100); // the sequence delay is above (5000) 5s digitalWrite(in1, LOW); //If I stop the motor, the lock holds its place either open or closed digitalWrite(in2, LOW); } void CloseDoor(){ digitalWrite(in1, HIGH); //Turn in other direction for 100ms and stops digitalWrite(in2, LOW); delay(100); digitalWrite(in1, LOW); digitalWrite(in2, LOW); } |
Possible improvements:
Codes are made the simple way as I’m a beginner, so they should be clear for anyone willing to improve it like entering the password it could be more secure as the user should enter a more than 4 digits or less, and the validation can be done with a button then it’s compared to the code programmed… Also you can add the deleting a template sequence, just like adding, press a button -> password -> and type the ID.
Also you can add a buzzer to ring or as an Alarm, or a PIR sensor to turn on the the system whenever a person is near the door…
Hope you like it and if there’s any problem you can contact me, don’t forget to consider a subscribe to the channel.
Categories
Yassine View All
Automation and Electrical Engineer, Electronics amateur trying to share my little projects.
there is so much of error is coming
Make sure you installed the libraries correctly and don’t have two or more with the same name.
enroll code i m unable to find out .
kind send me the link of enroll code.
Hello, the enroll code is already in the FPM10A library examples.