Advertisement
safwan092

project_9295_Fingerprint

Apr 29th, 2022
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.58 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h>
  3. #include <Adafruit_MLX90614.h>
  4. #include <Adafruit_Fingerprint.h>
  5.  
  6. //------------------------------------------byte array to display degrees on the LCD
  7. byte degree[8] = {
  8. 0b00110,
  9. 0b01001,
  10. 0b01001,
  11. 0b00110,
  12. 0b00000,
  13. 0b00000,
  14. 0b00000,
  15. 0b00000
  16. };
  17. //------------------------------------------
  18.  
  19. #if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)
  20. // For UNO and others without hardware serial, we must use software serial...
  21. // pin #2 is IN from sensor (GREEN wire)
  22. // pin #3 is OUT from arduino (WHITE wire)
  23. // Set up the serial port to use softwareserial..
  24. SoftwareSerial mySerial(2, 3);
  25.  
  26. #else
  27. // On Leonardo/M0/etc, others with hardware serial, use hardware serial!
  28. // #0 is green wire, #1 is white
  29. #define mySerial Serial1
  30.  
  31. #endif
  32. LiquidCrystal_I2C lcd(0x27, 20, 4);
  33. Adafruit_MLX90614 mlx = Adafruit_MLX90614(); //-> mlx declaration
  34. Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
  35. #define pumpPin 11
  36.  
  37. int fingerNumber = 0;
  38. void setup()
  39. {
  40. pinMode(pumpPin, OUTPUT);
  41. digitalWrite(pumpPin, LOW);
  42. lcd.init();
  43. lcd.backlight();
  44. lcd.setCursor(3, 0);
  45. lcd.print("Hello, world!");
  46. lcd.createChar(0, degree);
  47. mlx.begin();
  48. Serial.begin(9600);
  49. while (!Serial); // For Yun/Leo/Micro/Zero/...
  50. delay(100);
  51. Serial.println("\n\nAdafruit finger detect test");
  52.  
  53. // set the data rate for the sensor serial port
  54. finger.begin(57600);
  55. delay(5);
  56. if (finger.verifyPassword()) {
  57. Serial.println("Found fingerprint sensor!");
  58. } else {
  59. Serial.println("Did not find fingerprint sensor :(");
  60. while (1) {
  61. delay(1);
  62. }
  63. }
  64.  
  65. Serial.println(F("Reading sensor parameters"));
  66. finger.getParameters();
  67. Serial.print(F("Status: 0x")); Serial.println(finger.status_reg, HEX);
  68. Serial.print(F("Sys ID: 0x")); Serial.println(finger.system_id, HEX);
  69. Serial.print(F("Capacity: ")); Serial.println(finger.capacity);
  70. Serial.print(F("Security level: ")); Serial.println(finger.security_level);
  71. Serial.print(F("Device address: ")); Serial.println(finger.device_addr, HEX);
  72. Serial.print(F("Packet len: ")); Serial.println(finger.packet_len);
  73. Serial.print(F("Baud rate: ")); Serial.println(finger.baud_rate);
  74.  
  75. finger.getTemplateCount();
  76.  
  77. if (finger.templateCount == 0) {
  78. Serial.print("Sensor doesn't contain any fingerprint data. Please run the 'enroll' example.");
  79. }
  80. else {
  81. Serial.println("Waiting for valid finger...");
  82. Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
  83. }
  84. }
  85.  
  86. void loop() // run over and over again
  87. {
  88. getFingerprintID();
  89. delay(50); //don't ned to run this at full speed.
  90. }
  91.  
  92. uint8_t getFingerprintID() {
  93. uint8_t p = finger.getImage();
  94. switch (p) {
  95. case FINGERPRINT_OK:
  96. Serial.println("Image taken");
  97. break;
  98. case FINGERPRINT_NOFINGER:
  99. //Serial.println("No finger detected");
  100. return p;
  101. case FINGERPRINT_PACKETRECIEVEERR:
  102. Serial.println("Communication error");
  103. return p;
  104. case FINGERPRINT_IMAGEFAIL:
  105. Serial.println("Imaging error");
  106. return p;
  107. default:
  108. Serial.println("Unknown error");
  109. return p;
  110. }
  111.  
  112. // OK success!
  113.  
  114. p = finger.image2Tz();
  115. switch (p) {
  116. case FINGERPRINT_OK:
  117. Serial.println("Image converted");
  118. break;
  119. case FINGERPRINT_IMAGEMESS:
  120. Serial.println("Image too messy");
  121. return p;
  122. case FINGERPRINT_PACKETRECIEVEERR:
  123. Serial.println("Communication error");
  124. return p;
  125. case FINGERPRINT_FEATUREFAIL:
  126. Serial.println("Could not find fingerprint features");
  127. return p;
  128. case FINGERPRINT_INVALIDIMAGE:
  129. Serial.println("Could not find fingerprint features");
  130. return p;
  131. default:
  132. Serial.println("Unknown error");
  133. return p;
  134. }
  135.  
  136. // OK converted!
  137. p = finger.fingerSearch();
  138. if (p == FINGERPRINT_OK) {
  139. Serial.println("Found a print match!");
  140. fingerNumber = finger.fingerID;
  141. fingerFound();
  142. } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
  143. Serial.println("Communication error");
  144. return p;
  145. } else if (p == FINGERPRINT_NOTFOUND) {
  146. Serial.println("Did not find a match");
  147. fingerNotFound();
  148. return p;
  149. } else {
  150. //Serial.println("Unknown error");
  151. return p;
  152. }
  153.  
  154. // found a match!
  155. Serial.print("Found ID #"); Serial.print(finger.fingerID);
  156. Serial.print(" with confidence of "); Serial.println(finger.confidence);
  157.  
  158. return finger.fingerID;
  159. }
  160.  
  161. void fingerFound() {
  162. lcd.clear();
  163. lcd.setCursor(0, 0);
  164. lcd.print("Found ID #");
  165. lcd.print(fingerNumber);
  166. lcd.print(" ");
  167. lcd.setCursor(0, 1);
  168. lcd.print("Ambient Temp: ");
  169. lcd.print(mlx.readAmbientTempC());
  170. lcd.write(byte(0));
  171. lcd.setCursor(0, 2);
  172. lcd.print("Target Temp: ");
  173. lcd.print(mlx.readObjectTempC());
  174. lcd.write(byte(0));
  175. digitalWrite(pumpPin, HIGH);
  176. delay(500);
  177. digitalWrite(pumpPin, LOW);
  178. delay(3000);
  179. lcd.clear();
  180. lcd.setCursor(0, 0);
  181. lcd.print("Scanning...");
  182.  
  183. }
  184.  
  185. void fingerNotFound() {
  186. lcd.clear();
  187. lcd.setCursor(0, 0);
  188. lcd.print("Finger Print N/A");
  189. lcd.setCursor(0, 1);
  190. lcd.print("Ambient Temp: ");
  191. lcd.print(mlx.readAmbientTempC());
  192. lcd.write(byte(0));
  193. lcd.setCursor(0, 2);
  194. lcd.print("Target Temp: ");
  195. lcd.print(mlx.readObjectTempC());
  196. lcd.write(byte(0));
  197. digitalWrite(pumpPin, HIGH);
  198. delay(500);
  199. digitalWrite(pumpPin, LOW);
  200. delay(3000);
  201. lcd.clear();
  202. lcd.setCursor(0, 0);
  203. lcd.print("Scanning...");
  204. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement