SHARE
TWEET

Untitled

omarkslab Sep 30th, 2019 130 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /***************************************************
  2.   This is an example sketch for our optical Fingerprint sensor
  3.  
  4.   Designed specifically to work with the Adafruit BMP085 Breakout
  5.   ----> http://www.adafruit.com/products/751
  6.  
  7.   These displays use TTL Serial to communicate, 2 pins are required to
  8.   interface
  9.   Adafruit invests time and resources providing this open source code,
  10.   please support Adafruit and open-source hardware by purchasing
  11.   products from Adafruit!
  12.  
  13.   Written by Limor Fried/Ladyada for Adafruit Industries.  
  14.   BSD license, all text above must be included in any redistribution
  15.  ****************************************************/
  16.  
  17.  
  18. #include <Adafruit_Fingerprint.h>
  19. #include <SoftwareSerial.h>
  20. #include <Servo.h> //Add servo library
  21.  
  22. int getFingerprintIDez();
  23.  
  24. Servo servo1; //Define servo name / object
  25.  
  26. #define servoPin 9 //Define pin number to which servo motor is connected
  27. #define durationTime 3000 //Define the time it remains in the open position of the door lock (miliseconds)
  28. #define servoMin 0 //Open position
  29. #define servoMax 90 // Closed position
  30.  
  31.  
  32. SoftwareSerial mySerial(2, 3);
  33. Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
  34.  
  35.  
  36. void setup()  
  37. {
  38.   while (!Serial);  // For Yun/Leo/Micro/Zero/...
  39.  
  40.   Serial.begin(9600);
  41.   Serial.println("Adafruit finger detect test");
  42.  
  43.   servo1.attach(servoPin); //Define pin number of the servo
  44.   servo1.write(servoMax); //The position of the servo at the start of the program
  45.  
  46.   // set the data rate for the sensor serial port
  47.   finger.begin(57600);
  48.  
  49.   if (finger.verifyPassword()) {
  50.     Serial.println("Found fingerprint sensor!");
  51.   } else {
  52.     Serial.println("Did not find fingerprint sensor :(");
  53.     while (1);
  54.   }
  55.   Serial.println("Waiting for valid finger...");
  56. }
  57.  
  58. void loop()                     // run over and over again
  59. {
  60.   getFingerprintIDez();
  61.   delay(50);            //don't ned to run this at full speed.
  62. }
  63.  
  64. uint8_t getFingerprintID() {
  65.   uint8_t p = finger.getImage();
  66.   switch (p) {
  67.     case FINGERPRINT_OK:
  68.       Serial.println("Image taken");
  69.       break;
  70.     case FINGERPRINT_NOFINGER:
  71.       Serial.println("No finger detected");
  72.       return p;
  73.     case FINGERPRINT_PACKETRECIEVEERR:
  74.       Serial.println("Communication error");
  75.       return p;
  76.     case FINGERPRINT_IMAGEFAIL:
  77.       Serial.println("Imaging error");
  78.       return p;
  79.     default:
  80.       Serial.println("Unknown error");
  81.       return p;
  82.   }
  83.  
  84.   // OK success!
  85.  
  86.   p = finger.image2Tz();
  87.   switch (p) {
  88.     case FINGERPRINT_OK:
  89.       Serial.println("Image converted");
  90.       break;
  91.     case FINGERPRINT_IMAGEMESS:
  92.       Serial.println("Image too messy");
  93.       return p;
  94.     case FINGERPRINT_PACKETRECIEVEERR:
  95.       Serial.println("Communication error");
  96.       return p;
  97.     case FINGERPRINT_FEATUREFAIL:
  98.       Serial.println("Could not find fingerprint features");
  99.       return p;
  100.     case FINGERPRINT_INVALIDIMAGE:
  101.       Serial.println("Could not find fingerprint features");
  102.       return p;
  103.     default:
  104.       Serial.println("Unknown error");
  105.       return p;
  106.   }
  107.  
  108.   // OK converted!
  109.   p = finger.fingerFastSearch();
  110.   if (p == FINGERPRINT_OK) {
  111.     Serial.println("Found a print match!");
  112.   } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
  113.     Serial.println("Communication error");
  114.     return p;
  115.   } else if (p == FINGERPRINT_NOTFOUND) {
  116.     Serial.println("Did not find a match");
  117.     return p;
  118.   } else {
  119.     Serial.println("Unknown error");
  120.     return p;
  121.   }  
  122.  
  123.   // found a match!
  124.   Serial.print("Found ID #"); Serial.print(finger.fingerID);
  125.   Serial.print(" with confidence of "); Serial.println(finger.confidence);
  126. }
  127.  
  128. // returns -1 if failed, otherwise returns ID #
  129. int getFingerprintIDez() {
  130.   uint8_t p = finger.getImage();
  131.   if (p != FINGERPRINT_OK)  return -1;
  132.  
  133.   p = finger.image2Tz();
  134.   if (p != FINGERPRINT_OK)  return -1;
  135.  
  136.   p = finger.fingerFastSearch();
  137.   if (p != FINGERPRINT_OK)  return -1;
  138.  
  139.   servo1.write(servoMin); //If the fingerprint is correct open the door lock
  140.   delay(durationTime); //Keep the lock open for the defined duration
  141.   servo1.write(servoMax); //take the lock OFF again
  142.  
  143.  
  144.   // found a match!
  145.   Serial.print("Found ID #"); Serial.print(finger.fingerID);
  146.   Serial.print(" with confidence of "); Serial.println(finger.confidence);
  147.   return finger.fingerID;
  148. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top