Adafruit Fingerprint: enroll and search on R30x and AS608 sensors
Yes. You can use the Adafruit Fingerprint Sensor Library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (Fingerprint sensor, R30x / AS608). The example below, "Finding a fingerprint with Adafruit Fingerprint", runs on the Arduino Uno R3.
Built in on Mokxi: #include <Adafruit_Fingerprint.h> and it builds, with nothing to install. Free, and no account needed.
What Adafruit Fingerprint Sensor Library does
Optical fingerprint modules in the R30x and AS608 families do the hard work inside: they take the image, turn it into a template, keep templates in their own memory and search them. The Arduino only sends commands over a serial line, at 57600 baud in the tutorials, and reads back a confirmation code. Adafruit’s library wraps each command in one call.
Every call returns that code, FINGERPRINT_OK (0) when it worked, so a sketch is a chain of steps that each check the last. Finding a finger is getImage(), image2Tz() and fingerFastSearch(), after which fingerID and confidence hold the result. Enrolling is two captures into slots 1 and 2 with image2Tz(1) and image2Tz(2), then createModel() to combine them and storeModel(id) to save it.
On an Uno the sensor goes on SoftwareSerial, since pins 0 and 1 carry the serial monitor; the example puts the sensor’s TX on pin 2 and its RX on pin 3. In Mokxi the fingerprint part represents a finger as a number you choose: two images match when they are the same finger, and the confidence is always 100. The example’s part holds two templates, so it finds ID #2 for finger 2 and reports no match for one it does not know.
| Library Manager name | Adafruit Fingerprint Sensor Library |
|---|---|
| Author | Adafruit |
| Include | #include <Adafruit_Fingerprint.h> |
| Boards | Arduino Uno, Arduino Nano, Arduino Mega 2560, Arduino Leonardo, SparkFun Pro Micro, Arduino Micro, Arduino Pro Mini 3.3 V, ESP8266 NodeMCU, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32 |
| In the simulator | Simulated: it runs against the part the way it does on the bench. |
| Parts it drives | Fingerprint sensor, R30x / AS608 |
Install it
It builds on Arduino Uno, Arduino Nano, Arduino Mega 2560, Arduino Leonardo, SparkFun Pro Micro, Arduino Micro, Arduino Pro Mini 3.3 V, ESP8266 NodeMCU, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32.
In Mokxi it is built in: #include <Adafruit_Fingerprint.h> and the sketch compiles, with no download, no zip and no Library Manager.
On a real board, install "Adafruit Fingerprint Sensor Library" by Adafruit from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add Adafruit Fingerprint Sensor Library to lib_deps in PlatformIO. Mokxi follows the calls of release 2.1.4, so a sketch written here builds there too.
What to know in the simulator: A finger is a number on the part: two images match when they are the same finger, and the confidence is a fixed 100.
The calls you will use
In the order a sketch meets them.
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial)
Creates the driver on a serial port, here a SoftwareSerial declared as SoftwareSerial mySerial(2, 3) with the sensor’s TX first.
finger.begin(57600)
Opens the port at the sensor’s baud rate. The library waits for the sensor’s start-up time before the first command.
finger.verifyPassword()
Sends the default password and returns true when the sensor replies, the standard check that it is connected.
finger.getImage()
Captures an image. Returns FINGERPRINT_NOFINGER while the window is empty and FINGERPRINT_OK once a finger is on it.
finger.image2Tz(1)
Turns the last image into features in slot 1 (or 2 when enrolling). With no argument it uses slot 1.
finger.fingerFastSearch()
Searches the stored templates for slot 1. On FINGERPRINT_OK, finger.fingerID is the match and finger.confidence the score; FINGERPRINT_NOTFOUND means no match.
if (finger.fingerFastSearch() == FINGERPRINT_OK) {
Serial.print("Found ID #");
Serial.println(finger.fingerID);
}finger.createModel()
Combines slots 1 and 2 into one template. FINGERPRINT_ENROLLMISMATCH means the two captures were not the same finger.
finger.storeModel(id)
Saves the template under an ID number in the sensor’s own memory.
finger.getTemplateCount()
Asks how many templates are stored and puts the answer in finger.templateCount.
finger.deleteModel(id)
Removes one stored template; emptyDatabase() removes them all.
Example: Finding a fingerprint with Adafruit Fingerprint
On the Arduino Uno R3. It runs in the browser exactly as printed.
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // the sensor's TX, RX
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
void setup() {
Serial.begin(9600);
Serial.println("Adafruit finger detect test");
finger.begin(57600);
if (finger.verifyPassword()) {
Serial.println("Found fingerprint sensor!");
} else {
Serial.println("Did not find fingerprint sensor :(");
while (1) { delay(1); }
}
finger.getTemplateCount();
Serial.print("Sensor contains ");
Serial.print(finger.templateCount);
Serial.println(" templates");
Serial.println("Waiting for valid finger...");
}
int getFingerprintIDez() {
if (finger.getImage() != FINGERPRINT_OK) return -1;
if (finger.image2Tz() != FINGERPRINT_OK) return -1;
if (finger.fingerFastSearch() != FINGERPRINT_OK) {
Serial.println("Did not find a match");
return -1;
}
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
return finger.fingerID;
}
void loop() {
getFingerprintIDez();
delay(50);
}Wiring
- Arduino Uno R3 2 to Fingerprint sensor, R30x / AS608 TX
- Arduino Uno R3 3 to Fingerprint sensor, R30x / AS608 RX
- Arduino Uno R3 5V to Fingerprint sensor, R30x / AS608 VCC
- Arduino Uno R3 GND to Fingerprint sensor, R30x / AS608 GND
Common errors and how to fix them
Did not find fingerprint sensor :(
verifyPassword() got no reply. The sensor’s TX must go to the first SoftwareSerial pin and its RX to the second; swapped wires are the usual cause. Also confirm the baud rate matches the module, 57600 by default.
An enrolled finger prints Did not find a match
The finger landed differently from when it was enrolled, or its template was stored under another ID or deleted. Enroll again with careful placement; in Mokxi, set the part to the finger number that was stored.
createModel() returns FINGERPRINT_ENROLLMISMATCH
The two captures did not agree. Wait for getImage() to return FINGERPRINT_NOFINGER between them so the finger is lifted, then place the same finger again.
Questions and answers
Where are the fingerprints stored?
In the sensor module, not on the Arduino, so they survive a power cut and a new sketch. Mokxi’s part does not model the template data that getModel() would upload.
Why is the confidence always 100 in Mokxi?
The simulated sensor matches by finger number rather than by image, so a match is exact and the part reports a fixed 100.
Projects that use Adafruit Fingerprint Sensor Library
Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.
Keep going
Try Adafruit Fingerprint Sensor Library without installing anything
Open the example, change the sketch, and keep your version in a free account.