Introduction
This fully integrated capacitive fingerprint sensor provides an efficient way for users to capture, process, store, and match fingerprints. Based on high-performance processor & semiconductor fingerprint sensor, it's equipped with built-in IDfinger6.0 fingerprint algorithm that enables it to complete fingerprint recognition independently. And when working with DFRobot Arduino library, the sensor can realize functions like fingerprint entry, deletion and matching through UART. Also, upper computer software is provided to help users easily operate it.
This low-power sensor comes with a compact size and delicate appearance, and offers fast recognition and high security. Moreover, it supports 360-degree any view object recognition and deep self-learning.
Note:
It is recommended to use hardware serial to drive this sensor module as it may be unstable and thus result in unknown errors when using software serial. It is suggested to reduce the module's baud rate to 9600 when using software serial driver.
API: fingerprint.setBaudrate(fingerprint.e9600bps);
As this module has no LED lamp ring, so the codes for controlling LED in the sample code and the description about LED are invalid.
Features
- 360-degree fingerprint entry and matching
- Self-learning function
- Compact size, easy to install
Application
- Fingerprint door lock
- Drawer Lock
- ID Recognition
- Authorization
Specification
- Operating Voltage: 3.3V
- Operating Current: <40mA
- Communication Method: UART
- Storage Capacity: 80 fingerprints
- 1: N Verification Time: <0.5S
- Pixel Resolution: 508dpi
- Number of Pixels: 160x160
- Operating Environment: -10-60℃/20%-80%RH
- Dimension: diameter of 19mm/0.75"
Board Overview
Num | Label | Description |
---|---|---|
Pin 1 | GND | Ground |
Pin 2 | RX | UART receive |
Pin 3 | TX | UART transmit |
Pin 4 | VIN | Processor Power supply (3.3V): operate when powered on, enter sleep mode when powered off |
Pin 5 | IRQ | Finger sensing output: active high |
Pin 6 | 3.3V | Power supply for collector |
Tutorial
Requirements
- Hardware
- DFRduino Leonardo (or similar) × 1
- Capacitive Fingerprint Sensor - UART (FPC Connector) × 1
- DuPont Wires
- Software
- Arduino IDE
- Download and install the ID809 Library (About how to install the library?)
- Frequently-used API Functions
/**
* @brief Test whether the module is properly connected
* @return true or false
*/
bool isConnected();
/**
* @brief Detect whether the module is touched by a finger
* @return 1(Yes) or 0(No)
*/
uint8_t detectFinger();
/**
* @brief Get the first registrable ID number
* @return Registrable ID number or ERR_ID809
*/
uint8_t getEmptyID();
/**
* @brief Check whether the ID has been registered
* @return 0(Registered), 1(Not Registered) or ERR_ID809
*/
uint8_t getStatusID(uint8_t ID);
/**
* @brief Get the number of registered users
* @return Number of registered users or ERR_ID809
*/
uint8_t getEnrollCount();
/**
* @brief Get the list of registered users
* @return 0(succeed) or ERR_ID809
*/
uint8_t getEnrolledIDList(uint8_t* list);
/**
* @brief Capture fingerprint
* @return 0(succeed) or ERR_ID809
*/
uint8_t collectionFingerprint(uint16_t timeout);
/**
* @brief Save fingerprint
* @param Fingerprint ID
* @return 0(succeed) or ERR_ID809
*/
uint8_t storeFingerprint(uint8_t ID);
/**
* @brief Delete fingerprint
* @param Finerprint ID or DELALL(delete all)
* @return 0(succeed) or ERR_ID809
*/
uint8_t delFingerprint(uint8_t ID);
/**
* @brief Match the fingerprint with all fingerprints
* @return Successfully matched fingerprint, 0(Finerprint matching failed) or ERR_ID809
*/
uint8_t search();
/**
* @brief Match the fingerprint with a designated fingerprint
* @return Successfully matched fingerprint ID, 0(Finerprint matching failed) or ERR_ID809
*/
uint8_t verify(uint8_t ID);
/**
* @brief Get error information
* @return Text description of error information
*/
String getErrorDescription();
/*Set module baud rate, available range:
e9600bps e19200bps e38400bps e57600bps e115200bps
1 2 3 4 5
*/
fingerprint.setBaudrate(fingerprint.e115200bps);
Connection Diagram
Sample Code 1 - Query Module Baud Rate
The module's baud rate is 115200 by default. You can use the following codes to query if you don't know its buad rate (the buad rate will not be restored to the default when the module is power off).
/*!
* @file queryDeviceBPS.ino
* @brief Query device baud rate
* @n Experiment Phenomenon:Query device baud rate, and print from serial port
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @licence The MIT License (MIT)
* @author [Eddard](Eddard.liu@dfrobot.com)
* @version V1.0
* @date 2020-03-19
* @get from https://www.dfrobot.com
* @url https://github.com/DFRobot/DFRobot_ID809
*/
#include <DFRobot_ID809.h>
/*Use software serial when using UNO or NANO*/
#if ((defined ARDUINO_AVR_UNO) || (defined ARDUINO_AVR_NANO))
#include <SoftwareSerial.h>
SoftwareSerial Serial1(2, 3); //RX, TX
#define FPSerial Serial1
#else
#define FPSerial Serial1
#endif
DFRobot_ID809 fingerprint;
uint32_t ID809_BPS[5] = {9600, 19200, 38400, 57600, 115200};
uint8_t i = 0;
void setup(){
/*Init print serial port */
Serial.begin(9600);
/*Test module baud rate */
FPSerial.begin(ID809_BPS[i]);
Serial.print(".");
while(fingerprint.begin(FPSerial) == false){
i++;
FPSerial.begin(ID809_BPS[i]);
Serial.print(".");
}
Serial.println(" ");
}
void loop(){
Serial.print("Module baud rate:");
Serial.println(ID809_BPS[i-1]);
Serial.println("-----------------------------");
delay(1000);
}
- Expected Result 1
Sample Code 2 - Get or Set Module Information
Get and serial print the module information.
/*!
* @file getDeviceInformation.ino
* @brief Get fingerprint module information
* @n Experiment Phenomenon:serial print module ID, security level, baud rate, etc.
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (https://www.dfrobot.com)
* @licence The MIT License (MIT)
* @author [Eddard](Eddard.liu@dfrobot.com)
* @version V1.0
* @date 2020-03-19
* @get from https://www.dfrobot.com
* @url https://github.com/DFRobot/DFRobot_ID809
*/
#include <DFRobot_ID809.h>
/*Use software serial when using UNO or NANO*/
#if ((defined ARDUINO_AVR_UNO) || (defined ARDUINO_AVR_NANO))
#include <SoftwareSerial.h>
SoftwareSerial Serial1(2, 3); //RX, TX
#define FPSerial Serial1
#else
#define FPSerial Serial1
#endif
DFRobot_ID809 fingerprint;
//String desc; //Error code information, enabling this function will consume much memory
void setup(){
/*Initialize serial port for printing*/
Serial.begin(9600);
/*Initialize FPSerial*/
FPSerial.begin(115200);
/*Use FPSerial as communication serial port of module*/
fingerprint.begin(FPSerial);
/*Wait for Serial to open*/
while(!Serial);
/*Test whether device can communicate properly with mainboard,
Return true or false
*/
while(fingerprint.isConnected() == false){
Serial.println("Communication with device failed, please check connection");
/*Get error code information*/
//desc = fingerprint.getErrorDescription();
//Serial.println(desc);
delay(1000);
}
}
uint8_t enrollCount; //Number of registered users
void loop(){
/*Set module ID, available range: 1-255*/
//fingerprint.setDeviceID(/*Device ID = */1);
Serial.print("Module ID:");
/*Read module ID*/
Serial.println(fingerprint.getDeviceID());
/*Set module security level, range 1-5, Default level 3
Security Level Recognition rate
Level 1 FAR 0.1%
FRR 0.005%
Level 2 FAR 0.003%
FRR 0 01%
Level 3 FAR 0.001%
FRR 0.1%
Level 4 FAR 0.003%
FRR 0.5%
Level 5 FAR 0.0001%
FRR 1%
*/
//fingerprint.setSecurityLevel(/*Security Level = */3);
Serial.print("Module security level:");
/*Read module security level*/
Serial.println(fingerprint.getSecurityLevel());
/*Set module baud rate, available range:
e9600bps e19200bps e38400bps e57600bps e115200bps
1 2 3 4 5
*/
//fingerprint.setBaudrate(fingerprint.e115200bps);
Serial.print("Module baud rate:");
/*Read module baud rate*/
Serial.println(fingerprint.getBaudrate());
/*Set module self-learning function, 1(ON) 0(OFF)*/
//fingerprint.setAutoLearn(/*Auto Learn = */1);
Serial.print("Module self-learning function:");
/*Read the state of module self-learning function
Print ON if it is enabled, otherwise print OFF*/
Serial.println(fingerprint.getSelfLearn()?"ON":"OFF");
/*Set module serial number, the number of characters of serial number should be small than 15*/
//fingerprint.setModuleSN(/*Module SN = */"DFRobot");
Serial.print("Module serial number:");
/*Read module serial number*/
Serial.println(fingerprint.getModuleSN());
Serial.print("Number of registered fingerprints in the module:");
/*Get the number of registered users*/
Serial.println(enrollCount = fingerprint.getEnrollCount());
/*Declare an array to hold ID list*/
uint8_t list[80] = {0};
/*Get user list
Pass an array of pointer to receive ID list
*/
fingerprint.getEnrolledIDList(list);
Serial.print("ID list of registered users:");
for(uint8_t i = 0; i < enrollCount; i++){
Serial.print(list[i]);
Serial.print(",");
}
Serial.print("\nNumber of broken fingerprints:");
/*Get the number of broken fingerprints*/
Serial.println(fingerprint.getBrokenQuantity());
/*Get the ID of the first broken fingerprint*/
//fingerprint.getBrokenID();
Serial.println("-----------------------------");
delay(1000);
}
- Expected Result 2
Sample Code 3 - Add Fingerprints
This sample automatically obtains the registrable ID, then collects the fingerprint three times, and the yellow light flashes three times when collecting succeeded. At last, save the fingerprint to the obtained unregistered ID, and the green light will be on for 1s, then be off.
/*!
* @file fingerprintRegistration.ino
* @brief Get and save fingerprint
* @n This module can be controlled by hardware serial or software serial
* @n Experiment Phenomenon:auto retrieve unregistered ID, collect fingerprint 3 times.
* @n In collecting, set LED ring to breathing lighting in blue, and then to quick blink in yellow 3 times when completed
* @n At last, save the fingerprint in an unregistered ID,
* @n the green LED lights up for 1s and turns off.
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (https://www.dfrobot.com)
* @licence The MIT License (MIT)
* @author [Eddard](Eddard.liu@dfrobot.com)
* @version V1.0
* @date 2020-03-19
* @get from https://www.dfrobot.com
* @url https://github.com/DFRobot/DFRobot_ID809
*/
#include <DFRobot_ID809.h>
#define COLLECT_NUMBER 3 //Fingerprint sampling times, can be set to 2-3
/*Use software serial when using UNO or NANO*/
#if ((defined ARDUINO_AVR_UNO) || (defined ARDUINO_AVR_NANO))
#include <SoftwareSerial.h>
SoftwareSerial Serial1(2, 3); //RX, TX
#define FPSerial Serial1
#else
#define FPSerial Serial1
#endif
DFRobot_ID809 fingerprint;
//String desc; //Error code information, enabling this function will consume much memory
void setup(){
/*Initialize serial port for printing*/
Serial.begin(9600);
/*Initialize FPSerial*/
FPSerial.begin(115200);
/*Use FPSerial as communication serial port of module*/
fingerprint.begin(FPSerial);
/*Wait for Serial to open*/
while(!Serial);
/*Test whether device can communicate properly with mainboard,
Return true or false
*/
while(fingerprint.isConnected() == false){
Serial.println("Communication with device failed, please check connection");
/*Get error code information*/
//desc = fingerprint.getErrorDescription();
//Serial.println(desc);
delay(1000);
}
}
uint8_t ID,i,ret;
void loop(){
/*Get an unregistered ID for saving fingerprint
Return ID when succeeded,
Return ERR_ID809 if failed
*/
if((ID = fingerprint.getEmptyID()) == ERR_ID809){
while(1){
/*Get error code information*/
//desc = fingerprint.getErrorDescription();
//Serial.println(desc);
delay(1000);
}
}
Serial.print("unresistered ID, ID=");
Serial.println(ID);
i = 0; //Clear sampling times
/*Fingerprint sampling 3 times*/
while(i < COLLECT_NUMBER){
/*Set fingerprint LED ring mode, color, and number of blinks,
Can be set as follows:
Parameter 1:<LEDMode>
eBreathing eFastBlink eKeepsOn eNormalClose
eFadeIn eFadeOut eSlowBlink
Parameter 2:<LEDColor>
eLEDGreen eLEDRed eLEDYellow eLEDBlue
eLEDCyan eLEDMagenta eLEDWhite
Parameter 3:<Number of blinks> 0 represents blinking all the time,
This parameter will only be valid in mode eBreathing, eFastBlink and eSlowBlink
*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eBreathing, /*LEDColor = */fingerprint.eLEDBlue, /*blinkCount = */0);
Serial.print("The fingerprint sampling of the");
Serial.print(i+1);
Serial.println("(th) is being taken");
Serial.println("Please press down your finger");
/*Capture fingerprint image, 10s idle timeout, if timeout=0, disable the collection timeout function
If succeeded, return 0, otherwise, return ERR_ID809
*/
if((fingerprint.collectionFingerprint(/*timeout = */10)) != ERR_ID809){
/*Set fingerprint LED ring to quick blink in yellow 3 times*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eFastBlink, /*LEDColor = */fingerprint.eLEDYellow, /*blinkCount = */3);
Serial.println("Sampling succeeds");
i++; //Sampling times +1
}else{
Serial.println("Sampling failed");
/*Get error code information*/
//desc = fingerprint.getErrorDescription();
//Serial.println(desc);
}
Serial.println("Please release your finger");
/*Wait for finger to release
Return 1 when finger is detected, otherwise return 0
*/
while(fingerprint.detectFinger());
}
/*Save fingerprint in an unregistered ID*/
if(fingerprint.storeFingerprint(/*Empty ID = */ID) != ERR_ID809){
Serial.print("Saving succeed, ID=");
Serial.println(ID);
Serial.println("-----------------------------");
/*Set fingerprint LED ring to be always ON in green*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eKeepsOn, /*LEDColor = */fingerprint.eLEDGreen, /*blinkCount = */0);
delay(1000);
/*Turn off fingerprint LED ring*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eNormalClose, /*LEDColor = */fingerprint.eLEDBlue, /*blinkCount = */0);
delay(1000);
}else{
Serial.println("Saving failed");
/*Get error code information*/
//desc = fingerprint.getErrorDescription();
//Serial.println(desc);
}
}
- Expected Result 3
Sample Code 4 - Fingerprint Matching
Collect the fingerprint image and compare it with the fingerprints in the fingerprint library. If they matches, the green light will be on and the ID number will be printed, otherwise, the red light will be on and the matching failure will be prompted.
/*!
* @file fingerprintMatching.ino
* @brief Collect fingerprint and compare it with fingerprints in fingerprint library
* @n Experiment Phenomenon:capture fingerprint image and compare it with all fingerprints in the fingerprint library,
If matched successfully, light up green LED and print ID number. Return 0 when failed.
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (https://www.dfrobot.com)
* @licence The MIT License (MIT)
* @author [Eddard](Eddard.liu@dfrobot.com)
* @version V1.0
* @date 2020-03-19
* @get from https://www.dfrobot.com
* @url https://github.com/DFRobot/DFRobot_ID809
*/
#include <DFRobot_ID809.h>
/*Use software serial when using UNO or NANO*/
#if ((defined ARDUINO_AVR_UNO) || (defined ARDUINO_AVR_NANO))
#include <SoftwareSerial.h>
SoftwareSerial Serial1(2, 3); //RX, TX
#define FPSerial Serial1
#else
#define FPSerial Serial1
#endif
DFRobot_ID809 fingerprint;
//String desc; //Error code information, enabling this function will consume much memory
void setup(){
/*Initialize serial port for printing*/
Serial.begin(9600);
/*Initialize FPSerial*/
FPSerial.begin(115200);
/*Use FPSerial as communication serial port of module*/
fingerprint.begin(FPSerial);
/*Wait for Serial to open*/
while(!Serial);
/*Test whether device can communicate properly with mainboard,
Return true or false
*/
while(fingerprint.isConnected() == false){
Serial.println("Communication with device failed, please check connection");
/*Get error code information*/
//desc = fingerprint.getErrorDescription();
//Serial.println(desc);
delay(1000);
}
}
void loop(){
uint8_t ret = 0;
/*Set fingerprint LED ring mode, color, and number of blinks,
Can be set as follows:
Parameter 1:<LEDMode>
eBreathing eFastBlink eKeepsOn eNormalClose
eFadeIn eFadeOut eSlowBlink
Parameter 2:<LEDColor>
eLEDGreen eLEDRed eLEDYellow eLEDBlue
eLEDCyan eLEDMagenta eLEDWhite
Parameter 3:<number of blinks> 0 represents blinking all the time,
This parameter will only be valid in mode eBreathing, eFastBlink, eSlowBlink
*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eBreathing, /*LEDColor = */fingerprint.eLEDBlue, /*blinkCount = */0);
Serial.println("Please press down your finger");
/*Capture fingerprint image, Disable the collection timeout function
If succeed return 0, otherwise return ERR_ID809
*/
if((fingerprint.collectionFingerprint(/*timeout=*/0)) != ERR_ID809){
/*Set fingerprint LED ring to quick blink in yellow 3 times*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eFastBlink, /*LEDColor = */fingerprint.eLEDYellow, /*blinkCount = */3);
Serial.println("Capturing succeeds");
Serial.println("Please release your finger");
/*Wait for finger to release
Return 1 when finger is detected, otherwise return 0
*/
while(fingerprint.detectFinger());
/*Compare the captured fingerprint with all the fingerprints in the fingerprint library,
Return fingerprint ID(1-80) if succeed, return 0 when failed
*/
ret = fingerprint.search();
/*Compare the captured fingerprint with a fingerprint of specific ID
Return fingerprint ID(1-80) if succeed, return 0 when failed
*/
//ret = fingerprint.verify(/*Fingerprint ID = */1);
if(ret != 0){
/*Set fingerprint LED ring to always ON in green*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eKeepsOn, /*LEDColor = */fingerprint.eLEDGreen, /*blinkCount = */0);
Serial.print("Matching succeeds, ID=");
Serial.println(ret);
}else{
/*Set fingerprint LED ring to always ON in red*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eKeepsOn, /*LEDColor = */fingerprint.eLEDRed, /*blinkCount = */0);
Serial.println("Matching fails");
}
}else{
Serial.println("Capturing fails");
/*Get error code information*/
//desc = fingerprint.getErrorDescription();
//Serial.println(desc);
}
Serial.println("-----------------------------");
delay(1000);
}
- Expected Result 4
Sample Code 5 - Delete Fingerprint
Run the codes, and press your finger on the sensor to delete your fingerprint.
/*!
* @file fingerprintDeletion.ino
* @brief Delete a specific fingerprint
* @n Experiment phenomenon:press your finger on the sensor, if this fingerprint is registered, delete it and LED lights up green.
If it is unregistered or fingerprint collection fails, LED lights up red.
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (https://www.dfrobot.com)
* @licence The MIT License (MIT)
* @author [Eddard](Eddard.liu@dfrobot.com)
* @version V1.0
* @date 2020-03-19
* @get from https://www.dfrobot.com
* @url https://github.com/DFRobot/DFRobot_ID809
*/
#include <DFRobot_ID809.h>
/*Use software serial when using UNO or NANO*/
#if ((defined ARDUINO_AVR_UNO) || (defined ARDUINO_AVR_NANO))
#include <SoftwareSerial.h>
SoftwareSerial Serial1(2, 3); //RX, TX
#define FPSerial Serial1
#else
#define FPSerial Serial1
#endif
DFRobot_ID809 fingerprint;
//String desc; //Error code information, enabling this function will consume much memory
void setup(){
/*Initialize serial port for printing*/
Serial.begin(9600);
/*Initialize FPSerial*/
FPSerial.begin(115200);
/*Use FPSerial as communication serial port of module*/
fingerprint.begin(FPSerial);
/*Wait for Serial to open*/
while(!Serial);
/*Test whether device can communicate properly with mainboard,
Return true or false
*/
while(fingerprint.isConnected() == false){
Serial.println("Communication with device failed, please check connection");
/*Get error code information*/
//desc = fingerprint.getErrorDescription();
//Serial.println(desc);
delay(1000);
}
}
void loop(){
uint8_t ret = 0;
/*Set fingerprint LED ring mode, color, and number of blinks,
Can be set as follows:
Parameter 1:<LEDMode>
eBreathing eFastBlink eKeepsOn eNormalClose
eFadeIn eFadeOut eSlowBlink
Parameter 2:<LEDColor>
eLEDGreen eLEDRed eLEDYellow eLEDBlue
eLEDCyan eLEDMagenta eLEDWhite
Parameter 3:<Number of blinks> 0 represents blinking all the time,
This parameter will only be valid in mode eBreathing, eFastBlink, eSlowBlink
*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eBreathing, /*LEDColor = */fingerprint.eLEDBlue, /*blinkCount = */0);
Serial.println("Please press the finger on the sensor to delete the fingerprint");
/*Capture fingerprint image, 10s idle timeout, if timeout=0, disable the collection timeout function
If succeed return 0, otherwise return ERR_ID809
*/
if((fingerprint.collectionFingerprint(/*timeout=*/10)) != ERR_ID809){
/*Compare the captured fingerprint with all the fingerprints in the fingerprint library,
Return fingerprint ID(1-80) if succeed, return 0 when failed
*/
ret = fingerprint.search();
/*Compare the captured fingerprint with a fingerprint of specific ID
Return fingerprint ID(1-80) if succeed, return 0 when failed
*/
if(ret != 0){
/*Delete the fingerprint of this ID*/
fingerprint.delFingerprint(/*Fingerprint ID = */ret);
//fingerprint.delFingerprint(DELALL); //Delete all fingerprints
Serial.print("delete successful,ID=");
Serial.println(ret);
/*Set fingerprint LED ring to always ON in green*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eKeepsOn, /*LEDColor = */fingerprint.eLEDGreen, /*blinkCount = */0);
}else{
Serial.println("Fingerprint is unregistered");
/*Set fingerprint LED ring to always ON in red*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eKeepsOn, /*LEDColor = */fingerprint.eLEDRed, /*blinkCount = */0);
}
}else{
Serial.println("Capturing fails");
/*Get error code information*/
//desc = fingerprint.getErrorDescription();
//Serial.println(desc);
/*Set fingerprint LED ring to always ON in red*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eKeepsOn, /*LEDColor = */fingerprint.eLEDRed, /*blinkCount = */0);
}
Serial.println("Please release your finger");
/*Wait for finger to release
Return 1 when finger is detected, otherwise return 0
*/
while(fingerprint.detectFinger());
/*Check whether the fingerprint ID has been registered
Return 1 if registered, otherwise return 0
*/
// if(fingerprint.getStatusID(/*Fingerprint ID = */FINGERPRINTID)){
// Serial.println("ID has been registered");
// }else{
// Serial.println("ID is unregistered");
// }
Serial.println("-----------------------------");
delay(1000);
}
- Expected Result 5
Sample Code 6 - Comprehensive Examples
This example is a comprehensive application of the fingerprint module, in which the module will enter into different modes according to the length of finger pressing time. When a finger pressed down, the blue light flashes 3 times to enter the fingerprint comparison mode; the yellow light flashes 3 times to enter the fingerprint registration mode; the red light flashes 3 times to enter the fingerprint deletion mode to delete the fingerprint. This experiment needs to connect IRQ pin to D6 pin.
/*!
* @file comprehensiveExample.ino
* @brief Comprehensive Example
* @n This module can be controlled by hardware serial or software serial. Pin IRQ should be connected to D6 in this experiment.
* @n Experiment Phenomenon:when finger pressed down, the blue LED blinks quickly 3 times to enter fingerprint comparison mode.
* @n The yellow LED blinks quickly 3 times to enter fingerprint registration mode
* @n The red LED blinks quickly 3 times to enter fingerprint deletion mode, and delete this fringerprint
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (https://www.dfrobot.com)
* @licence The MIT License (MIT)
* @author [Eddard](Eddard.liu@dfrobot.com)
* @version V1.0
* @date 2020-03-19
* @get from https://www.dfrobot.com
* @url https://github.com/DFRobot/DFRobot_ID809
*/
#include <DFRobot_ID809.h>
#define COLLECT_NUMBER 3 //Fingerprint sampling times, can be set to 1-3
#define IRQ 6 //Interrupt pin
/*Use software serial when using UNO or NANO*/
#if ((defined ARDUINO_AVR_UNO) || (defined ARDUINO_AVR_NANO))
#include <SoftwareSerial.h>
SoftwareSerial Serial1(2, 3); //RX, TX
#define FPSerial Serial1
#else
#define FPSerial Serial1
#endif
DFRobot_ID809 fingerprint;
//String desc; //Error code information, enabling this function will consume much memory
void setup(){
/*Initialize serial port for printing*/
Serial.begin(9600);
/*Initialize FPSerial*/
FPSerial.begin(115200);
/*Use FPSerial as communication serial port of module*/
fingerprint.begin(FPSerial);
/*Wait for Serial to open*/
while(!Serial);
/*Test whether device can communicate properly with mainboard,
Return true or false
*/
while(fingerprint.isConnected() == false){
Serial.println("Communication with device failed, please check connection");
/*Get error code information*/
//desc = fingerprint.getErrorDescription();
//Serial.println(desc);
delay(1000);
}
}
//Blue LED comparison mode Yellow LED Registration mode Red Deletion mode
void loop(){
if(digitalRead(IRQ)){
uint16_t i = 0;
/*Capture fingerprint image, 5s idle timeout, if timeout=0, disable the collection timeout function
Return 0 if succeed, otherwise return ERR_ID809
*/
if((fingerprint.collectionFingerprint(/*timeout=*/5)) != ERR_ID809){
/*Get the time when finger pressed down*/
/*Set fingerprint LED ring mode, color, and number of blinks,
Can be set as follows:
Parameter 1:<LEDMode>
eBreathing eFastBlink eKeepsOn eNormalClose
eFadeIn eFadeOut eSlowBlink
Parameter 2:<LEDColor>
eLEDGreen eLEDRed eLEDYellow eLEDBlue
eLEDCyan eLEDMagenta eLEDWhite
Parameter 3:<number of blinks> 0 represents blinking all the time,
This parameter will only be valid in mode eBreathing, eFastBlink, eSlowBlink
*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eFastBlink, /*LEDColor = */fingerprint.eLEDBlue, /*blinkCount = */3); //Blue LED blinks quickly 3 times, means it's in fingerprint comparison mode now
/*Wait for finger to relase*/
while(fingerprint.detectFinger()){
delay(50);
i++;
if(i == 15){ //Yellow LED blinks quickly 3 times, means it's in fingerprint regisrtation mode now
/*Set fingerprint LED ring to always ON in yellow*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eFastBlink, /*LEDColor = */fingerprint.eLEDYellow, /*blinkCount = */3);
}else if(i == 30){ //Red LED blinks quickly 3 times, means it's in fingerprint deletion mode now
/*Set fingerprint LED ring to always ON in red*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eFastBlink, /*LEDColor = */fingerprint.eLEDRed, /*blinkCount = */3);
}
}
}
if(i == 0){
/*Fingerprint capturing failed*/
}else if(i > 0 && i < 15){
Serial.println("Enter fingerprint comparison mode");
/*Compare fingerprints*/
fingerprintMatching();
}else if(i >= 15 && i < 30){
Serial.println("Enter fingerprint registration mode");
/*Register fingerprint*/
fingerprintRegistration();
}else{
Serial.println("Enter fingerprint deletion mode");
/*Delete this fingerprint*/
fingerprintDeletion();
}
}
}
//Compare fingerprints
void fingerprintMatching(){
/*Compare the captured fingerprint with all fingerprints in the fingerprint library,
Return fingerprint ID number(1-80) if succeed, return 0 when failed
*/
uint8_t ret = fingerprint.search();
if(ret != 0){
/*Set fingerprint LED ring to always ON in green*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eKeepsOn, /*LEDColor = */fingerprint.eLEDGreen, /*blinkCount = */0);
Serial.print("Successfully matched, ID=");
Serial.println(ret);
}else{
/*Set fingerprint LED Ring to always ON in red*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eKeepsOn, /*LEDColor = */fingerprint.eLEDRed, /*blinkCount = */0);
Serial.println("Matching failed");
}
delay(1000);
/*Turn off fingerprint LED Ring*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eNormalClose, /*LEDColor = */fingerprint.eLEDBlue, /*blinkCount = */0);
}
//Fingerprint Registration
void fingerprintRegistration(){
uint8_t ID,i;
/*Compare the captured fingerprint with all fingerprints in the fingerprint library,
Return fingerprint ID number(1-80) if succeed, return 0 when failed
Function: clear the last captured fingerprint image.
*/
fingerprint.search(); //Can add "if else" statement to judge whether the fingerprint has been registered.
/*Get a unregistered ID for saving fingerprint
Return ID number when succeed,
Return ERR_ID809 if failed
*/
if((ID = fingerprint.getEmptyID()) == ERR_ID809){
while(1){
/*Get error code imformation*/
//desc = fingerprint.getErrorDescription();
//Serial.println(desc);
delay(1000);
}
}
Serial.print("Unregistered ID, ID=");
Serial.println(ID);
i = 0; //Clear sampling times
/*Fingerprint Sampling 3 times*/
while(i < COLLECT_NUMBER){
/*Set fingerprint LED ring to breathing lighting in blue*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eBreathing, /*LEDColor = */fingerprint.eLEDBlue, /*blinkCount = */0);
Serial.print("The fingerprint sampling of the");
Serial.print(i+1);
Serial.println("(th) time is being taken");
Serial.println("Please press down your finger");
/*Capture fingerprint image, 10s idle timeout
If succeed return 0, otherwise return ERR_ID809
*/
if((fingerprint.collectionFingerprint(/*timeout = */10)) != ERR_ID809){
/*Set fingerprint LED ring to quick blink in yellow 3 times*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eFastBlink, /*LEDColor = */fingerprint.eLEDYellow, /*blinkCount = */3);
Serial.println("Capturing succeeds");
i++; //Sampling times +1
}else{
Serial.println("Capturing fails");
/*Get error code information*/
//desc = fingerprint.getErrorDescription();
//Serial.println(desc);
}
Serial.println("Please release your finger");
/*Wait for finger to release
Return 1 when finger is detected, otherwise return 0
*/
while(fingerprint.detectFinger());
}
/*Save fingerprint information into an unregistered ID*/
if(fingerprint.storeFingerprint(/*Empty ID = */ID) != ERR_ID809){
Serial.print("Saving succeed, ID=");
Serial.println(ID);
Serial.println("-----------------------------");
/*Set fingerprint LED ring to always ON in green*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eKeepsOn, /*LEDColor = */fingerprint.eLEDGreen, /*blinkCount = */0);
delay(1000);
/*Turn off fingerprint LED ring*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eNormalClose, /*LEDColor = */fingerprint.eLEDBlue, /*blinkCount = */0);
}else{
Serial.println("Saving failed");
/*Get error code information*/
//desc = fingerprint.getErrorDescription();
//Serial.println(desc);
}
}
//Fingerprint deletion
void fingerprintDeletion(){
uint8_t ret;
/*Compare the captured fingerprint with all the fingerprints in the fingerprint library,
Return fingerprint ID(1-80) if succeed, return 0 when failed
*/
ret = fingerprint.search();
if(ret){
/*Set fingerprint LED ring to always ON in green*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eKeepsOn, /*LEDColor = */fingerprint.eLEDGreen, /*blinkCount = */0);
fingerprint.delFingerprint(ret);
Serial.print("deleted fingerprint,ID=");
Serial.println(ret);
}else{
/*Set fingerprint LED ring to always ON in red*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eKeepsOn, /*LEDColor = */fingerprint.eLEDRed, /*blinkCount = */0);
Serial.println("Matching failed or the fingerprint hasn't been registered");
}
delay(1000);
/*Turn off fingerprint LED ring*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eNormalClose, /*LEDColor = */fingerprint.eLEDBlue, /*blinkCount = */0);
}
- Expected Result 6
Sample Code 7 - Comparison of fingerprint and template data
Once you press finger down, your fingerprint can be compared with the template data. The template data does not occupy the fingerprint storage capacity, and those for comparison are stored in an array. In this case, the template data can come from external sources (such as SD card and cloud). Please make sure that there are fingerprints stored in ID 1 before using this example.
/*!
*@file contrastTemplate.ino
*@brief Extract the ID 1 fingerprint template, and collect fingerprint to compare with it.
*@copyright Copyright (c) 2010 DFRobot Co.Ltd (https://www.dfrobot.com)
*@licence The MIT License (MIT)
*@author [fengli](li.feng@dfrobot.com)
*@version V1.0
*@date 2021-6-01
*@get from https://www.dfrobot.com
*@https://github.com/DFRobot/DFRobot_ID809
*/
#include <DFRobot_ID809.h>
uint8_t temp[1008]={0}; //Template data
/*Use software serial when using UNO or NANO*/
#if ((defined ARDUINO_AVR_UNO) || (defined ARDUINO_AVR_NANO))
#include <SoftwareSerial.h>
SoftwareSerial Serial1(2, 3); //RX, TX
#define FPSerial Serial1
#else
#define FPSerial Serial1
#endif
DFRobot_ID809 fingerprint;
//String desc;
void setup(){
/*Initialize serial port for printing*/
Serial.begin(9600);
/*Initialize FPSerial*/
FPSerial.begin(115200);
/*Use FPSerial as communication serial port of module*/
fingerprint.begin(FPSerial);
/*Wait for Serial to open*/
while(!Serial);
/*Test whether device can communicate properly with mainboard,
Return true or false
*/
while(fingerprint.isConnected() == false){
Serial.println("Communication with device failed, please check connection");
/*Get error code information*/
//desc = fingerprint.getErrorDescription();
//Serial.println(desc);
delay(1000);
}
//Get the fingerprint template of ID 1
fingerprint.getTemplate(/*id = */1,temp);
//Download the template to ID 1
//fingerprint.downLoadTemplate(/*id = */1,temp);
}
void loop(){
/*Set the fingerprint LED ring as blue breathing light*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eBreathing, /*LEDColor = */fingerprint.eLEDBlue, /*blinkCount = */0);
Serial.println("Please press down your finger");
/*Capture fingerprint image, Disable the collection timeout function
If succeed return 0, otherwise return ERR_ID809
Collect fingerprint template data and store them to rambuffer0
*/
if((fingerprint.collectionFingerprint(/*timeout=*/0,0)) != ERR_ID809){
/*Set fingerprint LED ring to quick blink in yellow 3 times*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eFastBlink, /*LEDColor = */fingerprint.eLEDYellow, /*blinkCount = */3);
Serial.println("Capturing succeeds");
Serial.println("Please release your finger");
/*Wait for finger to release
Return 1 when finger is detected, otherwise return 0
*/
while(fingerprint.detectFinger());
//Compare the template data with the collected fingerprints
if(!fingerprint.contrastTemplate(/*TEMP = */temp)){
/*Set fingerprint LED ring to always ON in green*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eKeepsOn, /*LEDColor = */fingerprint.eLEDGreen, /*blinkCount = */0);
Serial.println("Matching succeeds, the template matches the finger");
}else{
/*Set fingerprint LED ring to always ON in red*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eKeepsOn, /*LEDColor = */fingerprint.eLEDRed, /*blinkCount = */0);
Serial.println("Matching fails, the template does not match the finger");
}
}else{
Serial.println("Capturing fails");
}
Serial.println("-----------------------------");
delay(1000);
}
- Expected Result 7
Sample Code 8 - Display Fingerprint Images
This example will demonstrate how to collect and display fingerprint images, and store them in SD card.
Other devices used in this example
DFR0652 Firebeetle 2 M0 Development Board
DFR0664 Fermion: 2.0" 320x240 IPS TFT LCD Display with MicroSD Card (Breakout)
Note: Since the image data is relatively large, please use a high-performance main controller. If you use other main controller, please select the corresponding serial port and modify the codes of SD card according to the controller.
/*!
*@file getQuarterFingerImage.ino
*@brief Store the collected fingerprint image in the SD card and display it on the screen, can select to obtain quarter image or full image
*This example needs to be used with screen, SD card,and high-performance main controllers.
*@copyright Copyright (c) 2010 DFRobot Co.Ltd (https://www.dfrobot.com)
*@licence The MIT License (MIT)
*@author [fengli](li.feng@dfrobot.com)
*@version V1.0
*@date 2021-6-01
*@get from https://www.dfrobot.com
*@https://github.com/DFRobot/DFRobot_ID809
*/
#include <DFRobot_ID809.h>
#include "bmpHeader.h"
#include <SD.h>
#include "DFRobot_GDL.h"
//Custom communication pins
/*M0*/
#if defined ARDUINO_SAM_ZERO
#define TFT_DC 7
#define TFT_CS 5
#define TFT_RST 6
/*ESP32*/
#elif defined ESP32
#define TFT_DC D7
#define TFT_CS D8
#define TFT_RST D9
/* AVR series mainboard */
#else
#define TFT_DC 2
#define TFT_CS 3
#define TFT_RST 4
#endif
/*Choose the serial port according to the main controller you use*/
#define FPSerial Serial1
DFRobot_ILI9341_240x320_HW_SPI screen(/*dc=*/TFT_DC,/*cs=*/TFT_CS,/*rst=*/TFT_RST);
DFRobot_ID809 fingerprint;
//String desc;
File myFile;
#define QUARTER
#ifdef QUARTER
uint8_t data[6400]; //Quarter image
#else
uint8_t data[25600]; //Full image
#endif
void setup(){
/*Init print serial port */
Serial.begin(9600);
/*Init FPSerial*/
FPSerial.begin(115200);
/*Take FPSerial as communication port of fingerprint module */
fingerprint.begin(FPSerial);
screen.begin();
screen.fillScreen(0xFFFF);
/*Wait for Serial to open*/
/*Test whether device can communicate properly with mainboard
Return true or false
*/
while(fingerprint.isConnected() == false){
Serial.println("Communication with device failed, please check connection");
/*Get error code information */
//desc = fingerprint.getErrorDescription();
//Serial.println(desc);
delay(1000);
}
/*Initialize the SD card module according to SD library corresponding to the main controller*/
while(!SD.begin(/*csPin = */3, /*type = */TYPE_NONBOARD_SD_MOUDLE)) {
SerialUSB.println("initialization failed!");
delay(1000);
}
}
void loop(){
/*Set the fingerprint module LED ring to blue breathing lighting effect*/
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eBreathing, /*LEDColor = */fingerprint.eLEDBlue, /*blinkCount = */0);
Serial.println("Please release your finger");
/*Wait for finger to release
Return 1 when finger is detected, otherwise return 0
*/
while(!fingerprint.detectFinger());
#ifdef QUARTER //Collect quarter images
fingerprint.getQuarterFingerImage(data);
#else //Collect full images
fingerprint.getFingerImage(data);
#endif
myFile = SD.open("finger.bmp", FILE_WRITE);
#ifdef QUARTER
myFile.write((const char *)bmpHeader, sizeof(bmpHeader));
for(uint8_t i = 0;i < 13 ;i++){
if(i == 12){
myFile.write((const char *)data+i*512, 256);
break;
}
myFile.write((const char *)data+i*512, 512);
}
myFile.close();
//Display the image on the screen
for(uint16_t i = 0; i < 6400 ;i++){
uint8_t a = i % 80;
uint8_t b = i / 80;
screen.drawPixel(80+a,120+b,(data[i]/4)<<5);
}
#else
//Save the picture in bmp format to SD card
bmpHeader[18] = 0xa0;
bmpHeader[22] = 0xa0;
myFile.write((const char *)bmpHeader, sizeof(bmpHeader));
for(uint8_t i = 0;i < 50 ;i++){
myFile.write((const char *)data+i*512, 512);
}
myFile.close();
//Display the image on the screen
for(uint16_t i = 0; i < 25600 ;i++){
uint8_t a = i % 160;
uint8_t b = i / 160;
screen.drawPixel(40+a,80+b,(data[i]/4)<<5);
}
#endif
while(1);
}
Sample Code 9 - Demo for Low-power Mode
Control Pin VIN via relay to let the fingerprint module enter low-power mode.
How to enter sleep mode: first send entersleepstation (), then disconnect the VIN power supply (at this time, the module current is below 10uA)
How to wake up: when the maincontroller monitors that there is a pulse signal output from the Pin IRQ(the IRQ pin will generate a pulse signal when the finger is pressed on the fingerprint module), supply power to the VIN, and determine if the module communicates properly by fingerprint.isConnected(), if so, then it could work well.
/*!
* @file Demo for low power mode.ino
* @brief Control Pin VIN via relay to let the Fingerprint module enter low power mode
* @n Experiment Phenomenon:If there is no finger pressing for 10s, the mdoule enters sleep mode. Press your finger on the sensor to exit the sleep mode and the light ring lights up.
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (https://www.dfrobot.com)
* @licence The MIT License (MIT)
* @author [Eddard](Eddard.liu@dfrobot.com)
* @version V1.0
* @date 2021-08-20
* @get from https://www.dfrobot.com
* @url https://github.com/DFRobot/DFRobot_ID809
*/
#include <DFRobot_ID809.h>
#define IRQ 6
#define RELAY 7
/*Use software serial when using UNO or NANO*/
#if ((defined ARDUINO_AVR_UNO) || (defined ARDUINO_AVR_NANO))
#include <SoftwareSerial.h>
SoftwareSerial Serial1(2, 3); //RX, TX
#define FPSerial Serial1
#else
#define FPSerial Serial1
#endif
DFRobot_ID809 fingerprint;
long long curr = 0;
uint8_t sleepFlag = 1;
void setup(){
/*Init print serial port */
Serial.begin(9600);
/*Init FPSerial*/
FPSerial.begin(115200);
/*Take FPSerial as communication port of fingerprint module */
fingerprint.begin(FPSerial);
/*Wait for Serial to open*/
pinMode(RELAY, OUTPUT);
digitalWrite(RELAY, HIGH);
delay(100); //Delay 100ms to wait for the start of the module
while(!Serial);
/*Test whether device can communicate properly with mainboard
Return true or false
*/
while(fingerprint.isConnected() == false){
Serial.println("Communication with device failed, please check connection");
delay(1000);
}
Serial.println("Module init succeeds, enter sleep mode when no finger pressed for 10s");
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eBreathing, /*LEDColor = */fingerprint.eLEDBlue, /*blinkCount = */0);
}
void loop(){
if(digitalRead(IRQ) && (sleepFlag == 0)){
digitalWrite(RELAY, HIGH);
Serial.println("Exit sleep mode");
delay(100); //Delay 100ms to wait for the start of the module
curr = millis();
sleepFlag = 1;
if(fingerprint.isConnected() == true){
Serial.println("Module communication back to normal");
fingerprint.ctrlLED(/*LEDMode = */fingerprint.eBreathing, /*LEDColor = */fingerprint.eLEDBlue, /*blinkCount = */0);
} else{
Serial.println("Module communication recovery failed");
}
}
if((sleepFlag == 1)&&(millis() - curr > 10000)){
fingerprint.enterStandbyState(); //Let your module enter standby module first, then disconnect VIN power
digitalWrite(RELAY, LOW);
sleepFlag = 0;
Serial.println("Enter sleep mode");
}
}
- Expected Result 9
If there is no finger pressing for 10s, the mdoule enters sleep mode. Press your finger on the sensor to exit the sleep mode and the light ring lights up.
Upper Host Control
For controlling the module via upper host program, we need to connect this module to a computer with a USB to serial module.
Click to download Fingerprint Module Upper Host
Connection Diagram
Program Usage
FAQ
For any questions, advice or cool ideas to share, please visit the DFRobot Forum.