Adafruit Optical Fingerprint Sensor: Created by Lady Ada
Adafruit Optical Fingerprint Sensor: Created by Lady Ada
Guide Contents 2
Overview 3
Enrolling vs. Searching 5
Enrolling New Users with Windows 6
Searching with the Software 12
Wiring for use with Arduino 13
Arduino UNO & Compatible Wiring 14
Hardware Serial Wiring 15
Soft & Hard Serial 16
Upload 17
Enrolling with Arduino 18
Python & CircuitPython 19
Sensor Wiring 19
CircuitPython Microcontroller Wiring 20
Python Computer Wiring 20
CircuitPython Fingerprint Library Installation 22
Python Installation of Fingerprint Library 22
CircuitPython & Python Usage 22
CircuitPython Microcontroller Usage 23
Linux/Computer/Raspberry Pi with Python 23
Example Code 23
Enrolling Prints 27
Finding Prints 28
Deleting Fingerprints 28
Python Docs 30
Downloads 31
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: <1.0 seconds
Window area: 14mm x 18mm
Signature file: 256 bytes
Template file: 512 bytes
Storage capacity: 162 templates
You can enroll using the Windows software (easiest and neat because it shows you the photograph of the
print) or with the Arduino sketch (good for when you don't have a Windows machine handy or for on-the-
road enrolling).
First up, you'll want to connect the sensor to the computer via a USB-serial converter. The easiest way to
do this is to connect it directly to the USB/Serial converter in the Arduino. To do this, you'll need to upload
a 'blank sketch' this one works well for "traditional" Arduinos, like the Uno and the Mega:
void setup() {}
void loop() {}
The "blank" sketch won't work for "native USB" based Arduinos like the Leonardo, Micro, Zero,
etc! Use the Leo_passthru sketch instead!
If you're using a Leonardo, Micro, Yun, Zero, or other native-USB device like ATSAMD21 or ATmega32U4-
based controller, use the Leo_passthru sketch instead of the "blank" sketch.
void setup() {
// put your setup code here, to run once:
Serial1.begin(57600);
Serial.begin(57600);
}
void loop() {
while (Serial.available())
Serial1.write(Serial.read());
while (Serial1.available())
Serial.write(Serial1.read());
}
Wire up the sensor as described in the sketch comments after uploading the sketch. Since the sensor
wires are so thin and short, we stripped the wire a bit and melted some solder on so it made better
contact but you may want to solder the wires to header or similar if you're not getting good contact. When
you plug in the power, you may see the LED blink to indicate the sensor is working.
If your sensor has all the same-color wires, The first wire
from the left is ground, then the two data pins, then
power. You'll have to cut, strip and solder the wires.
Start up the SFGDemo software and click Open Device from the bottom left corner. Select the COM port
used by the Arduino.
If you get an error when you Open Device, check your wiring, try swapping the RX and TX wires
on the sensor, that's a common mixup!
The software will ask you to press the finger to the sensor
You can then see a preview (if you cliecked the preview checkbox) of the fingerprint.
It is normal for the sensor to blink the LED quickly once powered, after that the LED may stay off
until you've started to request data from it
The first wire from the left should be the black wire
ground
then the two data pins: Serial RX is the white wire
Serial TX is the green wire
Then the red power wire.
In the diagrams below we show the wires plugged directly into the Arduino. However, this does
Type in Fingerprint until you see the Adafruit Fingerprint library show up!
Click Install! That's it. Now you should be able to select the
File→Examples→Adafruit_Fingerprint→fingerprint example sketch.
// On Leonardo/Micro or others with hardware serial, use those! #0 is green wire, #1 is white
// uncomment this line:
#define mySerial Serial1
// For UNO and others without hardware serial, we must use software serial...
// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino (WHITE wire)
// comment these two lines if using hardware serial
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(2, 3);
If you can't get 'connected' to the sensor the library says "Did not find fingerprint sensor :(" Try
swapping the RX and TX wires and resetting
The 'confidence' is a score number (from 0 to 255) that indicates how good of a match the print is, higher
is better. Note that if it matches at all, that means the sensor is pretty confident so you don't have to pay
attention to the confidence number unless it makes sense for high security applications.
Of course you have to have enrolled a fingerprint first! If you did this using the Windows program, that's
good to go. If you have not yet, you should at least have gotten a Found fingerprint sensor! printout. You
can go ahead to the next step to enroll fingerprints.
If you get Did not find fingerprint sensor :( check your wiring, maybe swap the RX and TX wire as that's a
common issue
If you want to have a more detailed report, change the loop() to run getFingerprintID() instead of
getFingerprintIDez() - that will give you a detailed report of exactly what the sensor is detecting at each
point of the search process.
Run the File→Examples→Adafruit_Fingerprint→enroll sketch and upload it to the Arduino, use the same
wiring as above.
When you open up the serial monitor, it will ask for you to type in the ID to enroll - use the box up top to
type in a number and click Send.
Then go through the enrollment process as indicated. When it has successfully enrolled a finger, it will
print Stored!
Don't forget to do a search test when you're done enrolling to make sure its all good!
You can use this sensor with any CircuitPython microcontroller board or with a computer that has GPIO
and Python thanks to Adafruit_Blinka, our CircuitPython-for-Python compatibility
library (https://adafru.it/BSN).
Sensor Wiring
If your sensor has different wires, The first wire from the
left should be the black wire ground, then the two data
pins, RX is the white wire, TX is the green wire then the
red power wire. You'll have to cut, strip and solder thicker
gauge wires to the current wires.
If your sensor has all the same-color wires, The first wire
from the left is ground, then the two data pins, then
power. You'll have to cut, strip and solder the wires.
In the diagrams below we show the wires plugged directly into the Trinket. However, this does
not work well because the wires are so thin and they dont make contact. You should solder
thicker solid core wires to each wire, to make good contact. NOTE: Both ends of the cable plug
into the fingerprint sensor - verify that you're removing the correct end of it before cutting
anything off. Your wiring order should match the image above with the fingerprint sensor upside
down.
Every CircuitPython board has a hardware UART. Check the product page or look for RX and TX written
on the board. Remember that the RX from the sensor goes to the TX on the board! If you have problems
try swapping them, it's a common mistake.
Be aware that SAMD21 and other very-low-memory devices will not be able to run this example.
Here you have two options: An external USB-to-serial converter, or the built-in UART on the Pi's TX/RX
pins. Here's an example of wiring up the USB-to-serial converter (https://adafru.it/dDd):
If you want to use the built-in UART, you'll need to disable the serial console and enable the serial port
hardware in raspi-config. See the UART/Serial section of the CircuitPython on Raspberry Pi
guide (https://adafru.it/CEk) for detailed instructions on how to do this.
Note SBC boards other than the Raspberry Pi may or may not have a hardware UART available
on thee I/O pins or may have them permanently mapped to the console, etc. Refer to your
board's documentation to see if there is a hardware UART, where it is located, how to enable it,
First make sure you are running the latest version of Adafruit CircuitPython (https://adafru.it/Amd) for your
board.
Next you'll need to install the necessary libraries to use the hardware--carefully follow the steps to find
and install these libraries from Adafruit's CircuitPython library bundle (https://adafru.it/ENC). Our
introduction guide has a great page on how to install the library bundle (https://adafru.it/ABU) for both
express and non-express boards.
Copy the necessary file from the library bundle to the lib folder on your CIRCUITPY drive:
adafruit_fingerprint.mpy
Before continuing make sure your board's lib folder has the adafruit_fingerprint.mpy file copied over.
Next connect to the board's serial REPL (https://adafru.it/Awz)so you are at the CircuitPython >>> prompt.
Once that's done, from your command line run the following command:
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!
Once you've installed the library, run this code.py example on your CircuitPython board.
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.
import time
import board
import busio
from digitalio import DigitalInOut, Direction
import adafruit_fingerprint
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT
# 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)
finger = adafruit_fingerprint.Adafruit_Fingerprint(uart)
##################################################
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
# 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:
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
if fingerimg == 1:
print("Remove finger")
time.sleep(1)
while i != adafruit_fingerprint.NOFINGER:
i = finger.get_image()
return True
##################################################
def get_num():
"""Use input() to get a valid number from 1 to 127. Retry till success!"""
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:
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
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.
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
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!