Enrolling Fingerprints Using Adafruit Fingerprint Sensor and evive

Fingerprint-Sensor-Reader-R307
Description
Learn how to use the Adafruit Fingerprint Sensor and evive TFT Screen to enroll fingerprints for secure identity identification. Follow the steps to enroll the input finger and add fingerprint verification to your project.

Introduction

The Fingerprint is one of the safest ways to detect and identify the Authorized person, We know that fingerprint is unique even identical twins do not have identical fingerprints. By using this we can make pretty sure about security needs. To add fingerprint verification in evive project we can use this all-in-one optical fingerprint sensor-scanner (R307), It makes fingerprint detection and verification super simple.

The fingerprint identification process has two steps which are

  1. Enrolling Fingerprint.
  2. Matching Fingerprint.

In this tutorial, we are going to know how to enroll in Fingerprint.

Circuit Diagram

Code

First, save this library into the libraries folder of your Arduino or other programming software.

In the given below program we are doing two things:

  1. Enrolling the input finger: Basically, it captures two images and converts them into a uint8 array matrix. In fingerprint matching, it checks the degree of closeness to the mean value of captured images. To select the ID in which you want to save we are going to use potentiometer 1 of evive which is connected to the A9 pin of evive and then press tactile switch 2 connected to the D39  pin.
  2. Displaying every process on evive TFT screen.

#include <Adafruit_Fingerprint.h>
#include <evive.h>
#include <SoftwareSerial.h>
int a=9;
int x=39;
int b=38;
int id1;
int id2;
SoftwareSerial mySerial(10, 11);//YELLOW/WHITT

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

uint8_t id;

void setup()  
{
  tft_init(INITR_BLACKTAB);
  tft.fillScreen(ST7735_BLACK);  
  tft.setCursor(0,10);
  
  Serial.begin(9600);
  
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  pinMode(a,INPUT);
  pinMode(x,INPUT);
  pinMode(b,INPUT);
  delay(100);
  tft.println("\n\nAdafruit Fingerprint sensor enrollment");
  
  // set the data rate for the sensor serial port
  finger.begin(57600);
  
  if (finger.verifyPassword()) {
    tft.println("Found fingerprint sensor!");
  } else {
    tft.println("Did not find fingerprint sensor :(");
    while (1) { delay(1); }
  }
}



void loop()                     // run over and over again
{
    tft.fillScreen(ST7735_BLACK);
  tft.setCursor(0,10);
    tft.println("Try to enroll a fingerprint!");
    tft.println("press button b");
    int X=digitalRead(x);
    while(X==0)
    {
     X=digitalRead(x); 
    }
    tft.println("Please type in the ID # (from 1 to 127) you want to save this finger as...");
delay(3000);
  int B=0;
while(B==0)
{   
    tft.setCursor(0,10);
    tft.fillScreen(ST7735_BLACK);
    
    
    id1=analogRead(a);
    id2=map(id1,0,1023,0,127);
    tft.print(String(id2));
    delay(100);
//   tft.print(",");
    B=digitalRead(b);
//    tft.println(String(B));
    
    
}

  id=map(id1,0,1023,0,127);
  
  if (id == 0) {// ID #0 not allowed, try again!
     return;
  }
  tft.print("Enrolling ID #");
  tft.println(id);
  
  while (!  getFingerprintEnroll() );
}
  
uint8_t getFingerprintEnroll() {
tft.fillScreen(ST7735_BLACK);
  tft.setCursor(0,10);
  int p = -1;
  tft.print("Waiting for valid finger to enroll as #"); Serial.println(id);
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      tft.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      tft.print(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      tft.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      tft.println("Imaging error");
      break;
    default:
      tft.println("Unknown error");
      break;
    }
  }

  // OK success!
 
  p = finger.image2Tz(1);
  switch (p) {
    case FINGERPRINT_OK:
      tft.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      tft.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      tft.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      tft.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      tft.println("Could not find fingerprint features");
      return p;
    default:
      tft.println("Unknown error");
      return p;
  }
  
  tft.println("Remove finger");
  delay(2000);

  
  p = 0;
  while (p != FINGERPRINT_NOFINGER) {
    p = finger.getImage();
  }
  tft.print("ID "); tft.println(id);
  p = -1;
  tft.fillScreen(ST7735_BLACK);
  tft.setCursor(0,10);
  tft.println("Place same finger again");
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      tft.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      tft.print(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      tft.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      tft.println("Imaging error");
      break;
    default:
      tft.println("Unknown error");
      break;

    }
 
  }

  // OK success!
 
  p = finger.image2Tz(2);
  switch (p) {
    case FINGERPRINT_OK:
      tft.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      tft.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      tft.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      tft.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      tft.println("Could not find fingerprint features");
      return p;
    default:
      tft.println("Unknown error");
      return p;
  delay(5000);
  }
  
  // OK converted!
  tft.print("Creating model for #");  tft.println(id);
  
  p = finger.createModel();
  if (p == FINGERPRINT_OK) {
    tft.println("Prints matched!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    tft.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_ENROLLMISMATCH) {
    tft.println("Fingerprints did not match");
    return p;
  } else {
    tft.println("Unknown error");
    return p;
  }   
 
  tft.print("ID "); tft.println(id);
  p = finger.storeModel(id);
  if (p == FINGERPRINT_OK) {
    tft.println("Stored!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    tft.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_BADLOCATION) {
    tft.println("Could not store in that location");
    return p;
  } else if (p == FINGERPRINT_FLASHERR) {
    tft.println("Error writing to flash");
    return p;
  } else {
    tft.println("Unknown error");
    return p;
  }
   tft.println("press button b for next enroll");
int X=0;
     while(X==0)
    {
     X=digitalRead(x); 
    }
}

Output

Conclusion

This lesson has demonstrated how to use Adafruit Fingerprint Sensor to enroll a fingerprint using the evive TFT screen. The Fingerprint is a secure way to detect and identify an authorized person. The Fingerprint identification process has two steps which are enrolling and matching the fingerprints. In this lesson, we learned how to enroll the input finger by using the Adafruit Fingerprint Sensor and evive TFT screen.

Table of Contents