Arduino Projects

Interfacing R307 Fingerprint Sensor With Arduino

How to Use R307 Biometric Fingerprint Sensor With Arduino

Overview: R307 Fingerprint Sensor & Arduino

In this guide, we will demonstrate how to interface the R307 fingerprint sensor with an Arduino board. The R307 fingerprint sensor is an optical sensor designed to capture and store fingerprint data.

With a resolution of 512×288 pixels, this sensor can conveniently store up to 1000 fingerprint templates. To establish the connection between the sensor and Arduino, we will utilize the UART interface.

Interfacing R307 Fingerprint Sensor With Arduino on breadboard
Interfacing R307 Fingerprint Sensor With Arduino

Components Required

To successfully interface the R307 fingerprint sensor with Arduino, you will need the following components:

  • Arduino Nano or Similar Board: You will need an Arduino board, such as the Arduino Nano, to serve as the microcontroller and facilitate communication between the sensor and your computer.
  • R307 Fingerprint Sensor: The main component responsible for capturing and storing fingerprint data.
  • Breadboard: A breadboard will be used for prototyping and making the necessary connections between the sensor, Arduino board, and other components.
  • Jumper Wires: These wires will be used to establish the required connections between the R307 fingerprint sensor, Arduino Nano, and breadboard.

Ensure that you have these components ready before proceeding with the interfacing process.

S.NCOMPONENTS NAMEQUANTITYPURCHASE LINKS
1Arduino Nano1 Amazon | AliExpress
2R307 Fingerprint Sensor1 Amazon | AliExpress
3Breadboard1 Amazon | AliExpress
4Jumper Cables10 Amazon | AliExpress

R307 Fingerprint Scanner Sensor

The R307 fingerprint sensor module is designed for capturing and recognizing fingerprints. It utilizes an optical sensor to capture fingerprints. It uses a robust image-processing algorithm for fast and accurate fingerprint recognition.

R307 Fingerprint Sensor

With built-in memory, the R307 sensor can store up to 1000 fingerprints. It features a UART interface, allowing seamless integration with microcontrollers like Arduino, Raspberry Pi, and other UART-compatible devices.

R307 Fingerprint Sensor pinouts

The R307 fingerprint sensor is widely used in security systems and access control systems.

How R307 Fingerprint Scanners Work

The R307 fingerprint sensor functions by scanning an individual’s fingerprint and generating a digital image that represents the unique patterns of the fingertip. This image is then processed and converted into a mathematical algorithm, which is stored within the sensor.

Working of R307 Fingerprint Sensor

During subsequent scans, the sensor compares the new fingerprint image to the stored algorithm to verify if there is a match. If the fingerprint and algorithm correspond, the sensor produces a signal indicating a valid fingerprint.

Pinout of R307 Fingerprint Sensor

The R307 fingerprint sensor module consists of 6 pins. But we only use 4 of them for communication and power supply. The following diagram illustrates the pinout configuration of the R307 fingerprint sensor.

R307 Sensor

Specifications of R307 Fingerprint Sensor

  • Model: R307 Fingerprint Sensor
  • Sensor Type: Optical
  • Resolution: 500 DPI
  • Image Capture Area: 15.4mm x 18.2mm
  • Image Capture Time: <1.0s
  • Operating Voltage: 3.3V – 6V DC
  • Operating Current: <100mA
  • Interface: UART/TTL
  • Baud Rate: 9600 bps (default), adjustable to other rates such as 19200 bps
  • Fingerprint Capacity: Up to 1000 fingerprints
  • False Acceptance Rate (FAR): <0.001%
  • False Rejection Rate (FRR): <0.1%
  • Operating Temperature: -20°C to 50°C
  • Operating Humidity: 40% to 85%
  • Dimensions: 56 x 20 x 21.5 mm (L x W x H)
  • Weight: 12g

Check Out the R307 Fingerprint Sensor datasheet

Applications of R307 Fingerprint Sensor

The R307 fingerprint sensor finds extensive use across various industries. Here are some common applications of the R307 sensor:

  • Access control systems
  • Time and attendance systems
  • Security systems
  • Door locks
  • Employee identification systems
  • Banking and financial applications
  • Healthcare applications
  • Government applications
  • Smart homes and Internet of Things (IoT) applications.

Difference Between R305 and R307 Fingerprint Sensor

