Fingerprint Scanner with Raspberry Pi Single Board Computer - Unlock with Biometrics!

Updated 20 February 2023

Let's unlock Biometric Control on our Raspberry Pi Single Board Computers! Biometric Technology uses unique physical or behavioral attributes that are individual to each person and not (easily) replicable. Extraordinarily everyone on Earth has Unique Fingerprints, so let's explore what we can do with them! This will demonstrate the fastest way to install, program, and utilise a Fingerprint Scanner directly with a Raspberry Pi Single Board Computer. This guide will make adding fingerprint detection, capturing, and verification to any of your projects really quick.

Below is the fingerprint scanner we will use today connected to a Raspberry Pi 4 Model B and on the right you can see the scanner searching for fingerprints in a 3D printable wall mountable case. This specific scanner we will explore today is the Adafruit Optical Fingerprint Sensor which comes with a Socket Header Cable and electronic componentry.

One of these components is the DSP (Digital Signal Processor) chip which manages all the rendering, calculation, fingerprint feature finding, and searching on this module. This DSP chip is capable of storing 300 Unique Fingerprints inside the onboard flash memory. That means when you de-power the system the hardware will still remember all the enrolled fingerprints.

Any connected microcontroller (like an Arduino Uno) or microprocessor (like a Raspberry Pi 4 Model B) can communicate with it via TTL (UART) serial. The data sent can start the process to enroll new fingers, create a digital image of captured fingerprints, or for reporting back detected fingerprints. This means you can utilise your fingerprints to control GPIO-connected hardware. GPIO (General Purpose Input and Output) pins can be used to control an almost endless amount of sensors and mechanisms, like solenoids to unlock doors, LEDs to brighten your day, or any component your project requires. Here is my guide on controlling a 12V Solenoid with a Raspberry Pi Single Board Computer which could easily be triggerable by the Adafruit Fingerprint Scanner.

This guide will demonstrate how to enroll new fingerprints and how to control GPIO-attached hardware with your fingerprints. This will also demonstrate how to take digital images of your fingerprints. The contents of this guide are as follows.

- What you need
- Hardware Assembly
- Software Set Up
- Run Main Fingerprint Script
- Activate GPIO with a Known Fingerprint Script
- Where to Now (Creating a Digital Image of the Scanned Fingerprint)
- Downloads

The system created here is a form of biometric authentication. Fingerprint authentication automatically compares a user's fingerprint to a stored fingerprint template in order to validate a user's identity. There are three main types of fingerprint readers in use today, Optical, Ultrasound, and Capacitance. Optical Fingerprint Sensors are the traditional method and are the style utilised in this guide. It relies on a camera-like device to take a picture of a fingerprint placed on a layer of glass a set distance away. For extra security, some optical sensors also have extra components/run simple artificial intelligence to confirm that a live finger is being placed on the reader. Capacitance Fingerprint sensors are often found on mobile phones to unlock them. Capacitance sensors come in two styles, passive scanning where your raised ridges on your fingerprint form the other plate for each capacitor, or active scanning where the sensor has both plates and your fingerprint ridges alter the expected capacitance. These sensors require special construction to ensure high voltage electrostatic electricity doesn't ruin the sensing electronics. Ultrasound fingerprint sensors are the most recent method of fingerprint identification, only seen on a couple of high-end applications. They use ultrasound to sense the deeper dermal layer of your fingerprints. This means dirty or scratched-up fingers won't stop correct fingerprint identification.    

I have done Face Recognition with the Raspberry Pi which is another fantastic example of Biometric Control, link to that guide here. If you happen to be holding a Raspberry Pi board and are not quite sure what it is? Then check out this guide Raspberry Pi Generations to identify it. 

As always if you have any questions, queries, thoughts, or comments please let me know.

What You Need

Below is everything you need to set up your Raspberry Pi to work with an optical fingerprint scanner

- A Raspberry Pi Palm-Sized Computer (in my case I have used a Raspberry Pi 4 Model B 2GB but this can be done perfectly with a lower-spec Pi like the Raspberry Pi Zero 2)
- Adafruit Finger Print Scanner
- Micro-SD card flashed with Raspberry Pi OS
- Micro-HDMI to HDMI Cord to connect the system to a Monitor
- Power Supply
- Mouse and Keyboard

Hardware Build

The first step is to connect the provided wires to the scanner by carefully lining up the 8-pin 1mm pitch connectors, as you can see in the image below. Don't connect this backward. Also note, the female connector side is not perfectly parallel with the board and is delicate. To prevent damage push these two parts together gently and firmly by holding only the connector parts. Once connected it will not fall out easily. 

Then we will connect four wires coming out of the scanner to our Raspberry Pi Single Board computer exactly the same way as in the image below. Right-click the image and open it in a new tab to easily zoom into the image if you need. There are four wires coming out of the fingerprint scanner that will remain unconnected from anything. The red wire is for 3.3V power and should be connected to the 3.3V Power Pin on the Raspberry Pi. The White wire connects to the TX GPIO 14 Pin on the Raspberry Pi. The Yellow wire connects to RX GPIO 15 pin on the Raspberry Pi. The Black Wire is for the Ground and should connect to a Ground pin on the Raspberry Pi. This fingerprint scanner will break if you connect it to 5V so be sure to double-check that you have connected power to the 3.3V Pin before powering up the system.

Connecting up the Raspberry pi to the finger print scanner
With that complete, insert a micro-SD card flashed with Raspberry Pi OS and hook it up as a desktop computer. Add a mouse, keyboard, and HDMI to a monitor. Then power up the Raspberry Pi System by plugging in the USB-C power supply. The fingerprint scanner will illuminate as soon as you do. See all of these parts, as well as the mouse and keyboard, attached together below.

Set Up Completed for fingerprint scanner
With that done hardware assembly is completed!

Software Set up

Some packages will need to be installed and settings altered on your fresh version of Raspberry Pi OS. This will allow correct communication between the Finger Print Scanner and your Raspberry Pi. With the power into the system and the (new) first boot-up wizard complete, you will be welcomed by the Raspberry Pi Desktop. If you feel like you need extra help at this stage come check out this linked guide here.  

The first step is to turn on the Serial Port Connectivity, as this will enable the Raspberry Pi Single board computer to communicate with the Fingerprint Scanner through TTL UART Serial communication. By default, on Raspberry Pi OS this communication method is turned off. To turn this on open up the Raspberry Pi Configuration menu (found using the top left menu and scrolling over Preferences) and then enable the | Serial Port | connection found under the Interfaces tab. When here also make sure that the | Serial Console | has been turned off. See this happening in the image below.

Sorting UART for Fingerprint Scanner
Now with your system rebooted and connected to the internet, open a new terminal window by pressing the black button on the top left of the screen. This will open up a terminal window. See the image below of this happening and a big red arrow pointing toward the terminal button that was pressed.

This terminal window will enable us to download from the internet the exact packages we require. So now type and enter the following lines into the terminal to get all the packages that you will need. If prompted, type and enter | Y | to continue/confirm installations. See further below an image of one of these commands being downloaded and requesting this confirmation.

sudo pip3 install adafruit-circuitpython-fingerprint pyfingerprint

git clone

git clone

Terminal Commands being typed in
Once completed we have fully set up our Raspberry Pi Single Board Computer to work with the Finger Print Scanner. 

Run the Main Fingerprint Script

If you have followed through the above software section the Python scripts we want to run will already be on the system. The particular script we want is called | |. In the image below see the script directory location | /home/pi/Adafruit_CircuitPython_Fingerprint/examples | and also that file being right-clicked and opened up into Thonny IDE. Follow through and do the same so that this script is opened up in Thonny IDE.

Now we will need to adjust this | | Python script slightly so that It can work with our exact setup here. Comment out Line 14 by adding a | # | Symbol to the front of it. Un-Comment line 17 by deleting the | # | Symbol. Make sure to save the script after doing this. See this happening in the image below.

With that done we can now press the big green | run | button! This will spit out some information to the shell offering several options. Let's enroll our finger into the system. To do this type and enter |e|. Then type and enter |1| to ID index this fingerprint as the first one. Each fingerprint will have an index number associated with it and you can have 300 indexed fingerprints. See this happening in the images below.

Once you press enter it will take you through a text-based wizard to add a new finger. You will need to press your finger onto the scanner when it lights up two times. Follow through with the text requests and your first fingerprint will be enrolled within 10 seconds.

Bopping it
Then we can check whether it has been correctly enrolled by testing our system. At this stage type and enter | f |. Then place that same finger onto the scanner. Confirm that the shell output a similar message to mine, as you can see in the image below. If so you have successfully enrolled a finger and then successfully identified your fingerprint! Sweet! It even provides a confidence value from 0 to 255. In my case, I got a confidence score of 183. Incorporating confidence scores into your project only makes sense for higher security applications. If the scanner confirms a detection you can feel pretty self-assured with it.

Activate GPIO with a Known Fingerprint Script

Let's now control some GPIO with our fingerprint. Utilising a Breadboard I have added a LED and resistor in series to GPIO21 and a Ground Pin on the Raspberry Pi Single Board Computer. The end goal here is to turn on the LED based on our correctly identified fingerprint. GPIO is the gateway to the rest of the world and this LED is simply a placeholder to represent whatever hardware you want to connect to. If you want some tips regarding breadboards check out this linked guide here. See the image below for this setup.

The script name is | |. You can copy and paste it from below, or download all the scripts talked about in this guide from the zip file found at the bottom of the page. Open it in the same way as before into Thonny IDE. 

#!/usr/bin/env python
# -*- coding: utf-8 -*-

Originally a Bastian Raschke Example 
Modified by Tim for GPIO LED Control


import hashlib
from pyfingerprint.pyfingerprint import PyFingerprint
from pyfingerprint.pyfingerprint import FINGERPRINT_CHARBUFFER1

#LED is attached to the GPIO numbered below
Pin = 21

#Import Time, and set up the GPIO, stop warnings, and activate the LED GPIO as an output (defaults to LOW Voltage) 
import time
import RPi.GPIO as GPIO
GPIO.setup(Pin, GPIO.OUT)

## Search for a finger

## Tries to initialize the sensor
    f = PyFingerprint('/dev/ttyS0', 57600, 0xFFFFFFFF, 0x00000000)

    if ( f.verifyPassword() == False ):
        raise ValueError('The given fingerprint sensor password is wrong!')

except Exception as e:
    print('The fingerprint sensor could not be initialized!')
    print('Exception message: ' + str(e))

## Gets some sensor information
print('Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity()))

## Tries to search the finger and calculate hash
    print('Waiting for finger...')

    ## Wait that finger is read
    while ( f.readImage() == False ):

    ## Converts read image to characteristics and stores it in charbuffer 1

    ## Searchs template
    result = f.searchTemplate()

    positionNumber = result[0]
    accuracyScore = result[1]

    if ( positionNumber == -1 ):
        print('No match found!')

#This Else statement is only reached when an Index Finger is Detected
        print('Found template at position #' + str(positionNumber))
        print('The accuracy score is: ' + str(accuracyScore))

#Because we have reached this else statement we had detected an enrolled finger
#This means we can now toggle the LED. This is done with the three lines below.
        GPIO.output(Pin, GPIO.HIGH)
        GPIO.output(Pin, GPIO.LOW)

    ## OPTIONAL stuff

    ## Loads the found template to charbuffer 1
    f.loadTemplate(positionNumber, FINGERPRINT_CHARBUFFER1)

    ## Downloads the characteristics of template loaded in charbuffer 1
    characterics = str(f.downloadCharacteristics(FINGERPRINT_CHARBUFFER1)).encode('utf-8')

    ## Hashes characteristics of template
    print('SHA-2 hash of template: ' + hashlib.sha256(characterics).hexdigest())

except Exception as e:
    print('Operation failed!')
    print('Exception message: ' + str(e))

With the script open in Thonny IDE you should be good to go. If you run into errors double-check that anywhere in the script where it has | /dev | it looks like | /dev/ttyS0 |. This will target the correct communication serial port. The light of the Finger Print Scanner will be lit and now you can place your finger onto the Fingerprint Scanner. As soon as you do it'll attempt to identify your fingerprint and if it is one that has been indexed it will turn on the LED for a second. See this happening in the image below.

Now, this doesn't just have to be an LED, it could very easily be a solenoid to unlock a door or a gate that opens up once it receives the correct fingerprint. And those are just two ideas, you can take this concept to wherever your imagination desires! With your Biometrics as the control lever. Check this guide on controlling a 12V Solenoid with a Raspberry Pi if you want any tips on doing this.

Where to Now (Creating a Digital Image of the Scanned Fingerprint)

I really wanted to see what the image of my fingerprint looked like through the Fingerprint Scanner. The script | | can be found in the downloadable zip file at the bottom of this article or beneath the image written in full. Whenever you run this script (using Thonny IDE in the same manner as before) and press your finger on the scanner it will export a BMP image of your fingerprint. It does take ~10 seconds to do so. See my (modified for security) fingerprint below!

#!/usr/bin/env python
# -*- coding: utf-8 -*-
##Copyright (C) 2015 Bastian Raschke 
#All rights reserved.

import tempfile
from pyfingerprint.pyfingerprint import PyFingerprint

## Reads image and download it

## Tries to initialize the sensor
    f = PyFingerprint('/dev/ttyS0', 57600, 0xFFFFFFFF, 0x00000000)

    if ( f.verifyPassword() == False ):
        raise ValueError('The given fingerprint sensor password is wrong!')

except Exception as e:
    print('The fingerprint sensor could not be initialized!')
    print('Exception message: ' + str(e))

## Gets some sensor information
print('Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity()))

## Tries to read image and download it
    print('Waiting for finger...')

    ## Wait that finger is read
    while ( f.readImage() == False ):

    print('Downloading image (this take a while)...')

    imageDestination =  tempfile.gettempdir() + '/fingerprint.bmp'

    print('The image was saved to "' + imageDestination + '".')

except Exception as e:
    print('Operation failed!')
    print('Exception message: ' + str(e))

Big thanks goes to Bastian Raschke for this script, to check out more of his output check his GitHub page here.

With this technology in your toolbelt, you'll be harvesting all your friend's fingerprints in no time. So if you ever wake up and feel like everyone has been replaced with an identical twin version you can use your fingerprint data to confirm or refute this hypothesis. Identical twins don't have matching fingerprints after all.


Here is a Download Link for all the Python Scripts utilised in this guide. That Zip file also has the 3D printable Wall Mountable Case seen at the start of this guide. Check here for the original Thingiverse link for this case. For ideas on what to do with these fingerprint scanners just check out this!

Have a question? Ask the Author of this guide today!

Please enter minimum 20 characters

Your comment will be posted (automatically) on our Support Forum which is publicly accessible. Don't enter private information, such as your phone number.

Expect a quick reply during business hours, many of us check-in over the weekend as well.



Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.