• First Steps
  • General
  • Projects
Facebook Twitter YouTube
Tutorials for Raspberry Pi Tutorials for Raspberry Pi
  • Hardware & GPIO
  • Sensors & Components
  • Scale
  • Cases
  • Fingerprint
  • Gas Sensor
  • Heartbeat
  • German
  • French
Tutorials for Raspberry Pi Tutorials for Raspberry Pi
Home»Hardware & GPIO»How to use a Raspberry Pi Fingerprint Sensor for Authentication

How to use a Raspberry Pi Fingerprint Sensor for Authentication

Facebook Twitter LinkedIn Tumblr Email Reddit
How to use a Raspberry Pi Fingerprint Sensor for Authentication
Share
Facebook Twitter LinkedIn Email Tumblr Reddit Telegram WhatsApp

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

Shell
1
2
Currently stored templates: 0
Please enter the index page (0, 1, 2, 3) you want to see:

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:

Fingerprint Hausautomation Hausautomatisierung home automation python safety lock security
Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
Previous ArticleRaspberry Pi Heartbeat / Pulse measuring
Next Article Programmieren lernen am Raspberry Pi – Teil 1: Einführung

Related Posts

Control all GPIOs with the Raspberry Pi REST API via Python

How to build a ESP8266 Scale (with Weight Sensor HX711)

Using TensorFlow Lite with Google Coral TPU on Raspberry Pi 4

How-To: Bluetooth Connection between ESP32’s and Raspberry Pi’s

76 Comments

  1. omar on 30. July 2017 19:09

    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
    • Felix on 30. July 2017 20:05

      You could try a previous version from Github or contact the author directly?

      Reply
      • Samm on 19. August 2017 21:37

        I have the same problem, have u been able to solve it yet?

    • Panfilo Jr on 16. September 2017 20:18

      Try putting the fingerpint reader on a different voltage, switching the TX and RX, and/or building the package from here: https://github.com/bastianraschke/pyfingerprint/blob/Development/README.md

      Worked for me!

      Reply
    • Paarth Arkadi on 21. March 2019 15:47

      I solved this, by wiring the tx and rx pins properly.

      Reply
  2. Jamaxack on 10. August 2017 12:56

    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
    • Felix on 10. August 2017 13:06

      You probably could, but that’s how the author created his library – with limiations.

      Reply
    • Wessel on 7. January 2018 13:32

      Did you get any results? i want to save the fingerprints also in a database but i dont know how

      Reply
      • Finley on 10. July 2021 8:15

        Check out SQLAlchemy for Python, and look at storing your image as a “BLOB” data type.
        I tried it with .pdf and .jpg, and it worked fine.

    • Carlos on 28. July 2018 19:19

      yep.. wrong. The storage is IN the sensor itself.
      When you enroll, the hashes are stored INSIDE the sensor. When checking, it just informs in what template was the fingerprint found. As such, the capacity is defined by the sensor’s flash size.

      Reply
  3. Bineesh on 30. August 2017 1:14

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

    Reply
    • Felix on 9. September 2017 9:48

      You could use crontab or a init.d daemon.

      Reply
  4. Timo on 14. September 2017 14:32

    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
    • Felix on 15. September 2017 9:50

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

      Reply
    • hardy on 16. April 2019 14:30

      Hello @Timo, have you found something for your door unlocker? I’m searching something like that.
      thanks

      Reply
    • Hussain Mansoor on 16. August 2021 11:34

      Hi Timo, i am reading your message 4 years after yu posted it, i was actually making something u were making, a raspberry pi fingerprint sensor door unlocker, i would appreciate all the help and recommendations you might have, i am still in the research stage and havent purchased any equipemt

      Reply
  5. amr on 16. September 2017 12:31

    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
  6. abhijit kshirsagar on 30. October 2017 13:32

    can you please send me source code in python

    Reply
    • Felix on 31. October 2017 14:13

      It is on Github

      Reply
  7. Evan on 4. November 2017 1:03

    Thanks for the tutorial, Exception message : The received packet do not begin with a valid header, I had switch Tx and Rx header with no luck (/dev/ttyUSB0 detected, via using a TTL to usb adapter). The sensor works fine in windows with the provided windows only software. Maybe the ZFM-70 is not compatible with this library. Do you know by any chance how to manipulate the py files to be able to communicate with Z-70 or any github that have Z-70 driver written already (cant find it) Thanks in advance

    Reply
    • Eswar Karumuri on 10. December 2017 4:22

      Initially I got the error: Exception message : The received packet do not begin with a valid header, after switching RXD to Green & TXD to white, it started working.

      Reply
      • kiran R on 12. January 2018 7:08

        Hi,

        Good to know it worked for you…I am still struggling can you help me?

        Regards,
        Kiran

  8. Manasi on 20. December 2017 19:11

    Greetings,

    I have ZFM 20 sensor whenever i try to put it in 5V TTL pin it restarts the PI, when i put it in 3.3V it doesn’t recognize the USB.
    Could you pls help.
    Thank you!

    Reply
    • Felix on 20. December 2017 22:56

      Use a MCP3008…

      Reply
      • Manasi on 20. December 2017 23:40

        sure thank you . i will try doing that. Do you know if the same is possible in java?

      • Felix on 21. December 2017 19:24

        Should be, but I have not seen an implementation yet.

  9. Manasi on 22. December 2017 17:47

    Greetings,
    Thanks for your quick responses. I implemented it in python and works great. Thank you
    If i have to delete the entries, how do i do it? I see that in my case files are under doc not docs
    ls /usr/share/docs/python-fingerprint/
    Could you please help me with how to remove the entry. and can i use the same details in store them using java.
    Thank you! 🙂

    Reply
  10. Manasi on 22. December 2017 17:52

    Correction – I see that in my case files are under doc not docs
    “ls /usr/share/doc/python-fingerprint/”

    Reply
  11. Shubham on 1. January 2018 6:47

    Any way I could send the stored fingerprint to a database?

    Reply
    • Felix on 1. January 2018 14:52

      Yes, just print the data and save it anywhere you like.

      Reply
      • Manasi on 2. January 2018 19:32

        hi, right now is it saving it in the fingerprint sensor?
        Could you please help me with my earlier response?
        Thanks

      • Felix on 2. January 2018 19:37

        Yes, but as I remember, the library has a function to print the data. This could be used as an export.

  12. kiran R on 12. January 2018 7:06

    Hi,

    I have been trying to integrate Fingerprint sensor GT (511C1R) with the Raspberry Pi3, however, I still see this exception “The received packet does not begin with a valid header!” I am trying to connect it to the UBS/TTL but no luck. tried it on the SDK on windows it works but on Raspberry Pi it doesn’t. I would really appreciate if anyone could help me with this.

    I have tried all basic troubleshooting methods but nothing really takes this exception off the screen

    Regards,
    Kiran

    Reply
    • Trider on 8. April 2018 22:38

      hello I also have that problem with the same
      if you could solve it

      Reply
  13. viki on 22. February 2018 5:42

    i am trying it with r305 fr raspberry pi , it is not working i am getting error as sensor could not be initialised ,pls provide me a solution

    Reply
  14. Thắng on 14. March 2018 5:33

    Can you show me a diagram that connects the specific legs?

    Reply
    • Felix on 17. March 2018 18:32

      You have to use the colors of the wires.

      Reply
  15. Pablo on 9. May 2018 5:46

    Hi Felix! First of all, I want to thank you for writing this article. Now, here’s my question: I’m planning to use the “UART Fingerprint Reader STM32F205 TFS-D400”. I’m a bit masochistic and I like to struggle with low level programming, thus, my idea is to make my own lib. Do you know if all “uart fp readers” implements the same protocol? If the answer is yes, have you idea where can I find the specs for such protocol? Thank you very much in advance! Best regards!

    Reply
  16. Nalini on 13. July 2018 9:34

    Hello, I am using R305 with RPi3. I have stored few fingerprints and My problem is, sometimes sensor recognizes the fingers and sometimes not. Why is this happening, can someone tell me?

    Reply
    • manish on 8. April 2019 10:06

      hey, i am working with r305 and rpi3 . But i am getting error
      “The fingerprint sensor could not be initialized!
      Exception message: The received packet do not begin with a valid header!”

      did you get any problem like this? If yes, how you solved it.

      Reply
  17. Abdullah on 29. July 2018 13:03

    What is the fingerprint module has 3.3V to 6.0V range. Do I need to use the USB TTL to connect to the pi? If not, how are the connections to be made?
    Thanks

    Reply
  18. Scratchy on 5. September 2018 13:53

    Greetings

    Would like to know what the accuracy score is out of? I have manged to get the fingerprint sensor and code working (many thanks for the help). I get accuracy scores of 167 etc… Therefore i would like to know what the score it out of? (cant be a percentage)

    Reply
  19. sharad on 21. December 2018 11:26

    did anyone tried this with raspberry pi zero w ??

    Reply
    • sharad on 21. December 2018 11:29

      because i am able to enroll it without any issues but when I try to run example_downloadImage code i get the following error
      “Operation failed!
      Exception message: The received packet is corrupted (the checksum is wrong)!
      ”
      but i dont get any of this error if i am using raspberry pi 3 b+ …!!!

      Reply
  20. Tahir on 7. January 2019 10:57

    i design web-based Electronic voting system in which storing fingerprint into database and also retrieving data through fingerprint but i am getting stuck and don’t know how to resolve this problem if any suggestion kindly help me……

    Reply
    • Shubham on 31. January 2019 18:38

      CAN SIR YOU PLEASE TELL ME HOW TO TAKE FINGERPRINT DATA IN A MYSQL DB COULD YOU PLEASE HELP ME IN DETAIL PLEASE…URGENT?

      Reply
  21. Shisht on 3. February 2019 9:37

    Hello @Felix
    Thanks for this great library and working as expected but I am looking for, How can I store multiple fingerprints from the same user like right-hand-thumb and left-hand-thumb.
    As I know that we can do this kind of work as well as, we can store up to 10 fingerprints for the same user in this kind of devices.
    https://www.realtimebiometrics.com/product-detail.php?id=30&title=Realtime%20T52

    Reply
  22. Mubeen on 4. April 2019 12:48

    This is for python2, How can we use it python3.6??? is anybody worked on python3.6 with finger print module??

    Reply
  23. Francesco Turrini on 29. April 2019 9:33

    There is a library for C# Windows 10 for the fingerprint sensor?

    Reply
  24. chum on 28. May 2019 8:39

    Hi all,
    My requirement is adding finger print with corresponding user ID.

    When finger is detected at the time we should get the LCD message with user ID.

    How to Store finger template with corresponding ID

    Thanks in advance

    Reply
  25. Ashfaaq on 23. July 2019 9:08

    Hi,
    I tried to install the fingerprint library for raspberry pi ,by following the above mentioned instructions.But as soon as I started rooting and entering this url -> wget -O – http://apt.pm-codeworks.de/pm-codeworks.de.gpg | apt-key add – It shows me an error ->No such file or directory. please help in fixing this issue.

    Reply
  26. Andrew on 29. July 2019 18:20

    Hi there!

    Great guide! Already tried to accomplish this, also used a code matrix for additional possibilities to enter the door.

    I have bought this fingerprint-sensor:
    https://www.amazon.de/gp/product/028492038X/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1
    Im having issues with the Exception message: The received packet do not begin with a valid header!

    Already tried to switch RX and TX as mentioned above, but didn’t trie 3,3V as the specs from this fingerprint only says 3,6V DC!

    Im only facing this problem when I entered a valid finger and when waiting again for a finger it always gives me the valid header Error Message!

    Any suggestions?

    Thanks guys!

    Reply
    • Finley on 10. July 2021 8:25

      Is it possible you need to initialize the serial interface parameters? An example of these might be
      “9600 bits/sec, no parity, 2 stop bits”, etc. Does the fingerprint reader documentation discuss anything like that, e.g. what it’s expecting? It seems like the code seems data coming in, but can’t decode it into the right binary / ascii characters. Having an incorrectly initialized serial interface could be a reason for this. I’ve interfaced RPI with a geiger counter and a radio gateway, and both required this.
      Not sure what your reader expects but you could try some common values and see what happens.

      Reply
  27. William Flinchbaugh on 22. November 2019 5:14

    Would there theoretically be a way to attach a name or id to a fingerprint so that whenever a finger is recognized, it would say their name on the lcd? I need this because I’m trying to create an attendance system and I need the fingerprint when recognized to say that the one person is present. Any help?

    Reply
  28. Yanick on 13. December 2019 21:18

    This only works if the fingerprint reader use serial to USB. I have a USB-ready device, and this does not work whatsoever.

    Reply
  29. Deepak on 7. January 2020 15:40

    R307 fingerprint scanning not working in one attempt. after multiple attempt it detect finger.

    how to solve this problem ?

    Reply
  30. Victor Mudon 1923 https://www.google.com/ 1337271 on 23. July 2020 5:39

    glaksinyy8v@mail.ru

    Reply
  31. Alberto on 1. December 2020 22:27

    Hello,

    I’m using python 3 on raspberry pi 4 and fingerprint R307 sensor.
    I would like to store into fingerprint sensor a template I’ve in DB for future search, using “finger_search()” function of sensor.
    I try to save data in this way:
    data = [5, 1, …]
    finger.send_fpdata(data, “char”, 1)

    but when I run print(finger.count_templates()) to check the save, the result is 0 and the template isn’t saved

    Is there anyone who could help me

    Thanks

    Reply
    • robby on 31. August 2021 9:20

      Did you manage to find a solution

      Thanks

      Reply
  32. Chandramouli on 27. January 2021 6:12

    Can anyone share the C library for R305 fingerprint module interface to Raspberry PI?

    Reply
  33. Vrushali on 15. March 2021 19:50

    I get error as modulenotfound how to import fingerprint module in code part

    Reply
  34. Hassan on 21. September 2021 9:51

    Please Tell me Hardware Requirements with LCD Please

    Reply

Leave A Reply Cancel Reply

Raspberry Pi Tablet “Sunfounder RasPad” Review & Setup

Raspberry Pi and Arduino – Introduction

Telegram Messenger on the RaspberryPi

Build Your Own Raspberry Pi Weather Station with OpenHAB 2

Raspberry Pi Pico: Programming with the Affordable Microcontroller

Fan control for better Overclocking of the Raspberry Pi

Subscribe to Blog
Subscribe to Raspberry Pi Tutorials and don't miss any new Tutorial!
Subscribe

Thank you!

We will contact you soon.

Tutorials for Raspberry Pi
Facebook Twitter YouTube
  • Contact & Disclaimer

Type above and press Enter to search. Press Esc to cancel.