Our prices are exclusive of taxes and shipping. 18% GST shall be added during check out. Happy Shopping! :)  

Robocraze Welcome to Robocraze

#Tutorial Fingerprint sensor with Arduino

Ever wanted to protect your hobby projects with your fingerprint? Now thanks to the fingerprint sensor module which can easily be set up in just a few steps.

#Tutorial Fingerprint sensor with Arduino

 

 

It involves minimalistic circuitry and is directly compatible with Arduino.

 

 

Features:

  • Supply voltage: DC 4.2 ~ 6.0V

  • Supply current: Working current: 50mA (typical) Peak current: 80mA

  • Fingerprint image input time: <0.3 seconds

  • Window area: 14x18 mm

  • Matching method: Comparison method (1: 1)

  • Search method (1: N)

  • Characteristic file: 256 bytes

  • Template file: 512 bytes

  • Security Level: Five (from low to high: 1,2,3,4,5)

  • Fake rate (FAR): <0.001%

  • Refusal rate (FRR): <1.0%

  • Search time: <1.0 seconds (1: 1000 hours, mean value)

  • Host interface: UART \ USB1.1

  • Communication baud rate (UART): (9600xN) bps Where N = 1 ~ 12 (default N = 6, ie 57600 bps)

  • Working environment: Temperature: -20 ℃ - +40 ℃ Relative humidity: 40% RH-85% RH (no condensation)

  • Storage environment: Temperature: -40 ℃ - +85 ℃ Relative humidity: <85% H (no condensation)

 

Setup:

As mentioned earlier, it is very easy to set up the Fingerprint sensor with Arduino. For this example, we will take the 6 pin variant of the fingerprint sensor. It is also available in 4 and 8 pin variants.

  1. Download the Adafruit Fingerprint sensor library. https://github.com/adafruit/Adafruit-Fingerprint-Sensor-Library

 

  1. Open the .zip file and extract the library folder into the main library folder of your Arduino project. It is usually in the location C:\Users\PC\Documents\Arduino\libraries\

 

  1. Moving on to the circuitry, we need to connect 4 wires from the fingerprint sensor to the Arduino. Once identified, connect Vcc to the 5V pin of Arduino. GND to GND of Arduino. TX to digital pin 2 and RX to digital pin 3.

 

In the 6 wire variant (R307 module), when viewing the connector, the leftmost wire(RED) should be Vcc, the one next(BLACK) should be GND, next(YELLOW) should be TX and the next(WHITE) is RX. The first two wires from the right are not connected.

                     

Note: If you want to power the sensor using a 3.3V supply, make sure you short the jumper labeled 3.3 located right above the main connector. Once this jumper is shorted, you can use the last wire(labeled 3.3V) to power the sensor.

The second last wire from the right (labeled touch) is not generally used in this setup, but its primary function is to give an active low output whenever a touch is there on the sensor by finger.

 

Fig: Connections for the fingerprint sensor with Arduino. Note- Colours of the wire may vary depending on the sensor module model. Refer to the datasheet in this case.

  1. Once the connections are done, upload the following code into your Arduino and open the serial monitor at 9600 baud.

  1. This code can also be found in the fingerprint sensor library. Open the Arduino IDE, go to file -> Example -> Adafruit Fingerprint Sensor Library -> Enroll.

 

With the other variants of the fingerprint sensor which may have a different number of connecting wires, you can refer to the datasheet to find which pins are for Vcc, GND, TX, RX.

 

Code:

 

#include <Adafruit_Fingerprint.h>

 

// On Leonardo/Micro or others with hardware serial, use those! #0 is green wire, #1 is white

// uncomment this line:

// #define mySerial Serial1

 

// For UNO and others without hardware serial, we must use software serial...

// pin #2 is IN from sensor (YELLOW wire)

// pin #3 is OUT from Arduino  (WHITE wire)

// comment these two lines if using the hardware serial

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3);

 

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

 

uint8_t id;

 

void setup()  

{

 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

{

 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...");

 id = readnumber();

 if (id == 0) {// ID #0 not allowed, try again!

    return;

 }

 Serial.print("Enrolling ID #");

 Serial.println(id);

 

 while (!  getFingerprintEnroll() );

}

 

uint8_t getFingerprintEnroll() {

 

 int p = -1;

 Serial.print("Waiting for valid finger to enroll as #"); Serial.println(id);

 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();

 }

 Serial.print("ID "); Serial.println(id);

 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!

 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) {

   Serial.println("Fingerprints did not match");

   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!");

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

 }  

}

 

Working:

The sensor will first display if the sensor is detected or not. If not detected, make sure the connectors are not loose and reset the Arduino. Once detected, it will ask you to enter a unique ID number between 1-127. Choose a number and hit enter. The sensor will then prompt you to repeatedly lift and place your finger to register the image. If you choose the same number twice, the fingerprint data will be overwritten by the new one.

 

Grab your Arduino here

Grab your Fingerprint Sensor here




Write Your Comment

Only registered users can write comments. Please, log in or register