Adafruit Optical Fingerprint Sensor
Created by lady ada
https://learn.adafruit.com/adafruit-optical-fingerprint-sensor
Last updated on 2022-03-15 09:52:55 PM EDT
©Adafruit Industries
Page 1 of 27
Table of Contents
Overview
3
Enrolling vs. Searching
4
Enrolling New Users with Windows
4
Searching with the Software
9
Wiring for use with Arduino
10
•
•
•
•
Arduino UNO & Compatible Wiring
Hardware Serial Wiring
Soft & Hard Serial
Upload
12
13
14
15
Enrolling with Arduino
16
Python & CircuitPython
17
•
•
•
•
•
•
•
•
•
•
17
18
18
19
20
20
21
25
25
26
Sensor Wiring
CircuitPython Microcontroller Wiring
Python Computer Wiring
CircuitPython Fingerprint Library Installation
Python Installation of Fingerprint Library
CircuitPython & Python Usage
Example Code
Enrolling Prints
Finding Prints
Deleting Fingerprints
Python Docs
26
Downloads
26
©Adafruit Industries
Page 2 of 27
Overview
Secure your project with biometrics - this all-in-one optical fingerprint sensor will
make adding fingerprint detection and verification super simple. These modules are
typically used in safes - there's a high powered DSP chip that does the image
rendering, calculation, feature-finding and searching. Connect to any microcontroller
or system with TTL serial, and send packets of data to take photos, detect prints, hash
and search. You can also enroll new fingers directly - up to 162 finger prints can be
stored in the onboard FLASH memory.
We like this particular sensor because not only is it easy to use, it also comes with
fairly straight-forward Windows software that makes testing the module simple - you
can even enroll using the software and see an image of the fingerprint on your
computer screen. But, of course, we wouldn't leave you a datasheet and a "good
luck!" - we wrote a full Arduino library so that you can get running in under 10 minutes.
The library can enroll and search so its perfect for any project (https://adafru.it/aRz).
We've also written a detailed tutorial on wiring and use (https://adafru.it/clz). This is by
far the best fingerprint sensor you can get.
• Supply voltage: 3.6 - 6.0VDC
• Operating current: 120mA max
• Peak current: 150mA max
• Fingerprint imaging time: prompt.
Python Installation of Fingerprint Library
You'll need to install the Adafruit_Blinka library that provides the CircuitPython
support in Python. This may also require enabling the hardware UART on your
platform (see red note above) and verifying you are running Python 3. Since each
platform is a little different, and Linux changes often, please visit the CircuitPython on
Linux guide to get your computer ready (https://adafru.it/BSN)!
Once that's done, from your command line run the following command:
• sudo pip3 install adafruit-circuitpython-fingerprint
If your default Python is version 3 you may need to run 'pip' instead. Just make sure
you aren't trying to use CircuitPython on Python 2.x, it isn't supported!
CircuitPython & Python Usage
To demonstrate the usage of the sensor, we'll use the example python script included
with the library. This sensor is fairly complex so its hard to run it just from the REPL.
©Adafruit Industries
Page 20 of 27
CircuitPython Microcontroller Usage
Once you've installed the library, run this code.py example on your CircuitPython
board.
Linux/Computer/Raspberry Pi with Python
If you're running fingerprint_simpletest.py on the Raspberry Pi (or any computer),
you'll have to make some changes.
On the Raspberry Pi, comment out the uart = busio.UART(...) line, and
uncomment the applicable import serial and uart = serial.Serial(...)
lines, depending on whether you're using USB serial or hardware UART. Now you can
run the program with the following command:
python3 fingerprint_simpletest.py
Example Code
Remember, SAMD21 and other very-low-memory devices will not be able to run
the following example.
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
import time
import board
import busio
from digitalio import DigitalInOut, Direction
import adafruit_fingerprint
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT
uart = busio.UART(board.TX, board.RX, baudrate=57600)
# If using with a computer such as Linux/RaspberryPi, Mac, Windows with USB/serial
converter:
# import serial
# uart = serial.Serial("/dev/ttyUSB0", baudrate=57600, timeout=1)
# If using with Linux/Raspberry Pi and hardware UART:
# import serial
# uart = serial.Serial("/dev/ttyS0", baudrate=57600, timeout=1)
finger = adafruit_fingerprint.Adafruit_Fingerprint(uart)
##################################################
©Adafruit Industries
Page 21 of 27
def get_fingerprint():
"""Get a finger print image, template it, and see if it matches!"""
print("Waiting for image...")
while finger.get_image() != adafruit_fingerprint.OK:
pass
print("Templating...")
if finger.image_2_tz(1) != adafruit_fingerprint.OK:
return False
print("Searching...")
if finger.finger_search() != adafruit_fingerprint.OK:
return False
return True
# pylint: disable=too-many-branches
def get_fingerprint_detail():
"""Get a finger print image, template it, and see if it matches!
This time, print out each error instead of just returning on failure"""
print("Getting image...", end="", flush=True)
i = finger.get_image()
if i == adafruit_fingerprint.OK:
print("Image taken")
else:
if i == adafruit_fingerprint.NOFINGER:
print("No finger detected")
elif i == adafruit_fingerprint.IMAGEFAIL:
print("Imaging error")
else:
print("Other error")
return False
print("Templating...", end="", flush=True)
i = finger.image_2_tz(1)
if i == adafruit_fingerprint.OK:
print("Templated")
else:
if i == adafruit_fingerprint.IMAGEMESS:
print("Image too messy")
elif i == adafruit_fingerprint.FEATUREFAIL:
print("Could not identify features")
elif i == adafruit_fingerprint.INVALIDIMAGE:
print("Image invalid")
else:
print("Other error")
return False
print("Searching...", end="", flush=True)
i = finger.finger_fast_search()
# pylint: disable=no-else-return
# This block needs to be refactored when it can be tested.
if i == adafruit_fingerprint.OK:
print("Found fingerprint!")
return True
else:
if i == adafruit_fingerprint.NOTFOUND:
print("No match found")
else:
print("Other error")
return False
# pylint: disable=too-many-statements
def enroll_finger(location):
"""Take a 2 finger images and template it, then store in 'location'"""
for fingerimg in range(1, 3):
if fingerimg == 1:
print("Place finger on sensor...", end="", flush=True)
else:
©Adafruit Industries
Page 22 of 27
print("Place same finger again...", end="", flush=True)
while True:
i = finger.get_image()
if i == adafruit_fingerprint.OK:
print("Image taken")
break
if i == adafruit_fingerprint.NOFINGER:
print(".", end="", flush=True)
elif i == adafruit_fingerprint.IMAGEFAIL:
print("Imaging error")
return False
else:
print("Other error")
return False
print("Templating...", end="", flush=True)
i = finger.image_2_tz(fingerimg)
if i == adafruit_fingerprint.OK:
print("Templated")
else:
if i == adafruit_fingerprint.IMAGEMESS:
print("Image too messy")
elif i == adafruit_fingerprint.FEATUREFAIL:
print("Could not identify features")
elif i == adafruit_fingerprint.INVALIDIMAGE:
print("Image invalid")
else:
print("Other error")
return False
if fingerimg == 1:
print("Remove finger")
time.sleep(1)
while i != adafruit_fingerprint.NOFINGER:
i = finger.get_image()
print("Creating model...", end="", flush=True)
i = finger.create_model()
if i == adafruit_fingerprint.OK:
print("Created")
else:
if i == adafruit_fingerprint.ENROLLMISMATCH:
print("Prints did not match")
else:
print("Other error")
return False
print("Storing model #%d..." % location, end="", flush=True)
i = finger.store_model(location)
if i == adafruit_fingerprint.OK:
print("Stored")
else:
if i == adafruit_fingerprint.BADLOCATION:
print("Bad storage location")
elif i == adafruit_fingerprint.FLASHERR:
print("Flash storage error")
else:
print("Other error")
return False
return True
##################################################
def get_num():
"""Use input() to get a valid number from 1 to 127. Retry till success!"""
©Adafruit Industries
Page 23 of 27
i = 0
while (i > 127) or (i < 1):
try:
i = int(input("Enter ID # from 1-127: "))
except ValueError:
pass
return i
while True:
print("----------------")
if finger.read_templates() != adafruit_fingerprint.OK:
raise RuntimeError("Failed to read templates")
print("Fingerprint templates:", finger.templates)
print("e) enroll print")
print("f) find print")
print("d) delete print")
print("----------------")
c = input("> ")
if c == "e":
enroll_finger(get_num())
if c == "f":
if get_fingerprint():
print("Detected #", finger.finger_id, "with confidence",
finger.confidence)
else:
print("Finger not found")
if c == "d":
if finger.delete_model(get_num()) == adafruit_fingerprint.OK:
print("Deleted!")
else:
print("Failed to delete")
It's fairly long but it will help you set-up and test your sensor!
When you first start up, you should get something like this:
If you get an error like RuntimeError: Failed to read data from sensor it
means something went wrong - check your wiring and baud rate!
This menu system is fairly simple, you have three things you can do
• Enroll print - you will use your finger to take images and 'store' the model in the
sensor
• Find print - determine whether a fingerprint is known and stored
• Delete print - clear out a model
©Adafruit Industries
Page 24 of 27
Enrolling Prints
Enrolling a finger print is easy. Type e to start the process. You'll need to select a
location. The sensor can store up to 127 print locations. Pick a valid number, then
place your finger twice to enroll.
Note that after success, the Fingerprint templates: [...] printout will include the new
template id.
If an error occurs, the sensor will give you an error, such as if the two prints don't
match, or if it failed to store or generate a model:
Finding Prints
Once you've enrolled fingerprints you can then test them. Run the find command, and
try various fingers! Once the fingerprint id identified it will tell you the location
number, in this case #5
©Adafruit Industries
Page 25 of 27
Deleting Fingerprints
If you made a mistake you can remove fingerprint models from the database. For
example, here's how to delete #5. Note the Fingerprint templates: [...] printout
changes!
Python Docs
Python Docs (https://adafru.it/C4C)
Downloads
• Arduino interface library on github (https://adafru.it/aRz)
• User Manual (https://adafru.it/C4D)
• Datasheet (its not really a great datasheet and its in Chinese, but its better than
nothing) (https://adafru.it/aRB)
©Adafruit Industries
Page 26 of 27
• English version of the User Manual (https://adafru.it/C4D)
• "SFGDemo" Windows-only test software (https://adafru.it/aRC)
©Adafruit Industries
Page 27 of 27