Advertisement
Guest User

Source Code

a guest
Jul 24th, 2016
2,864
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.44 KB | None | 0 0
  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<stdint.h>
  21.  
  22. int getFingerprintIDez();
  23.  
  24. int pinRelay =12;
  25. //DECLARE SOLENOID
  26. const int relay1Pin = 7;
  27. //DECLARE BUZZER
  28. const int relay2Buz = 8;
  29.  
  30. // pin #2 is IN from sensor (GREEN wire)
  31. // pin #3 is OUT from arduino (WHITE wire)
  32. SoftwareSerial mySerial(A1, A2);
  33. Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
  34.  
  35. // On Leonardo/Micro or others with hardware serial, use those! #0 is green wire, #1 is white
  36. //Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial1);
  37.  
  38. void setup()
  39. {
  40. while (!Serial); // For Yun/Leo/Micro/Zero/...
  41.  
  42. Serial.begin(9600);
  43. Serial.println("Adafruit finger detect test");
  44.  
  45. // set the data rate for the sensor serial port
  46. finger.begin(57600);
  47.  
  48. // SET PIN AS OUTPUT
  49. pinMode(pinRelay, OUTPUT);
  50. pinMode(relay1Pin, OUTPUT);
  51. pinMode(relay2Buz, OUTPUT);
  52. //DEACTIVATE THE BUZZER
  53. digitalWrite(relay2Buz,LOW);
  54. //LOCK THE SOLENOID
  55. digitalWrite(relay1Pin, HIGH);
  56.  
  57.  
  58. if (finger.verifyPassword()) {
  59. Serial.println("Found fingerprint sensor!");
  60. } else {
  61. Serial.println("Did not find fingerprint sensor :(");
  62. while (1);
  63. }
  64. Serial.println("Waiting for valid finger...");
  65. }
  66.  
  67. void loop() // run over and over again
  68. {
  69. getFingerprintIDez();
  70. delay(50); //don't ned to run this at full speed.
  71. }
  72.  
  73. uint8_t getFingerprintID() {
  74. uint8_t p = finger.getImage();
  75. switch (p) {
  76. case FINGERPRINT_OK:
  77. Serial.println("Image taken");
  78. break;
  79. case FINGERPRINT_NOFINGER:
  80. Serial.println("No finger detected");
  81. return p;
  82. case FINGERPRINT_PACKETRECIEVEERR:
  83. Serial.println("Communication error");
  84. return p;
  85. case FINGERPRINT_IMAGEFAIL:
  86. Serial.println("Imaging error");
  87. return p;
  88. default:
  89. Serial.println("Unknown error");
  90. return p;
  91. }
  92.  
  93. // OK success!
  94.  
  95. p = finger.image2Tz();
  96. switch (p) {
  97. case FINGERPRINT_OK:
  98. Serial.println("Image converted");
  99. break;
  100. case FINGERPRINT_IMAGEMESS:
  101. Serial.println("Image too messy");
  102. return p;
  103. case FINGERPRINT_PACKETRECIEVEERR:
  104. Serial.println("Communication error");
  105. return p;
  106. case FINGERPRINT_FEATUREFAIL:
  107. Serial.println("Could not find fingerprint features");
  108. return p;
  109. case FINGERPRINT_INVALIDIMAGE:
  110. Serial.println("Could not find fingerprint features");
  111. return p;
  112. default:
  113. Serial.println("Unknown error");
  114. return p;
  115. }
  116.  
  117. // OK converted!
  118. p = finger.fingerFastSearch();
  119. if (p == FINGERPRINT_OK) {
  120. Serial.println("Found a print match!");
  121. } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
  122. Serial.println("Communication error");
  123. return p;
  124. } else if (p == FINGERPRINT_NOTFOUND) {
  125. Serial.println("Did not find a match");
  126. return p;
  127. } else {
  128. Serial.println("Unknown error");
  129. return p;
  130. }
  131.  
  132. // found a match!
  133. Serial.print("Found ID #"); Serial.print(finger.fingerID);
  134. Serial.print(" with confidence of "); Serial.println(finger.confidence);
  135. }
  136.  
  137. // returns -1 if failed, otherwise returns ID #
  138. int getFingerprintIDez() {
  139. uint8_t p = finger.getImage();
  140. if (p != FINGERPRINT_OK) return -1;
  141.  
  142. p = finger.image2Tz();
  143. if (p != FINGERPRINT_OK) return -1;
  144.  
  145. p = finger.fingerFastSearch();
  146. if (p != FINGERPRINT_OK)
  147. {
  148. digitalWrite (relay2Buz, HIGH);
  149. delay(10000);
  150. digitalWrite(relay2Buz, LOW);
  151. return -1;
  152. }
  153. }
  154.  
  155. // found a match!
  156. Serial.print("Found ID #");
  157. Serial.print(finger.fingerID);
  158. Serial.print(" with confidence of ");
  159. Serial.println (finger.confidence);
  160. digitalWrite (relay1Pin, LOW);
  161. digitalWrite (pinRelay, HIGH);
  162. return finger.fingerID;
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement