Summary
Learn how to connect the R307 fingerprint sensor to Arduino Uno, install the Adafruit library, enrol fingerprints, match stored IDs and troubleshoot common wiring and communication errors.
How to Use the R307 Fingerprint Sensor with Arduino (Wiring and Code)
The R307 fingerprint sensor can store fingerprint templates and identify a finger by comparing a scanned print with enrolled templates. To use it with Arduino, connect the sensor's power and UART pins, install a compatible fingerprint library, enrol a fingerprint, and run a matching example. The sensor can store up to 1,000 templates, depending on the module's specifications.
This guide covers the R307 pinout, Arduino wiring, library installation, fingerprint enrolment, matching, troubleshooting and a simple attendance or door-lock project.
What Is the R307 Fingerprint Sensor?
The R307 is an optical fingerprint recognition module that captures a fingerprint image, processes it and stores a template for later comparison. Its onboard processing allows a microcontroller such as an Arduino Uno to communicate with it over a serial UART connection instead of processing the fingerprint image itself.
Typical applications include:
-
Fingerprint-based attendance systems
-
Access control and electronic door locks
-
Student embedded-systems projects
-
Personal identification prototypes
-
Arduino security and automation projects
The sensor handles fingerprint capture and template matching internally. Arduino sends commands and receives responses, such as whether a fingerprint matches a stored template.
For the specific R307 module, verify the supplied datasheet for the supported voltage range, storage capacity, baud rate and connector pinout before wiring.
Components and Supplies
R307 Fingerprint Sensor Pinout
Many R307 modules use a six-pin connector. The exact pin order can vary between boards or cable assemblies, so confirm the labels or documentation for your particular sensor before applying power.
|
Sensor pin |
Function |
Arduino connection |
|---|---|---|
|
VCC |
Sensor power |
Supply voltage supported by your module |
|
GND |
Ground |
GND |
|
TX |
Serial data transmitted by sensor |
Arduino RX pin |
|
RX |
Serial data received by sensor |
Arduino TX pin |
|
Touch / Wake |
Optional touch or wake signal on some versions |
Optional digital input, if supported |
|
Additional pin |
May vary by module |
Confirm with the module's pinout |
Important: TX and RX cross over. The sensor's TX connects to the Arduino's RX, and the sensor's RX connects to the Arduino's TX. Do not rely on the physical pin order in a generic diagram if your module's markings differ.
Components Required
Before wiring the circuit, gather these components:
-
USB cable compatible with your Arduino Uno
-
Computer with Arduino IDE installed
The R307 communicates with Arduino using UART serial communication. The Arduino runs the application code, while the fingerprint module handles image capture, fingerprint-template creation and matching.
R307 Fingerprint Sensor Wiring with Arduino Uno
For an Arduino Uno, use software serial on digital pins 2 and 3 so that the USB serial connection remains available for the Serial Monitor.
Wiring Table
|
R307 pin |
Arduino Uno pin |
Purpose |
|---|---|---|
|
VCC |
5V, if supported by your module |
Sensor power |
|
GND |
GND |
Common ground |
|
TX / TXD |
D2 |
Sensor transmits data to Arduino |
|
RX / RXD |
D3 |
Arduino transmits data to sensor |
|
Touch |
Leave disconnected for basic testing |
Optional finger-detection signal |
|
Additional pin |
Leave disconnected unless required |
Check the module documentation |
The UART connections must cross over: sensor TX goes to Arduino D2, and sensor RX goes to Arduino D3. The library's software-serial constructor uses the order (Arduino RX, Arduino TX).
Power warning: Many R307 modules specify a supply around 4.2–6V, but module variants can differ. Verify the voltage and pin labels for your exact sensor. Do not connect an unidentified pin to 5V based only on its position or wire colour.
Installing the Adafruit Fingerprint Library
The Adafruit Fingerprint Sensor Library provides functions for communicating with compatible UART fingerprint modules, enrolling fingerprints and searching stored templates.
Follow these steps:
-
Open the Arduino IDE.
-
Select Sketch → Include Library → Manage Libraries.
-
Search for
Adafruit Fingerprint Sensor Library. -
Install the library by Adafruit.
-
Connect the Arduino Uno to your computer using USB.
-
Select the correct board and port from the Tools menu.
You can also review the library's official repository: Adafruit Fingerprint Sensor Library.
Before uploading the enrolment or matching program, test the connection using the library's example sketch if you are unsure whether the wiring is correct.
Enrolling a Fingerprint with Arduino
Enrolment stores a fingerprint template in the sensor's memory. The same finger is scanned twice so the module can compare the two captures and create a template.
This example stores a fingerprint under ID 1. Install the Adafruit library first, then upload the sketch and open the Serial Monitor at 9600 baud.
Arduino Code: Fingerprint Enrolment
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
// Arduino RX, TX
SoftwareSerial fingerSerial(2, 3);
Adafruit_Fingerprint finger(&fingerSerial);
const uint16_t fingerprintID = 1;
bool waitForImage() {
while (true) {
uint8_t result = finger.getImage();
if (result == FINGERPRINT_OK) {
return true;
}
if (result != FINGERPRINT_NOFINGER) {
Serial.print("Image capture error: ");
Serial.println(result);
return false;
}
delay(100);
}
}
void waitForFingerRemoval() {
Serial.println("Remove your finger.");
while (finger.getImage() != FINGERPRINT_NOFINGER) {
delay(100);
}
}
bool enrollFingerprint() {
Serial.println("Place your finger on the sensor.");
if (!waitForImage()) return false;
if (finger.image2Tz(1) != FINGERPRINT_OK) {
Serial.println("Could not process first scan.");
return false;
}
waitForFingerRemoval();
delay(500);
Serial.println("Place the same finger again.");
if (!waitForImage()) return false;
if (finger.image2Tz(2) != FINGERPRINT_OK) {
Serial.println("Could not process second scan.");
return false;
}
if (finger.createModel() != FINGERPRINT_OK) {
Serial.println("Scans did not match. Try again.");
return false;
}
if (finger.storeModel(fingerprintID) != FINGERPRINT_OK) {
Serial.println("Could not save fingerprint.");
return false;
}
Serial.println("Fingerprint enrolled successfully!");
Serial.print("Stored under ID: ");
Serial.println(fingerprintID);
return true;
}
void setup() {
Serial.begin(9600);
finger.begin(57600);
if (!finger.verifyPassword()) {
Serial.println("Sensor not found. Check wiring and baud rate.");
while (true) delay(100);
}
Serial.println("R307 fingerprint sensor detected.");
while (!enrollFingerprint()) {
Serial.println("Enrolment failed. Starting again...");
delay(1000);
}
}
void loop() {
// Enrolment runs during setup.
}
How the Enrolment Code Works
-
The Arduino checks whether the fingerprint sensor responds.
-
The user places a finger on the scanner for the first capture.
-
The sensor converts the captured image into fingerprint features.
-
The user removes the finger and places the same finger again.
-
The sensor compares the captures and creates a model if they match.
-
The Arduino asks the sensor to store the model under ID
1.
Note: This is a basic teaching example. If you run it again, it attempts to enrol ID 1 again, potentially replacing the existing template. Use a unique ID for each enrolled person in a multi-user project. The enrolment loop waits for a finger and may need a reset if communication fails during capture.
Matching a Fingerprint with Arduino
After enrolment, upload this separate sketch to search for the stored fingerprint. It continuously scans for a finger and reports whether the sensor finds a matching template.
Arduino Code: Fingerprint Matching
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
// Arduino RX, TX
SoftwareSerial fingerSerial(2, 3);
Adafruit_Fingerprint finger(&fingerSerial);
void setup() {
Serial.begin(9600);
finger.begin(57600);
if (!finger.verifyPassword()) {
Serial.println("Sensor not found. Check wiring and baud rate.");
while (true) delay(100);
}
Serial.println("Fingerprint matching is ready.");
}
void loop() {
uint8_t result = finger.getImage();
if (result == FINGERPRINT_NOFINGER) {
delay(100);
return;
}
if (result != FINGERPRINT_OK) {
Serial.println("Could not capture fingerprint.");
delay(300);
return;
}
result = finger.image2Tz();
if (result != FINGERPRINT_OK) {
Serial.println("Could not process fingerprint.");
delay(500);
return;
}
result = finger.fingerFastSearch();
if (result == FINGERPRINT_OK) {
Serial.println("Fingerprint matched!");
Serial.print("Stored ID: ");
Serial.println(finger.fingerID);
Serial.print("Match confidence: ");
Serial.println(finger.confidence);
} else if (result == FINGERPRINT_NOTFOUND) {
Serial.println("No matching fingerprint found.");
} else {
Serial.print("Search error: ");
Serial.println(result);
}
delay(800);
}
Expected Output
When the sensor finds a stored fingerprint, the Serial Monitor displays output similar to this:
Fingerprint matching is ready.
Fingerprint matched!
Stored ID: 1
Match confidence: 120
The ID and confidence score are examples; actual values depend on the enrolled template and scan. If the sensor cannot find a match, it reports that no matching fingerprint was found.
The confidence value is a sensor-reported matching score, not a percentage probability of identity. Do not treat it as a standalone security guarantee.
Troubleshooting R307 Fingerprint Sensor with Arduino
If the sensor does not detect a finger or the Arduino cannot communicate with it, check the wiring, supply voltage, serial settings and fingerprint enrolment.
|
Problem |
Possible cause |
What to do |
|---|---|---|
|
|
Incorrect wiring, wrong baud rate or insufficient power |
Check VCC and GND, swap TX/RX if needed, and verify the sensor's configured baud rate |
|
Fingerprint not detected |
Finger is not positioned correctly or the sensor window is dirty |
Clean the scanner window gently and place the finger flat over the sensing area |
|
Fingerprint scans but does not match |
Finger moved between scans, poor image quality or no template enrolled |
Re-enrol the same finger and ensure both captures are clear |
|
Communication errors |
Loose connections, unsuitable serial pins or unreliable software serial communication |
Check connections and use a supported serial interface; confirm the baud rate |
|
Sensor resets or behaves inconsistently |
Unstable supply or wiring |
Check the specified supply voltage and provide a stable power source |
|
Fingerprint ID is not found |
The template was not saved or the wrong ID was used |
Run enrolment again and confirm that the sensor reports successful storage |
The Adafruit library documentation recommends checking wiring and the TX/RX connections when the sensor is not detected. Its example sketches also report sensor parameters, including capacity and baud rate, which can help with diagnosis.
Quick Checks Before Re-uploading Code
-
Confirm the sensor's VCC and GND connections.
-
Check that sensor TX connects to Arduino D2 and sensor RX connects to D3 for the wiring used in these examples.
-
Set the Serial Monitor to 9600 baud.
-
Confirm the sensor UART baud rate matches
finger.begin(57600). -
Upload the enrolment sketch before testing fingerprint matching.
-
If the problem persists, run the library's sensor test example to verify communication.
R307 Fingerprint Sensor Project Ideas
Once the sensor is communicating correctly with Arduino, you can extend the project beyond enrolment and matching.
1. Fingerprint Attendance System
Assign each enrolled fingerprint an ID and record the ID with a timestamp. To build a useful attendance system, add a real-time clock module or another reliable time source, and store records using an SD card or connected computer.
2. Fingerprint-Based Door Lock
Use a successful fingerprint match to trigger a relay or a suitable driver connected to a lock mechanism. Include a safe default state, a timeout and a manual override. Choose the switching hardware based on the lock's voltage and current requirements.
3. Fingerprint-Controlled Locker
Use a matched fingerprint to operate a low-voltage locking mechanism. Add status LEDs or a display to indicate whether access was granted or denied.
4. Fingerprint Access with Raspberry Pi
A Raspberry Pi can communicate with a compatible UART fingerprint sensor through a suitable serial interface. Software can then log events or integrate the reader into a larger access-control prototype.
Security consideration: These projects are educational prototypes, not automatically secure access-control systems. A fingerprint match alone does not prevent every spoofing or hardware attack. Do not rely on a basic R307-and-Arduino setup as the sole security mechanism for high-risk doors, valuable assets or sensitive personal data.
Conclusion
The R307 fingerprint sensor makes it possible to add fingerprint enrolment and matching to Arduino projects without implementing fingerprint-image processing from scratch. Connect its UART pins correctly, install the Adafruit Fingerprint Sensor Library, enrol a template and then test matching using the returned fingerprint ID.
Start with the R307 Optical Fingerprint Sensor Module, an Arduino Uno and a Jumper Wire Set. Once the basic setup works, you can expand it into an attendance logger, a locker prototype or a low-voltage access-control project.




