Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_Fingerprint.h>
- #include <LiquidCrystal_I2C.h>
- #include <Wire.h>
- #define WAKE_PIN 13
- // On Leonardo/Micro or others with hardware serial, use those!
- // uncomment this line:
- // #define mySerial Serial1
- // For UNO and others without hardware serial, we must use software serial...
- // pin #2 is IN from sensor
- // pin #3 is OUT from arduino
- // comment these two lines if using hardware serial
- //Open Serial Monitor
- SoftwareSerial mySerial(2, 3);
- LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
- Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
- uint8_t id;
- void setup()
- {
- pinMode(WAKE_PIN, INPUT );
- lcd.begin(); // initialize the lcd
- lcd.clear();
- lcd.backlight(); // Turn backlight On
- Serial.begin(9600);
- while (!Serial); // For Yun/Leo/Micro/Zero/...
- delay(100);
- Serial.println("\n\nAdafruit Fingerprint sensor enrollment");
- // set the data rate for the sensor serial port
- finger.begin(57600);
- if (finger.verifyPassword()) {
- Serial.println("Found fingerprint sensor!");
- } else {
- Serial.println("Did not find fingerprint sensor :(");
- while (1) {
- delay(1);
- }
- }
- }
- uint8_t readnumber(void) {
- uint8_t num = 0;
- while (num == 0) {
- while (! Serial.available());
- num = Serial.parseInt();
- }
- return num;
- }
- void loop() // run over and over again
- {
- delay(2000);
- finger.LEDcontrol(FINGERPRINT_LED_GRADUAL_ON, 200, FINGERPRINT_LED_PURPLE);
- delay(2000);
- finger.LEDcontrol(FINGERPRINT_LED_GRADUAL_OFF, 200, FINGERPRINT_LED_PURPLE);
- delay(2000);
- lcd.setCursor(0, 0);
- lcd.print("Fingerprint");
- lcd.setCursor(0, 1);
- lcd.print("Enrollment");
- delay(2000);
- lcd.clear();
- Serial.println("Ready to enroll a fingerprint!");
- Serial.println("Please type in the ID # (from 1 to 127) you want to save this finger as...");
- lcd.setCursor(0, 0);
- lcd.print("Enter finger ID");
- delay(2000);
- id = readnumber();
- if (id == 0) {// ID #0 not allowed, try again!
- return;
- }
- Serial.print("Enrolling ID #");
- Serial.println(id);
- char buffer[16];
- sprintf(buffer, "Enrolling ID #%d", id);
- lcd.setCursor(0, 0);
- lcd.print(buffer);
- lcd.setCursor(0, 1);
- lcd.print("Place finger");
- while (! getFingerprintEnroll() );
- }
- uint8_t getFingerprintEnroll() {
- int p = -1;
- Serial.print("Waiting for valid finger to enroll as #"); Serial.println(id);
- finger.LEDcontrol(FINGERPRINT_LED_BREATHING, 100, FINGERPRINT_LED_BLUE);
- while (p != FINGERPRINT_OK) {
- p = finger.getImage();
- switch (p) {
- case FINGERPRINT_OK:
- finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_BLUE);
- Serial.println("Image taken");
- lcd.setCursor(0, 1);
- lcd.print("Image taken");
- delay(1000);
- lcd.clear();
- break;
- case FINGERPRINT_NOFINGER:
- Serial.println(".");
- break;
- case FINGERPRINT_PACKETRECIEVEERR:
- Serial.println("Communication error");
- break;
- case FINGERPRINT_IMAGEFAIL:
- Serial.println("Imaging error");
- break;
- default:
- Serial.println("Unknown error");
- break;
- }
- }
- // OK success!
- p = finger.image2Tz(1);
- switch (p) {
- case FINGERPRINT_OK:
- Serial.println("Image converted");
- break;
- case FINGERPRINT_IMAGEMESS:
- Serial.println("Image too messy");
- return p;
- case FINGERPRINT_PACKETRECIEVEERR:
- Serial.println("Communication error");
- return p;
- case FINGERPRINT_FEATUREFAIL:
- Serial.println("Could not find fingerprint features");
- return p;
- case FINGERPRINT_INVALIDIMAGE:
- Serial.println("Could not find fingerprint features");
- return p;
- default:
- Serial.println("Unknown error");
- return p;
- }
- Serial.println("Remove finger");
- lcd.setCursor(0, 0);
- lcd.print("Remove finger");
- delay(2000);
- lcd.clear();
- p = 0;
- while (p != FINGERPRINT_NOFINGER) {
- p = finger.getImage();
- }
- finger.LEDcontrol(FINGERPRINT_LED_BREATHING, 100, FINGERPRINT_LED_BLUE);
- Serial.print("ID "); Serial.println(id);
- p = -1;
- Serial.println("Place same finger again");
- lcd.setCursor(0, 0);
- lcd.print("Place finger");
- lcd.setCursor(0, 1);
- lcd.print("again");
- delay(2000);
- lcd.clear();
- while (p != FINGERPRINT_OK) {
- p = finger.getImage();
- switch (p) {
- case FINGERPRINT_OK:
- Serial.println("Image taken");
- break;
- case FINGERPRINT_NOFINGER:
- Serial.print(".");
- break;
- case FINGERPRINT_PACKETRECIEVEERR:
- Serial.println("Communication error");
- break;
- case FINGERPRINT_IMAGEFAIL:
- Serial.println("Imaging error");
- break;
- default:
- Serial.println("Unknown error");
- break;
- }
- }
- // OK success!
- p = finger.image2Tz(2);
- switch (p) {
- case FINGERPRINT_OK:
- Serial.println("Image converted");
- break;
- case FINGERPRINT_IMAGEMESS:
- Serial.println("Image too messy");
- return p;
- case FINGERPRINT_PACKETRECIEVEERR:
- Serial.println("Communication error");
- return p;
- case FINGERPRINT_FEATUREFAIL:
- Serial.println("Could not find fingerprint features");
- return p;
- case FINGERPRINT_INVALIDIMAGE:
- Serial.println("Could not find fingerprint features");
- return p;
- default:
- Serial.println("Unknown error");
- return p;
- }
- // OK converted!
- Serial.print("Creating model for #"); Serial.println(id);
- p = finger.createModel();
- if (p == FINGERPRINT_OK) {
- Serial.println("Prints matched!");
- } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
- Serial.println("Communication error");
- return p;
- } else if (p == FINGERPRINT_ENROLLMISMATCH) {
- finger.LEDcontrol(FINGERPRINT_LED_FLASHING, 25, FINGERPRINT_LED_RED, 10);
- Serial.println("Fingerprints did not match");
- lcd.setCursor(0, 0);
- lcd.print("Fingerprints did not match");
- lcd.setCursor(0, 1);
- lcd.print("not match");
- delay(2000);
- lcd.clear();
- return p;
- } else {
- Serial.println("Unknown error");
- return p;
- }
- Serial.print("ID "); Serial.println(id);
- p = finger.storeModel(id);
- if (p == FINGERPRINT_OK) {
- Serial.println("Stored!");
- lcd.setCursor(0, 0);
- lcd.print("Stored");
- } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
- Serial.println("Communication error");
- return p;
- } else if (p == FINGERPRINT_BADLOCATION) {
- Serial.println("Could not store in that location");
- return p;
- } else if (p == FINGERPRINT_FLASHERR) {
- Serial.println("Error writing to flash");
- return p;
- } else {
- Serial.println("Unknown error");
- return p;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement