safwan092

fingerprint-code-working

Mar 7th, 2021
532
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Adafruit_Fingerprint.h>
  2. int getFingerprintIDez();
  3. // pin #2 is IN from sensor (GREEN wire)
  4. // pin #3 is OUT from arduino  (WHITE wire)
  5. SoftwareSerial mySerial(2, 3);
  6. Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
  7. void setup()
  8. {
  9.   Serial.begin(9600);
  10.   Serial.println("fingertest");
  11.   pinMode(13, OUTPUT);
  12.   digitalWrite(13, LOW);
  13.   // set the data rate for the sensor serial port
  14.   finger.begin(57600);
  15.   if (finger.verifyPassword()) {
  16.     Serial.println("Found fingerprint sensor!");
  17.   } else {
  18.     Serial.println("Did not find fingerprint sensor : (");
  19.                    while (1);
  20.   }
  21. Serial.println("Waiting for valid finger…");
  22. }
  23. void loop()                     // run over and over again
  24. {
  25.   getFingerprintIDez();
  26.   delay(50);            //don’t ned to run this at full speed.
  27. }
  28. uint8_t getFingerprintID() {
  29.   uint8_t p = finger.getImage();
  30.   switch (p) {
  31.     case FINGERPRINT_OK:
  32.       Serial.println("Image taken");
  33.       break;
  34.     case FINGERPRINT_NOFINGER:
  35.       Serial.println("No finger detected");
  36.       return p;
  37.     case FINGERPRINT_PACKETRECIEVEERR:
  38.       Serial.println("Communication error");
  39.       return p;
  40.     case FINGERPRINT_IMAGEFAIL:
  41.       Serial.println("Imaging error");
  42.       return p;
  43.     default:
  44.       Serial.println("Unknown error");
  45.       return p;
  46.   }
  47.   // OK success!
  48.   p = finger.image2Tz();
  49.   switch (p) {
  50.     case FINGERPRINT_OK:
  51.       Serial.println("Image converted");
  52.       break;
  53.     case FINGERPRINT_IMAGEMESS:
  54.       Serial.println("Image too messy");
  55.       return p;
  56.     case FINGERPRINT_PACKETRECIEVEERR:
  57.       Serial.println("Communication error");
  58.       return p;
  59.     case FINGERPRINT_FEATUREFAIL:
  60.       Serial.println("Could not find fingerprint features");
  61.       return p;
  62.     case FINGERPRINT_INVALIDIMAGE:
  63.       Serial.println("Could not find fingerprint features");
  64.       return p;
  65.     default:
  66.       Serial.println("Unknown error");
  67.       return p;
  68.   }
  69.   // OK converted!
  70.   p = finger.fingerFastSearch();
  71.   if (p == FINGERPRINT_OK) {
  72.     Serial.println("Found a print match!");
  73.   } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
  74.     Serial.println("Communication error");
  75.     return p;
  76.   } else if (p == FINGERPRINT_NOTFOUND) {
  77.     Serial.println("Did not find a match");
  78.     return p;
  79.   } else {
  80.     Serial.println("Unknown error");
  81.     return p;
  82.   }
  83.   // found a match!
  84.   Serial.print("Found ID #"); Serial.print(finger.fingerID);
  85.   Serial.print(" with confidence of "); Serial.println(finger.confidence);
  86. }
  87. // returns -1 if failed, otherwise returns ID #
  88. int getFingerprintIDez() {
  89.   uint8_t p = finger.getImage();
  90.   if (p != FINGERPRINT_OK)  return -1;
  91.   p = finger.image2Tz();
  92.   if (p != FINGERPRINT_OK)  return -1;
  93.   p = finger.fingerFastSearch();
  94.   if (p != FINGERPRINT_OK)  return -1;
  95.   // found a match!
  96.   Serial.print("Found ID #"); Serial.print(finger.fingerID);
  97.   Serial.print(" with confidence of "); Serial.println(finger.confidence);
  98.   digitalWrite(13, HIGH);
  99.   delay(3000);
  100.   digitalWrite(13, LOW);
  101.   return finger.fingerID;
  102. }
RAW Paste Data