Introduction

Hi! In this update I will be taking a look at connecting a capactive fingerprint module to an Arduino MKR1000. I looked all over online, and could only find optical fingerprint sensors being connected to the Arduino, so I thought, why not give it a shot with a capacitive one, and if it works great! I want to integrate the fingerprint module to for now use it just a necessary switch, but will try using a solenoid in the device which would completely lock it. First, let's see what's a capacitive fingerprint sensor and how does it work!

 

 

 

Fingerprint Sensors

Fingerprint sensors, as the name suggests, are used for identifying fingerprints. Fingerprints are a unique thing for every person, so they are now used everywhere around us, specially on phones, since the technology allowed them to get so small. There are 2 main types of fingerprint sensors present today, optical fingerprint sensors, and capacitive fingerprint sensors, there is also a new type that is being developed currently, the ultrasonic fingerprint sensors. I will be covering the first 2, so let's start off with the optical fingerprint sensor.

 

Optical fingerprint sensors

Optical fingerprint sensors are the oldest off the bunch, and are still used everywhere. The optical sensors rely on pretty much a camera, that takes a detailed photo of the fingertip and using various algorithms scans the image. Of course the better the camera on the sensor the better the image and better the security. One of the main problems of the optical sensor is that most of them can be fooled easily. since they are capturing essentially a 2D image, which can sometimes be fooled with a good picture. Optical sensor modules can be found for the Arduino around the internet with libraries and everything.

 

Capacitive fingerprint sensors

Capacitive fingerprint sensors are the most widely spread fingerprint sensors in the phone industry currently. They use a lot of tightly pack capacitors, so when we put are fingertip on the sensor, the ridges on out fingerprint change the charge on some of the capacitors, effectively giving the information about our fingerprint to the device. After that, like with the optical fingerprint sensor, various algorithms are used to process the image. The good safety thing about these sensors is that 2D images can't fool them, since they are looking for actual ridges on the fingerprint.

 

 

GROW R302

The fingerprint module I went with is from a company called GROW and the model R302. These modules are the easiest to find around, and they are relatively low cost, with my module coming in around 16 euros, and a couple of weeks waiting time for the shipment to arrive. One more great thing about the modules from the GROW company is that they have the full documentation online free for anyone to use. Here is a picture of what I received in the package.

 

{gallery} R302

Module: In the package I got the module itself as well as a cable for connecting to it.

Table 1: General specification of the R302 module

Pin layout: Pin layout of the module board, the UART part has a connector that goes with the included cable, while for the USB part we need to solder the wires to the PCB.

Table 2: Pins for UART

 

The cool thing about these modules is that they store all of the data on themselves, and they do all of the processing of the images, so they don't use up any of processing power of the Arduino or any other boards. There are 2 ways to connect the module to other devices, UART or USB. First off I wanted to connect it to my PC to see if the module is functioning as it should be. The first attempt was using the USB communication, which required soldering some wires to the PCB. When I would plug in the module into the PC, I could see it in the devices but had problems with getting it to work.(I would see it as a CD ROM, then it would transfer itself to USB devices and then would just say it has a problem, so I opted to go with the second method). After that failed I tried using UART. This of course required a converter to go in between.

 

Connecting the module to a PC

 

The connections between them are:

  1. 5V on the Module (red wire) --- 5V on the converter
  2. GND on the Module (black wire) --- GND on the converter
  3. TXD on the Module (yellow wire) --- RXD on the converter
  4. RXD on the Module (white wire) --- TXD on the converter

 

Next thing we need to is plug the converter into a USB port and try the module out. Of course for that we need to download a program. The one most commonly used with which I went with is the SFG Demo V2.0. It can be easily found online to download. After downloading the program all that's left is trying out to see if the module works! Here is a step by step guide on using the program with the module.

 

 

{gallery} SFG Demo

Device Manager: First off all we need to see to what port the module is connected which can be done going to the device manager, as we can see my module is connected to COM1.

SYNO DEMO: This is the staring screen of the program, first we need to go and click Open Device.

Open Device: We will be greeted with a pop up screen asking us to select the port, for me that would be COM1.

Module Info: If the module is not broken is connected correctly, we should see a screen like this. On the left we can see all of the hardware information, and we can also adjust the BAUDRATE, security level, and other things within the program. Now let's try enrolling a fingerprint.

Enroll: We click the Enroll button and a pop up screen will come up asking us to which address on the module we want to save this fingerprint. Since this is the first time anyone has used this module, the memory is empty, so I just went with address zero. After clicking OK, the program will ask you to put your finger on the module and lift it off twice (a blue LED should be flashing when it is expecting a finger to be places).

Enroll success: If everything went smoothly we should get a message on the top saying success to enroll. And that would be how we add fingerprint to this module, now let's see how well the recognizing works. Also, if you want to see what kind of a picture the module creates of the fingerprint, you can click on the preview checkbox, but expect for the program to take a bit longer then.

