How to use a Raspberry Pi Fingerprint Sensor for Authentication

25. March 2017
25 Comments

Not only in Hollywood films, fingerprint readers are seen more and more frequently. Such modules are often installed in home surveillance systems and are used for the simple but secure verification of persons. With such a Raspberry Pi Fingerprint Sensor you can also implement some other projects, such as secured locks.

One of the advantages is that passwords and / or number codes can be completely omitted. Although this is still possible, but it’s a lot more comfortable without. This tutorial is about the connection as well as the reading, saving and verifying of imported fingerprints.

 

Accessories

Raspberry Pi Fingerprint Sensor ttyUSB0 UART Konverter

A USB TTL adapter with 3.3V and 5V voltage output can be used for many serial modules.

These sensors were originally developed for the Arduino and can be read via UART. The Raspberry Pi has two pins (pin 8 / GPIO14 and pin 10 / GPIO 15), but they work with 3.3V. Since there are different fingerprint sensors, which do not all work with 3.3V, a USB UART converter is recommended. Some models can be used with both 3.3V and 5V voltage. These are particularly suitable (also in connection with an Arduino).

The following is therefore required:

  • Raspberry Pi Fingerprint Sensor (US / UK). Apart from the voltage the models do not differ much.
  • Serial USB converter (US / UK) with 3.3V and 5V connection
  • Female-Female Jumper wires (US / UK), if not included with the USB converter.
  • optional: cousing (which can also be 3d-printed)

Note in the article description, what voltage your sensor needs. Mine needs 3.3V input voltage, however, e.g. other models have a voltage between 3.8V and 6V. The voltage is very important for the connection.

 

Connection of the Raspberry Pi Fingerprint Sensor

The USB adapter is labeled, but the fingerprint sensor cables are not. However, the cables have a clear color, which we can identify and connect to the USB converter. We only need four of the cables (if your fingerprint sensor has more, you can ignore the remaining colors):

  • Red: Depending on the accepted voltage of the sensor (3.3V or 5V).
  • White: RXD
  • Green: TXD
  • Black: GND

If your sensor needs a higher voltage than 3.3V (and the maximum value is equal to or greater than 5V), you can connect the red cable to the 5V pin.

To check whether the cabling is correct and whether the sensor is detected, you can open your console and perform the following before and after connecting:

ls /dev/ttyUSB*

If no other serial devices are connected via USB, nothing should be displayed first and afterwards /dev/ttyUSB0. If the name differs (because, for example, other devices are connected), you have to adapt it accordingly in the following steps.

Second variant via GPIO’s

If you have a sensor with 3.3V required input voltage, you can also connect this without USB converter directly to the GPIOs. Theoretically, you can do it also with 5V and a TTL converter, but I will not go into details in this tutorial. One advantage of the USB variant is that it is easier to check whether the sensor has been detected.

 

Installation of the Raspberry Pi Fingerprint Library

For some commands of the installation, root privileges are required. Therefore we start a terminal session and type the following, which executes all the following commands as root:

sudo bash

Now we add the necessary package sources (the author has also a few other exciting projects):

wget -O - http://apt.pm-codeworks.de/pm-codeworks.de.gpg | apt-key add -
wget http://apt.pm-codeworks.de/pm-codeworks.list -P /etc/apt/sources.list.d/

We then update the available packages and install the Python library:

apt-get update
apt-get install python-fingerprint --yes

If an error has occurred (in particular, that not all dependent packages have been installed), then execute the following:

apt-get -f install

To return to the normal shell (under the Pi user), type exit.

By the way: If you prefer to use a C ++ library, you can look at this one from Adafruit (originally for Arduino). The Python library code is available on Github.

 

Test code & example scenario

First, we do a small test to see if the sensor is detected and ready for access. To do this, we run one of the sample files:

First, we do a small test to see if the sensor is detected and ready for access. To do this, we run one of the sample files:

python2 /usr/share/doc/python-fingerprint/examples/example_index.py

A total of up to 1000 different fingerprints can be stored. A finger can also be used several times for example. It can be stored in different positions so that they are detected more quickly / more clearly. The following should appear, which allows you to display the positions under which an imprint is stored by selecting a page (0-3).

If the error message “Exception message: The fingerprint sensor port “/dev/ttyUSB0″ was not found!” appears, something is wrong with the cabling or the sensor. Check it again.

 

Save and read out

Attached are sample files for storing a new fingerprint, reading out and deleting stored fingerprints. Let’s begin by recording a finger. Call the following:

python2 /usr/share/doc/python-fingerprint/examples/example_enroll.py

Put your finger on the glass surface, wait for the instruction in the terminal and remove your finger as soon as it is written there. Afterwards you have to put your finger a second time for the verification and the imprint is stored in the next number.

Let us also see whether our finger is recognized. So remove your finger from the sensor and call the following script:

python2 /usr/share/doc/python-fingerprint/examples/example_search.py

Put your finger on it again. If the fingerprint on the Raspberry Pi is detected, a message like this appears:

Currently stored templates: 2
Waiting for finger...
Found template at position #1
The accuracy score is: 63
SHA-2 hash of template: 3aa1b01149abf0a7ad0d7803eaba65c22ba084009700c3c7f5f4ecc38f020851

In this case, an accuracy value is also specified (the higher, the better).

In this directory, there are also other scripts with which you can delete stored impressions or even load them as a picture. With ls /usr/share/docs/python-fingerprint/ you can display all of those files.

I have made a small video as a pre-taste:

 

25 Responses

  1. Can you PLEASE do a video tutorial. I have been trying to complete this tutorial for weeks and I am about to give up… When I run the python code I get the Error “The fingerprint sensor could not be initilaized. Exception Message: The received packet do not begin with a valid header.”

    I have checked the wiring numerous times and I am at a loss

    Reply
  2. Hi, I don’t understand why in all fingerprint there some limit of memory store, so I thought the fingerprint is just like sensor so whenever you touch it, it will give you some code(hash,guid, some unique value), so you can store in database or some where else, so you can compare it second time, so why we need to use fingerprint’s memory, please correct me if I’m wrong

    Reply
  3. How we can automate calling py files ? The users won’t be calling any files in the real life

    Reply
  4. Is it possible to get the name of the person in to the system? I want to build a door unlocker with a personal message like “Hallo Dora” or somethink like that. Is that possible?
    Greetings

    Reply
    • In the original library, there is no such opportunity, but as the code is available on Github, you can fork and adapt it.

      Reply
  5. would you please tell me what I have to do with the following line?
    “python2 /usr/share/doc/python-fingerprint/examples/example_index.py”
    should I write it in terminal or what?

    Reply

Leave a Comment

Your email address will not be published.

Blog abonnieren

Abonniere Tutorials-RaspberryPi, um kein Tutorial mehr zu verpassen!