Using an Optical Fingerprint Sensor with the Arduino
Fingerprint sensing is one of those technologies in science fiction movies that fascinated most of us as kids. Today, they are everywhere and asides from existing in everyday devices with huge electronics complexity, like mobile phones, they are also available in tiny modules to give makers and electronics hobbyists, the ability to include them in their own projects. For today’s tutorial, we will look at the use of a fingerprint sensor with Arduino.
Fingerprint sensors are based on diverse kind of technology, from capacitive fingerprint sensors used in recent mobile phones, to optical fingerprint sensors commonly used in access control applications. For today’s project, we will use an optical fingerprint sensor.
The Optical fingerprint sensor is a highly compact device. It comes embedded with an advanced DSP (Digital Signal Processing) chip, which is used to process the image of fingers captured and determine if a match exists or not.
When the sensor captures a new image, it is rendered and the distinguishing features are extracted. 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 of 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!
To demonstrate the use of this module with the Arduino, we will build an access notification system. We will use a TFT display alongside the fingerprint sensor and an Arduino nano, to build a simple device that displays “UNLOCKED” when there is a fingerprint match and displays “LOCKED ” when there is no match.
The following components are required to build this project;
These components, can be purchased via the links attached to them. The Power bank is optional but provides a very easy way to power the project when it is not connected to your computer.
Connect the components as shown in the schematics below. The particular optical fingerprint sensor used for this tutorial is not available on Fritzing, so a makeshift version was used.
As mentioned earlier, the optical fingerprint sensor communicates with microcontrollers over UART (Serial communication) and as such only requires 4 wires to connect it to the Arduino. The second significant element of the schematic is the 1.44″ color TFT LCD display and a detailed tutorial about its use is found on the link.
To make the connections easier to follow, especially since a makeshift representation was used for the fingerprint sensor, the pin connections are mapped below.
Fingerprint sensor – Arduino
VCC - 5V GND - GND TX - D2 RX - D3
TFT Display – Arduino
VIN - 5V GND - GND CS - D10 RST - D9 A0 - D8 SDA - D11 SCK - D13 LED - 3.3V
The pins of the fingerprint sensors are sometimes not labeled but differentiated with the color codes of the wires. It is important you check the description of the sensor to know what color of wire was used for each pin. If you have any further problems with connection, feel free to reach out via the comment section.
The code for this project relies heavily on the fingerprint sensor library from Adafruit. The library reduces the amount of code that is needed to interact with the sensor by compressing them into functions. The library can be downloaded here. To easily interact with the TFT display also, we will use the popular Adafruit GFX library and the ILI9163C library from Somutoy.
To do a brief explanation of the code, we start by including the libraries we will us.
Then we define the colors that will be used in the display.
The next important line is the creation of a software serial instance to enable the Arduino to communicate with the fingerprint 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.
With that done, we move to the void setup() function where we start and initialize all the communication systems and display the lock screen.
Next is the void loop function. In this function we check for a finger present every 50ms. If a finger is found, the module checks to see if the fingerprint is stored in its memory. If it is present, it generates the fingerprint ID and displays the name of the user. After a few seconds, the screen is locked again.
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 is shown below and also attached under the download section.
As mentioned above, you should use the enroll examples to enroll new fingerprints. Once this is done, Upload the code of this tutorial to your Arduino board. You should see the display come up after a while, waiting for you to place a finger on the fingerprint sensor. If an existing finger is placed, “ULOCKED” will be displayed on the TFT display as shown below. If the finger has not been registered it will display “DENIED”.
That’s it for today’s tutorial. If you have any question in regards to this, do not hesitate to drop it under the comment section below.
Till next time!
The video version of this tutorial is available on youtube.