Components and supplies
5V arduino relay
Jumper wires (generic)
Breadboard (generic)
Arduino UNO
12V power supply
Apps and platforms
Arduino IDE
Project description
Code
Fingerprint + Lock
c_cpp
1#include <Adafruit_Fingerprint.h> 2 3// On Leonardo/Micro or others with hardware serial, use those! #0 is green wire, #1 is white 4// uncomment this line: 5// #define mySerial Serial1 6 7// For UNO and others without hardware serial, we must use software serial... 8// pin #2 is IN from sensor (GREEN wire) 9// pin #3 is OUT from arduino (WHITE wire) 10// comment these two lines if using hardware serial 11//MADE BY CRISTI 12 13SoftwareSerial mySerial(2, 3); 14 15Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); 16 17void setup() 18{ 19 pinMode(11,OUTPUT); 20 Serial.begin(9600); 21 while (!Serial); // For Yun/Leo/Micro/Zero/... 22 delay(100); 23 Serial.println("\ 24\ 25Adafruit finger detect test"); 26 27 // set the data rate for the sensor serial port 28 finger.begin(57600); 29 delay(5); 30 if (finger.verifyPassword()) { 31 Serial.println("Found fingerprint sensor!"); 32 } else { 33 Serial.println("Did not find fingerprint sensor :("); 34 while (1) { delay(1); } 35 } 36 37 finger.getTemplateCount(); 38 Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates"); 39 Serial.println("Waiting for valid finger..."); 40} 41 42void loop() // run over and over again 43{ 44 getFingerprintIDez(); 45 delay(50); //don't ned to run this at full speed. 46} 47 48uint8_t getFingerprintID() { 49 uint8_t p = finger.getImage(); 50 switch (p) { 51 case FINGERPRINT_OK: 52 digitalWrite(11,HIGH); 53 delay(5000); 54 digitalWrite(11,LOW); 55 Serial.println("Image taken"); 56 break; 57 case FINGERPRINT_NOFINGER: 58 Serial.println("No finger detected"); 59 return p; 60 case FINGERPRINT_PACKETRECIEVEERR: 61 Serial.println("Communication error"); 62 return p; 63 case FINGERPRINT_IMAGEFAIL: 64 Serial.println("Imaging error"); 65 return p; 66 default: 67 Serial.println("Unknown error"); 68 return p; 69 } 70 71 // OK success! 72 73 p = finger.image2Tz(); 74 switch (p) { 75 case FINGERPRINT_OK: 76 digitalWrite(11,HIGH); 77 delay(5000); 78 digitalWrite(11,LOW); 79 Serial.println("Image converted"); 80 break; 81 case FINGERPRINT_IMAGEMESS: 82 Serial.println("Image too messy"); 83 return p; 84 case FINGERPRINT_PACKETRECIEVEERR: 85 Serial.println("Communication error"); 86 return p; 87 case FINGERPRINT_FEATUREFAIL: 88 Serial.println("Could not find fingerprint features"); 89 return p; 90 case FINGERPRINT_INVALIDIMAGE: 91 Serial.println("Could not find fingerprint features"); 92 return p; 93 default: 94 Serial.println("Unknown error"); 95 return p; 96 } 97 98 // OK converted! 99 p = finger.fingerFastSearch(); 100 if (p == FINGERPRINT_OK) { 101 digitalWrite(11,HIGH); 102 delay(5000); 103 digitalWrite(11,LOW); 104 Serial.println("Found a print match!"); 105 } else if (p == FINGERPRINT_PACKETRECIEVEERR) { 106 Serial.println("Communication error"); 107 return p; 108 } else if (p == FINGERPRINT_NOTFOUND) { 109 Serial.println("Did not find a match"); 110 return p; 111 } else { 112 Serial.println("Unknown error"); 113 return p; 114 } 115 116 // found a match! 117 118 Serial.print("Found ID #"); 119 Serial.print("Found ID #"); Serial.print(finger.fingerID); 120 Serial.print(" with confidence of "); Serial.println(finger.confidence); 121 return finger.fingerID; 122 if (finger.fingerID == 1) { 123 digitalWrite(11,HIGH); 124 delay(5000); 125 digitalWrite(11,LOW); 126 } 127} 128 129// returns -1 if failed, otherwise returns ID # 130int getFingerprintIDez() { 131 uint8_t p = finger.getImage(); 132 if (p != FINGERPRINT_OK) return -1; 133 134 p = finger.image2Tz(); 135 if (p != FINGERPRINT_OK) return -1; 136 137 p = finger.fingerFastSearch(); 138 if (p != FINGERPRINT_OK) return -1; 139 140 p = finger.fingerFastSearch(); 141 if (p != FINGERPRINT_OK) { 142 digitalWrite(11,HIGH); 143 delay(5000); 144 digitalWrite(11,LOW); 145 } 146 147 // found a match! 148 Serial.print("Found ID #"); Serial.print(finger.fingerID); 149 Serial.print(" with confidence of "); Serial.println(finger.confidence); 150 return finger.fingerID; 151 152 153}
Comments
Only logged in users can leave comments
capotacristi594
0 Followers
•0 Projects
0