DescriptionR305 SensorR307 Sensor
Storage Capacity2501000
3.3V OperationNoYes
USB OperationNoYes
Finger Detect OutputNoYes

Interfacing Fingerprint Sensor with Arduino

To interface the Fingerprint Sensor with Arduino, follow these steps:

Connect the Fingerprint Sensor to the Arduino board using jumper wires. Make sure to connect the sensor’s VCC pin to the 5V pin on the Arduino, GND to GND, RX to pin D3, and TX to pin D2.

Refer to the provided wiring diagram for a visual representation of the connections.

Interfacing Fingerprint Sensor with Arduino Nano
Interfacing R307 Fingerprint Sensor With Arduino

Wiring Diagram for Fingerprint Sensor with Arduino:

  • VCC pin to 5V pin of Arduino
  • GND pin to GND pin of Arduino
  • TX pin to pin D2 of Arduino
  • RX pin to pin D3 of Arduino

Setting up the Adafruit Fingerprint Sensor R307 Arduino Library

Download and install the Adafruit Fingerprint Library in the Arduino IDE. Go to Sketch > Include Library > Manage Libraries and search for “Adafruit Fingerprint“. Install the library and include it in your sketch.

Adafruit Fingerprint sensor Library

With the library installed, you can now utilize the Adafruit Fingerprint Library to capture and compare fingerprints with pre-stored fingerprints in the chip.

Uploading Code to Arduino Board

Follow these steps to successfully interface the Fingerprint Sensor with Arduino using the Adafruit Fingerprint Library. Open the Arduino IDE. Upload the “enroll” example code to your Arduino board. This can be done by selecting “File” in the Arduino IDE, then choosing “Examples” > “Adafruit Fingerprint” > “enroll”.

Fingerprint Enrollment Code

Fingerprint enrollment example code:

#include <Adafruit_Fingerprint.h>


#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)
// 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)
// Set up the serial port to use softwareserial..
SoftwareSerial mySerial(2, 3);

#else
// On Leonardo/M0/etc, others with hardware serial, use hardware serial!
// #0 is green wire, #1 is white
#define mySerial Serial1

#endif


Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

uint8_t id;

void setup()
{
  Serial.begin(9600);
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println("\n\nAdafruit Fingerprint sensor enrollment");

  // set the data rate for the sensor serial port
  finger.begin(57600);

  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1) { delay(1); }
  }

  Serial.println(F("Reading sensor parameters"));
  finger.getParameters();
  Serial.print(F("Status: 0x")); Serial.println(finger.status_reg, HEX);
  Serial.print(F("Sys ID: 0x")); Serial.println(finger.system_id, HEX);
  Serial.print(F("Capacity: ")); Serial.println(finger.capacity);
  Serial.print(F("Security level: ")); Serial.println(finger.security_level);
  Serial.print(F("Device address: ")); Serial.println(finger.device_addr, HEX);
  Serial.print(F("Packet len: ")); Serial.println(finger.packet_len);
  Serial.print(F("Baud rate: ")); Serial.println(finger.baud_rate);
}

uint8_t readnumber(void) {
  uint8_t num = 0;

  while (num == 0) {
    while (! Serial.available());
    num = Serial.parseInt();
  }
  return num;
}

void loop()                     // run over and over again
{
  Serial.println("Ready to enroll a fingerprint!");
  Serial.println("Please type in the ID # (from 1 to 127) you want to save this finger as...");
  id = readnumber();
  if (id == 0) {// ID #0 not allowed, try again!
     return;
  }
  Serial.print("Enrolling ID #");
  Serial.println(id);

  while (!  getFingerprintEnroll() );
}

