Biometric devices are the backbone of modern security and access systems. The most commonly used biometric device is a fingerprint scanner. Fingerprints are unique identifiers that cannot be easily faked. Optical fingerprint sensors are widely used in security systems as these are low-cost compared to capacitive and ultrasonic scanners. Optical fingerprint sensors digitize fingerprints by capturing a digital image and saving it to a fingerprint template. The fingerprint templates are stored in flash memory and are compared with new scans to detect a valid access attempt.
Most optical fingerprint scanners have a TTL UART port and USB port to communicate with a computer system. The computer system, a microcontroller, single-board computer, a desktop system, or a server can control the fingerprint scanner to enroll a fingerprint ID, compare and match a scan with enrolled fingerprint templates, or even download a stored or scanned fingerprint template.
Adafruit AS608 fingerprint scanner is one of the popular optical fingerprint scanners, and it is often used with Arduino and other embedded development boards. The R30X series of fingerprint sensors from a Chinese vendor called Hangzhou Grow Technology Co., Ltd. is an alternative to the Adafruit sensor. Popular fingerprint scanners in this series include R300, RR301T, R302, R303, R303T, R305, R307, R308, and R311. Some of these R30X sensors are capacitive. Despite different fingerprint scanning technologies, all R30X sensors have the same interface and command set. R305 and R307 are the most popular optical fingerprint sensors of this series. Interestingly, the Adafruit fingerprint sensor library works fine with both Adafruit fingerprint sensor and R30X sensors. In this tutorial, we will demonstrate enrolling a fingerprint ID and match fingerprints using the R307 module.
How optical fingerprint scanners work
The skin of our palm has friction ridges to grab and hold things, and the pattern of these ridges and valleys is also present on the fingertips. A miracle of nature is that this pattern of ridges and valleys is unique for every individual. An impression of our fingerprints is left whenever we grab or hold something due to oil, moisture, dust, and dead cells over the skin. These fingerprints objects are called latent fingerprints.
The optical fingerprint readers use the principle of Total Internal Reflection (TRI). An optical fingerprint scanner consists of a prism. On one face of the prism, there is a LED light source. The light enters the prism at a certain angle such that it is reflected from the adjacent face and exits from the third face, where a lens and an image capturing sensor are placed.
When no finger or impression is placed over the sensor, the light transmitted by the LED source is completely reflected off, and the image sensor captures a plain image. However, when there is a fingertip placed over the scanner, some of the light is reflected while some of the light is leaked along the surface of the face of the prism. These are called Evanescent Waves.
Different materials have different reflective indices and interact differently with the evanescent waves. When the fingertip is placed over the scanner, the ridges are in tight contact with the scanner’s surface while the valleys are filled with air pockets. The skin and air have different reflective indices causing different evanescent waves, called Frustrated Total Internal Reflection (FTIR). As a result of different evanescent waves from ridges and valleys, the intensity of the total internally reflected light changes according to the pattern of the ridges and valleys. The image sensor captures a high contrast image recording the changed light intensity pattern, capturing the pattern of ridges and valleys as a high-contrast digital image.
The high-contrast digital image is stored in Flash memory as fingerprint ID according to a predefined template. The template indicates the presence of ridges or valleys at predefined positions in a captured or scanned image. Any fingerprint sensor is designed to perform two processes – enrollment and matching essentially. The process of reading fingerprint impression and storing it according to a predefined template is called enrollment. A fingerprint reader can enroll several fingerprint IDs depending upon its flash memory and the built-in controller. The enrollment process usually involves confirmation of the fingerprint impression, so it requires scanning the fingerprint twice. Fingerprint IDs store the images in the module.
In fingerprint matching, a new scan is compared with stored fingerprint templates, and if it has the same template as any of the stored impressions, it is confirmed matched. Otherwise, the scan is rejected as unmatched. If the live finger is compared against a specific fingerprint ID, it is called 1:1 matching. If the live finger is compared to match against all fingerprint templates stored in the module, it is called 1:N matching.
 R307 fingerprint sensor
R307 is one of the optical fingerprint readers from Hangzhou Grow Technology Co., Ltd. The scanner operates at a voltage of 4.2V~6V and 50 mA with a storage capacity of 1000 impressions. R307 has both UART and USB 2.0 interfaces to communicate with a computer system at a baud rate in multiples of 9600 bps. It is capable of both 1:1 and 1:N matching with FAR (False Acceptance Rate) less than 0.001 percent. The module can scan a live finger in less than 0.5 seconds and supports five security levels (1~5; 5 is highest). The operating temperature range of this sensor is -10ËšC to 40ËšC, making it deployable in most of the locations.
R307 sensor assembly
R307 has a glass top where a fingertip can be placed for scanning. Below the glass top is placed a prism. The inside of the sensor is divided into two parts using a light barrier. On one side of the light barrier is a PCB consisting of four blue LED lights. At the other side of the light barrier is an image sensor connected with a processor. The outer PCB has the processor, connector, and other circuit elements. The prism, along with blue LEDs and an image sensor, is arranged such that light transmitted by blue LEDs is internally reflected through the prism to the image sensor.
R307 sensor pinout
The connector of the R307 fingerprint sensor has six terminals. The pin configuration of this connector is as follows.
The pins are arranged in the connector, as shown in the image below.
The sensor can be operated at both 5V as well as 3.3V DC. If the sensor is to be interfaced with a 3V3 controller, the 3.3V jumper must be short. If it is to be interfaced with a 5V controller, the jumper must be left open.Â
The scanner can communicate with a computer/controller using both TTL UART and a USB interface. When connected via a USB port, a virtual COM port is created. It should be noted that pin 6 is the supply voltage for finger detection. If pin 6 is connected to a 3.3V supply, the output of pin 5 goes HIGH when a live finger is placed over the sensor. It is helpful for manual scanning of the finger; otherwise, the sensor starts looking for a scan after few seconds from power-up. It is important to select proper supply voltage on the fingerprint scanner. A higher voltage can damage a 3V3 controller or its GPIO pins.
R307 sensor circuit
The controller chip on the R307 fingerprint scanner is AS606 from Synochip. AS606 is a microcontroller capable of digital signal processing. For touch detection, the sensor has TTP233D IC from Tontek. The outer PCB has the following circuit diagram.
R307 registers
The R307 scanner has built-in flash memory, and it has many registers and buffer memory to store configuration and fingerprint data. Some of the important R307 registers are explained below.
Notepad: This is a 512 bytes non-volatile flash memory arranged in 16 pages of 32 bytes each. The entire memory is written or updated at once.
Image Buffer: It is a RAM used to store a digital image of the fingerprint impression temporarily. It stores a BMP image of dimensions 256 X 288, where each pixel is stored as a byte.
Character File Buffer: It is used to store a processed high-contrast image of the fingerprint. There are two character file buffers of 512 bytes each, and these store two-character files from two consecutive scans. The two scans are combined to form a template file representing the final version of a fingerprint impression. The template files are stored in the fingerprint library.
Fingerprint Library: It is built-in flash memory where 1000 fingerprint templates can be stored. The template files are stored sequentially in the library.
System Configuration Registers: It is a 16-byte register bank that stores configuration data and status flags. The register bank starts a 2-byte status register, followed by a 2-byte system identifier code, 2-byte library size, 2-byte security level, 4-byte device address, 2-byte data packet size, and 2-byte baud multiplier. The status register is defined as follows.
Where, Busy = 1 if system is executing command else Busy = 0 if system is free. Pass = 1 if a matching fingerprint is found else Pass = 0 if fingerprint is not found. PWD = 1 if handshaking password is verified else PWD = 0 if password is not matched. ImgBufStat = 1 if image buffer contains a valid image else ImgBufStat = 0 if image is not processed.
System Identifier Code has a fixed value that identifies the module in the R30X series. R307 has a code of 0x0009. Library size indicates the number of fingerprint templates the module can store. For R307, it is 1000. Security value determines the threshold of fingerprint matching. It can be 1 to 5, where 5 is the highest security level providing minimum FAR and maximum FRR. FAR is the likelihood of identifying a weakly matched fingerprint as positive. FRR (False Recognition Rate) is the likelihood of identifying a wrong fingerprint as negative. At level 5, FAR is highest, and FRR is lowest. This is the strictest level of fingerprint matching. The device address is by default 0xFFFFFFFF. It can be modified with the SetAddr command. Data Packet Size determines the maximum size of data sent in a single packet. Its value can be 0~3, where 0 = 32 bytes, 1 = 64 bytes, 2 = 128 bytes and 3 = 256 bytes. Baud Multiplier sets the data communication speed with a computer system. It can be 1~12 in multiples of 9600 bps with a minimum baud rate of 9600 bps and a maximum of 115200 bps.
R307 communication protocol
The scanner can communicate data with a computer system using a UART or USB interface. Both interfaces use a common communication protocol. The data is communicated in the form of packets. Each packet is broken into 10-bit frames. A frame starts with a start bit 0 followed by a byte and ending with an end bit 1. A packet is divided into the following frames.
The Header is 2-byte long, having a fixed value of 0xEF01. The high byte is always sent first. The Address is the 32-bit device address of the scanner. The module accepts a command or data only if the address is correct. The default device address is 0xFFFFFFFF. The Packet Identifier determines the type of packet. It is 0x01 for command, 0x02 for data, 0x07 for acknowledgement packet, 0x08 for indicating end of data transfer packet. A command packet must follow a data packet. The acknowledgment packet is sent from the module to the computer system. Packet Length indicates the size of the packet content, including a checksum byte. Packet Content can be a command, data, or parameter of varying length as indicated by Packet Length. Checksum is the arithmetic sum of all bytes in Packet Identifier, Packet Length, and Packet Content.
The R307 supports the following instruction set.
In response to a command from the computer system, the scanner sends back an acknowledgment packet containing the result and status of command execution. Each command has a set of expected response codes called confirmation codes. Following is a list of confirmation codes for R30X modules.
Making a simple fingerprint scanner
A fingerprint scanner has two processes involved – fingerprint enrolment and fingerprint matching. Let us now scan and match fingerprints using the R307 module. With this simple knowledge of enrolling and matching fingerprints, we can build any biometric security or access system.
Components required
- Adafruit Fingerprint Scanner or R307 Fingerprint Scanner x1
- Arduino UNO x1
- Male Header x1
Tools required
- Soldering Iron
- Soldering wire
Circuit connections
The sensor comes with a connector cable having flexible wires with open ends at one side. The wire ends need to be soldered with a male header to be connected to a breadboard or Arduino. First of all, solder the cable wires with male headers. Now insert the connector cable to the header of the fingerprint scanner. It is easy to insert the connector cable as the header has clearly marked cuts for inserting the cable.
Connect the 5V pin and ground of the scanner with 5V out and any ground pin of the Arduino UNO, respectively. Connect the Rxd and Txd of the scanner with pins D2 and D3 of Arduino UNO, respectively.
Installing Adafruit Fingerprint Sensor Library
Navigate to library manager in Arduino IDE and search for Adafruit fingerprint library. Install the Adafruit Fingerprint Scanner Library. This library works fine for both Adafruit fingerprint scanners as well as R30X fingerprint scanners.
Enrolling a fingerprint ID
To enroll a fingerprint impression to the module, navigate to Files -> Examples -> Adafruit’s fingerprint -> Enroll. Upload the code to Arduino and run Serial Monitor. Select the baud rate to 9600. If the fingerprint scanner is properly interfaced with the Arduino, a prompt for entering a fingerprint ID will pop up into the Serial Monitor. Enter a valid fingerprint ID number and place your finger on the scanner. The scanner will prompt to scan the fingerprint impression twice. If successfully scanned, the confirmation message will be displayed in the Serial Monitor.
Matching a fingerprint ID
It is possible to scan a live finger against stored fingerprint templates. To match a fingerprint impression to the module, navigate to Files -> Examples -> Adafruit’s fingerprint -> Fingerprint. Upload the code to Arduino and run Serial Monitor. Select the baud rate to 9600. Place your finger on the scanner. If the scanner has a template stored for your finger, it will respond with the fingerprint ID of your template. If your fingerprint impression is not stored in the module, it will respond with “no match found”.
Extracting fingerprint templates
It is even possible to get the template files stored in the fingerprint module. Navigate to Files -> Examples -> Adafruit’s fingerprint -> show_fingerprint_templates. Upload the code to Arduino and run Serial Monitor. Select the baud rate to 9600. The Serial Monitor will display all the stored fingerprint templates one by one by their ID in sequential order.
Conclusion
R30X and Adafruit Fingerprint Scanners are low-cost and easy-to-use biometric modules. These can be easily interfaced in a security or access system using UART or USB interfaces. The Adafruit library works with R30X and Adafruit Fingerprint Scanners and can be directly used for many hobby projects.
You may also like:
Filed Under: Arduino Projects, Electronic Projects, Featured Contributions
Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.