How to use a fingerprint sensor with Arduino

Hi guys, Nick again, welcome to educ8s.tv. today we are going to learn how to use a cheap fingerprint sensor with the Arduino. The procedure is very easy and it is an ideal project for both Arduino experts and beginners.

I always wanted to try a fingerprint sensor module in order to learn more about its technology and use it in some of my projects in order to add biometric security to them. While searching for a nice and low cost sensor, I discovered this sensor module on Gearbest.com, with a price tag of around 30$ and  Gearbest.com was kind enough to send me a sample unit in order to test it and share my opinion about it with you.

Fingerprint Sensor

 

The fingerprint sensor module is a very compact module with an advanced DSP (Digital Signal Processing) chips inside  which is used by the sensor to process the image of fingers captured to detect if there is a match or not. When the sensor captures a new image, the image is rendered and some calculations are made to find the features of that finger after which the memory of the sensor is searched for a fingerprint with matching characteristics and the result of that session is sent  to the microcontroller via serial communication. All this is done in less than a second. The module can store up to 1000 fingerprints in its memory and its false acceptance rate is less than 0.001% which makes it pretty secure!

Fingerprint Detection Process

In order to demonstrate a simple use of the sensor, we will be building a simple project with it. We will be using the sensor along with an Arduino Uno and a 1.44 inch colored TFT display. The Concept behind the project is simple, we want to build a security system that unlocks only when a registered fingerprint is placed on the sensor. The project will display a welcome message on the LCD when the correct finger is placed and display a locked message when there is no fingerprint match. It is a useful and fun project and you will learn enough to build your own door security system.

 

Required Parts and Where to Buy

The following parts/components are required to build this project and they can be bought via the link in front of each component.

  1. Fingerprint Sensor: https://educ8s.tv/part/FingerprintSensor
  2. Arduino Nano: https://educ8s.tv/part/ArduinoNano
  3. 1.44 Color TFT: https://educ8s.tv/part/LCD144
  4. Small Breadboard: https://educ8s.tv/part/SmallBreadboard
  5. Jumper Wires: https://educ8s.tv/part/JumperWires
  6. Power bank Xiaomi: https://educ8s.tv/part/Powerbank
[adsense]

 

Schematics

Connect the parts as shown in the circuit diagram below. As mentioned earlier, the fingerprint sensor communicates with the microcontroller over serial communication so we only need connect two wires from the sensor to the microcontroller asides from power and ground. Fritzing didnt have the exact fingerprint sensor Wanted, hence the makeshift representation for the sensor.

To make the connection easier to follow, it is further described below.

FINGERPRINT Sensor ——–ARDUINO NANO

Vcc——————————–5V

GND——————————GND

Tx———————————D2

Rx———————————D3

 

NOTE: The  1.44’ TFT display used in the schematic above is quite different from the one used in the video tutorial. Ensure you make use of the pin mapping shown above if you are making use of the display used in the video

TFT DISPLAY———ARDUINO NANO

Vin———————–5V

GND——————–GND

CS———————–D10

RST———————D9

A0———————–D8

SDA——————–D11

SCK——————–D13

LED——————-3.3V

 

 

Code

It’s time to finally write the Arduino sketch for the project. To develop the code sketch for this project, we will be using three main Arduino libraries which are listed below. One  of the libraries is used to interface with the Finger print sensor while the other two libraries are required to use the TFT display for the project. The libraries can be downloaded from the links below.

——————–

LIBRARIES
——————–

https://github.com/adafruit/Adafruit-Fingerprint-Sensor-Library

https://github.com/adafruit/Adafruit-GFX-Library

https://github.com/sumotoy/TFT_ILI9163C

 

With the libraries downloaded and installed you can now proceed with the code. As usual I will do a brief explanation of the code for the project and attach the complete code under the download section at the end of this tutorial.

As usual, we start the code by including the libraries that we will be using.

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <TFT_ILI9163C.h>
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
#include <avr/pgmspace.h>

Then we make color definitions for the colors that will be used by the display.

#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0  
#define WHITE   0xFFFF

To ensure the display looks nice, an icon was created. Thus the next thing is for us to initialize the icons that will be used and store their hex values in the program memory. We have covered how to create icons for this display in a previous tutorial on this website.

The next important line is the creation of a software serial instance to enable the arduino communicate with the finger print sensor. The hardware serial was not used because it is the same pins that is being used by the arduino to communicate with the computer.

SoftwareSerial mySerial(2, 3);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

With that done, we move to the void setup() function where we start and initialize all the communications systems and display the lock screen.

void setup(void)
 {
  startFingerprintSensor();
  display.begin();
  displayLockScreen(); 
}

Next is the void loop function, we check for a finger every 50ms. If a finger is found, the module checks to see if the fingerprint is enrolled in its memory. If it is enrolled, it generates the fingerprintID and then then displays the name of the user. After a few seconds,  the screen is locked again.

void loop() {

  fingerprintID = getFingerprintID();
  delay(50);
  if(fingerprintID == 1)
  {
    display.drawBitmap(30,35,icon,60,60,GREEN);
    delay(2000);
    displayUnlockedScreen();
    displayIoanna();
    delay(5000);
    display.fillScreen(BLACK);
    displayLockScreen();
  }
  if(fingerprintID == 2)
  {
    display.drawBitmap(30,35,icon,60,60,GREEN);
    delay(2000);
    displayUnlockedScreen();
    displayNick();
    delay(5000);
    display.fillScreen(BLACK);
    displayLockScreen();
  }
}

Enrolling a finger before uploading the code for this project is important and can be done by uploading the enroll example from the Adafruit fingerprint library to our Arduino board. We go to File-> Examples -> Adafruit Fingerprint Sensor Library -> Enroll. With this example program we can store fingerprints in the FLASH memory of the module. We upload the sketch and open the Serial Monitor. The program asks us to enter the ID to enroll. Then we place the finger on the sensor twice as we are instructed and the fingerprint is stored! You can store as many as 1000 fingerprints this way.

 

The complete code for this project can be downloaded from the link below.

——————–

CODE OF THE PROJECT
——————–

 

 

 

After enrolling, upload the code for this project onto your Arduino and try with different fingers, you should see the project work as described. A look at the final setup in action is shown in the image below.

Thanks for watching or reading today’s tutorial. You can leave whatever questions you have under the comment section of this project, I will be glad to provide answers to them as soon as possible. Don’t forget to subscribe to get informed about all new tutorials.

SUBSCRIBE ON YOUTUBE

——————–

Never miss a video: Subscribe to educ8s.tv