uint8_t getFingerprintEnroll() {

  int p = -1;
  Serial.print("Waiting for valid finger to enroll as #"); Serial.println(id);
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      break;
    default:
      Serial.println("Unknown error");
      break;
    }
  }

  // OK success!

  p = finger.image2Tz(1);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  Serial.println("Remove finger");
  delay(2000);
  p = 0;
  while (p != FINGERPRINT_NOFINGER) {
    p = finger.getImage();
  }
  Serial.print("ID "); Serial.println(id);
  p = -1;
  Serial.println("Place same finger again");
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.print(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      break;
    default:
      Serial.println("Unknown error");
      break;
    }
  }

  // OK success!

  p = finger.image2Tz(2);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK converted!
  Serial.print("Creating model for #");  Serial.println(id);

  p = finger.createModel();
  if (p == FINGERPRINT_OK) {
    Serial.println("Prints matched!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_ENROLLMISMATCH) {
    Serial.println("Fingerprints did not match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }

  Serial.print("ID "); Serial.println(id);
  p = finger.storeModel(id);
  if (p == FINGERPRINT_OK) {
    Serial.println("Stored!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_BADLOCATION) {
    Serial.println("Could not store in that location");
    return p;
  } else if (p == FINGERPRINT_FLASHERR) {
    Serial.println("Error writing to flash");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }

  return true;
}

Once the upload is complete, open the Serial Monitor in the Arduino IDE. Set the baud rate to “9600” in the Serial Monitor.

Fingerprint Enrollment

In the Serial Monitor, you will see the prompt “Enroll Fingerprint”. Follow the instructions displayed in the Serial Monitor:

  • Set the Finger Print ID number according to the code.
  • Place an enrolled finger on the sensor.
  • Place the finger again on the sensor for confirmation.
Fingerprint Enrolled

After successfully enrolling the fingerprint, you can proceed to the final code.

By following these steps, you will be able to enroll fingerprints and test for a match using the R307 Fingerprint Sensor with Arduino.

Fingerprint Verification Code

Once the fingerprints have been registered and enrolled, you can proceed with the following steps to verify the fingerprints using the example code:

#include <Adafruit_Fingerprint.h>


#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)
// 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)
// Set up the serial port to use softwareserial..
SoftwareSerial mySerial(2, 3);

#else
// On Leonardo/M0/etc, others with hardware serial, use hardware serial!
// #0 is green wire, #1 is white
#define mySerial Serial1

#endif


Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()
{
  Serial.begin(9600);
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println("\n\nAdafruit finger detect test");

  // set the data rate for the sensor serial port
  finger.begin(57600);
  delay(5);
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1) { delay(1); }
  }

  Serial.println(F("Reading sensor parameters"));
  finger.getParameters();
  Serial.print(F("Status: 0x")); Serial.println(finger.status_reg, HEX);
  Serial.print(F("Sys ID: 0x")); Serial.println(finger.system_id, HEX);
  Serial.print(F("Capacity: ")); Serial.println(finger.capacity);
  Serial.print(F("Security level: ")); Serial.println(finger.security_level);
  Serial.print(F("Device address: ")); Serial.println(finger.device_addr, HEX);
  Serial.print(F("Packet len: ")); Serial.println(finger.packet_len);
  Serial.print(F("Baud rate: ")); Serial.println(finger.baud_rate);

  finger.getTemplateCount();

  if (finger.templateCount == 0) {
    Serial.print("Sensor doesn't contain any fingerprint data. Please run the 'enroll' example.");
  }
  else {
    Serial.println("Waiting for valid finger...");
      Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
  }
}

void loop()                     // run over and over again
{
  getFingerprintID();
  delay(50);            //don't ned to run this at full speed.
}

uint8_t getFingerprintID() {
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println("No finger detected");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK success!

  p = finger.image2Tz();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK converted!
  p = finger.fingerSearch();
  if (p == FINGERPRINT_OK) {
    Serial.println("Found a print match!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
    Serial.println("Did not find a match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }

  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID);
  Serial.print(" with confidence of "); Serial.println(finger.confidence);

  return finger.fingerID;
}

// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.image2Tz();
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK)  return -1;

  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID);
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
  return finger.fingerID;
}
  • Load the example code for fingerprint verification in the Arduino IDE.
  • Upload the code to your Arduino board.
  • After the upload is complete, open the Serial Monitor in the Arduino IDE.
  • In the Serial Monitor, you will see the prompt to place your finger on the sensor.
Interfacing R307 Fingerprint Sensor With Arduino nano
Interfacing R307 Fingerprint Sensor With Arduino
  • Place your enrolled finger on the sensor, and the sketch will read the fingerprint data.
  • The sketch will then compare the read fingerprint data with the enrolled fingerprints in its database.
  • The result will be displayed in the Serial Monitor, indicating the match or non-match of the fingerprint with the enrolled data.
Fingerprint Verification

Conclusion

By following these steps, you will be able to verify the registered fingerprints using the example code. The sketch will provide information on how closely the read fingerprint matches the enrolled data stored in the database.

Related Articles

3 Comments

  1. Pingback: Fingerprint Door Lock Security Systems Using Arduino & LCD

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button