Search initiation: When we click the Search button it will ask us to place the finger on the module, and the blue LED will start flashing on it.

Search success: This is me placing the finger i enrolled on the module, and as we can see the device took only 327 ms to recognize the fingerprint. But now let's see what happens when we put a finger that's not enrolled there.

Search Fail: As we can see it can't find the finger within its database, and it again took only around 300 ms which is great!

 

I tried playing around with the sensor a bit, and while it works great, there are some things that should be addressed, but are not a total deal breaker. The pad on the module is decent sized, but not large enough for a whole fingerprint really, specially with 2 scans. Most phones now when you need to enroll a fingerprint require you to scan your finger tip from all angles, so the pad could more easily recognize your finger regardless of the finger position. Again, even like this, I am impressed with how smooth and fast it works, but will try fixing this issue by enrolling the same finger to a few different addresses from all sorts of angles. Now we have to connect this to the Arduino MKR1000.

Connecting the module to an Arduino

Since we have already connected the module to the computer, we have a fingerprint recorded on the device, so to make this a bit shorter, I will for now only focus on recognizing the fingerprint. As I've said before, the module comes with full documentation but there are no convenient libraries specifically for it. But while doing some research around, I saw that there are a couple of libraries for other manufacturers modules. The one I took a look at was the Adafruit fingerprint module. Their fingerprint module is an optical one but I found a library for it, so I thought to go and look into that library as well as the documentation for the module itself. Having the documentation of both the Adafruit module and the GROW module side by side, I saw something that made me extremely happy, all of the commands are the same, which should mean that the library should straight on work with my module, and it did! The library in question can be found here (https://github.com/adafruit/Adafruit-Fingerprint-Sensor-Library). Now let's connect the module to the Arduino.

 

Connections are:

  1. Red wire on the module --- 5V on the Arduino
  2. Black wire on the module --- GND on the Arduino
  3. Yellow wire on the module --- RX Pin on the Arduino (13 on the MKR1000)
  4. Green wire on the module --- TX Pin on the Arduino (14 on the MKR1000)

 

 

To test out the module I will be using one of the example programs from the library ("fingerprint" example) with a few added lines to switch from a red to a green LED. As for the wiring all I did was add 2 LED-s with 220 Ohm resistors to pins 4 and 5. Here is the example code that comes with the library with addition of the couple of lines needed to turn on the LED-s.

 

/*************************************************** 
  This is an example sketch for our optical Fingerprint sensor


  Designed specifically to work with the Adafruit BMP085 Breakout 
  ----> http://www.adafruit.com/products/751


  These displays use TTL Serial to communicate, 2 pins are required to 
  interface
  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!


  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/




#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 (GREEN wire)
// pin #3 is OUT from arduino  (WHITE wire)
// comment these two lines if using hardware serial
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(2, 3);


Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);


void setup()  
{
  Serial.begin(9600);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  digitalWrite(4,LOW);
  digitalWrite(5,HIGH);
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println("\n\nAdafruit finger detect test");
  
  // 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); }
  }


  finger.getTemplateCount();
  Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
  Serial.println("Waiting for valid finger...");
}


void loop()                     // run over and over again
{
  getFingerprintIDez();
  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!
  Serial.print("Found ID #"); Serial.print(finger.fingerID); 
  Serial.print(" with confidence of "); Serial.println(finger.confidence); 
  return finger.fingerID;
}


// 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);
  digitalWrite(4,HIGH);
  digitalWrite(5,LOW);
  delay(700);
  digitalWrite(4,LOW);
  digitalWrite(5,HIGH);
  return finger.fingerID; 
}

 

When we upload the program we have to open the serial monitor to get the whole thing going and we should be firstly greeted with this screen:

 

 

The one valid template is from when we enrolled the fingerprint using the PC, if there is time left I will be sure to incorporate enrolling fingerprints using Arduino as well!. After placing the correct finger on the sensor we should see a message like this:

 

 

We get the ID of the fingerprint, and as we can see it returned 0, just like we enrolled it in the first place, and besides that returns a number which represents how confident the module is. This is a great little feature which can be used to make the sensor a bit more secure by adding a threshold, but for now all we care about is if the finger is recognized or not. The library comes with a few more great examples, but I will be sticking to this one for now. Here is a video of switching between LED-s. One more LED we can see reacting is the module integrated LED, which usually flashes blue, but changes to red if it doesn't recognize the fingerprint.

 

First Test

 

 

Summary

That would be it for this update, I was pretty frustrated in the beginning when it didn't want to work over the USB pins, but after setting up the converter correctly and going over UART everything clicked into place pretty fast, specially considering that the Adafruit library works with the module as well. I will take a look at it a bit better also to see what other functions are available. The primary goal of the fingerprint is to use it like an electronic switch, so that the device is useless for the most part without the owner, but would like to further increase its use by adding something like a solenoid lock to it, but that will have to come later on. Now it's time to finish up the mechanical part as well as take a look at the ESP8266. Thanks for reading the blog, hope you liked it!

 

Milos