Get started with a Fingerprint Sensor Module using Arduino

Today we will see how to use a fingerprint sensor from Adafruit. It’s easy to incorporate into your Arduino projects.

How to get started

First, hook up all four wires to your favorite solderless breadboard and connect power and ground. Next, hook up the green and white wires to digital pins 2 and 3 on your Arduino board.

1

Once you’ve got your library loaded in the Arduino IDE, open the in Enroll sketch from the samples and load it onto your board.
Fingerprint sensor library

Fingerprint sensor library

enroll

enroll

This will help you register your fingerprints with the sensor. Then open the serial monitor
and follow the prompts to enroll your finger prints. It’ll ask you for a numerical ID and then ask you to place your finger, remove your finger and then place it one more time so it knows it’s got the right image. If it doesn’t work the first time don’t be discouraged just keep trying it needs to get a clear picture.

Continue enrolling until you’ve got all the fingers you want to be stored in the sensor. Then open up the Fingerprint sketch from the examples. Here you can light up some LEDs. Set pin 11 and 12 as outputs. Here 11 is the green LED and 12 is the red LED which is set HIGH from the start.

Add some extra code to turn off the red LED and turn the green LED on for a moment and turn it off and turn the red LED back on indicating we’ve got a match.
// found a match! 
digitalWrite(12, LOW);// set the red led off 
digitalWrite(11, HIGH);// set the green led on 
delay(1000); // wait for a second; 
digitalWrite(11, LOW);// set the green led off 
delay(1000); // wait for a second; 
digitalWrite(12, HIGH);// set the red led on
Load this code in your Arduino board to verify that your sensor is actually reading your fingerprints correctly.

It’ll give you a confidence measurement for how sure it is that it’s a match. Higher the number the better the match !!
Plug your Arduino board into the computer and test to see if it works. First, scan the fingerprint you know you’ve got enrolled with the sensor that lights up the green LED. Next, try a finger you don’t have registered with the sensor the red LED remains on!!

 ENROLL CODE

#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>

uint8_t getFingerprintEnroll(uint8_t id);



// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino (WHITE wire)
SoftwareSerial mySerial(2, 3);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup() 
{
 Serial.begin(9600);
 Serial.println("fingertest");

// 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);
 }
}

void loop() // run over and over again
{
 Serial.println("Type in the ID # you want to save this finger as...");
 uint8_t id = 0;
 while (true) {
 while (! Serial.available());
 char c = Serial.read();
 if (! isdigit(c)) break;
 id *= 10;
 id += c - '0';
 }
 Serial.print("Enrolling ID #");
 Serial.println(id);
 
 while (! getFingerprintEnroll(id) );
}

uint8_t getFingerprintEnroll(uint8_t id) {
 uint8_t p = -1;
 Serial.println("Waiting for valid finger to enroll");
 while (p != FINGERPRINT_OK) {
 p = finger.getImage();
 switch (p) {
 case FINGERPRINT_OK:
 Serial.println("Image taken");
 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");
 delay(2000);
 p = 0;
 while (p != FINGERPRINT_NOFINGER) {
 p = finger.getImage();
 }

p = -1;
 Serial.println("Place same finger again");
 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!
 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) {
 Serial.println("Fingerprints did not match");
 return p;
 } else {
 Serial.println("Unknown error");
 return p;
 } 
 
 p = finger.storeModel(id);
 if (p == FINGERPRINT_OK) {
 Serial.println("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;
 } 
}

 FINGERPRINT CODE

#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>

int getFingerprintIDez();

// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino (WHITE wire)
SoftwareSerial mySerial(2, 3);



Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup() 
{
 Serial.begin(9600);
 Serial.println("fingertest");

// 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);
 }
 Serial.println("Waiting for valid finger...");
}

void loop() // run over and over again
{
 getFingerprintIDez();
 digitalWrite(12, HIGH);
 delay(50); //don't ned to run this at full speed.
}

uint8_t getFingerprintID() {
 uint8_t p = finger.getImage();
 switch (p) {
 case FINGERPRINT_OK:
 Serial.println("Image taken");
 break;
 case FINGERPRINT_NOFINGER:
 Serial.println("No finger detected");
 return p;
 case FINGERPRINT_PACKETRECIEVEERR:
 Serial.println("Communication error");
 return p;
 case FINGERPRINT_IMAGEFAIL:
 Serial.println("Imaging error");
 return p;
 default:
 Serial.println("Unknown error");
 return p;
 }

// OK success!

p = finger.image2Tz();
 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!
 p = finger.fingerFastSearch();
 if (p == FINGERPRINT_OK) {
 Serial.println("Found a print match!");
 } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
 Serial.println("Communication error");
 return p;
 } else if (p == FINGERPRINT_NOTFOUND) {
 Serial.println("Did not find a match");
 return p;
 } else {
 Serial.println("Unknown error");
 return p;
 } 
 
 // found a match!
 digitalWrite(12, LOW);// set the red led off 
 digitalWrite(11, HIGH);// set the green led on 
 delay(1000); // wait for a second;
 digitalWrite(11, LOW);// set the green led off 
 delay(1000); // wait for a second;
 digitalWrite(12, HIGH);// set the red led on
 
 Serial.print("Found ID #"); Serial.print(finger.fingerID); 
 Serial.print(" with confidence of "); Serial.println(finger.confidence); 
}

// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
 uint8_t p = finger.getImage();
 if (p != FINGERPRINT_OK) return -1;

p = finger.image2Tz();
 if (p != FINGERPRINT_OK) return -1;

p = finger.fingerFastSearch();
 if (p != FINGERPRINT_OK) return -1;
 
 // found a match!
 Serial.print("Found ID #"); Serial.print(finger.fingerID); 
 Serial.print(" with confidence of "); Serial.println(finger.confidence);
 return finger.fingerID; 
}

Christine

Christine

Author at onlineshouter
Christine writes for people who seek for knowledge about SEO, blogging, online marketing, gadgets and web apps.
Christine

Leave a Reply

Your email address will not be published.