RoboThings

Fingerprint Sensor Module - R307
Fingerprint sensors have become an essential component in many security systems. The R307 is a popular and user-friendly fingerprint sensor module that's perfect for adding biometric security to your Arduino projects. In this guide, I'll walk you through the process of setting up and using the R307 fingerprint sensor with the Arduino IDE for the first time.

What You’ll Need

  • Arduino Board (e.g., Arduino Uno, Nano, etc.)
  • Fingerprint Sensor Module – R307
  • Breadboard and Jumper Wires
  • Arduino IDE (with necessary libraries installed)

Step 1: Install the Arduino IDE

If you haven’t already, download and install the Arduino IDE from the official Arduino website.

Step 2: Understanding the R307 Fingerprint Sensor

The R307 is a versatile fingerprint sensor module that includes a powerful DSP chip that does image rendering, calculating, feature finding, and searching. It can store up to 1000 fingerprints and provides a UART interface, making it easy to connect with microcontrollers like Ardui

Step 3: Wiring the R307 Fingerprint Sensor

The R307 has four pins:

  • VCC: Connects to the 5V pin of the Arduino.
  • GND: Connects to the Ground (GND) pin of the Arduino.
  • TX: Connects to the RX pin of the Arduino.
  • RX: Connects to the TX pin of the Arduino.

 

 

 

 

Wiring Diagram:

Step 4: Installing the Necessary Library

  1. To communicate with the R307 sensor, we’ll use the Adafruit Fingerprint Sensor Library. Follow these steps to install the library:

    1. Open the Arduino IDE.
    2. Navigate to Sketch > Include Library > Manage Libraries.
    3. In the Library Manager, search for “Adafruit Fingerprint Sensor Library”.
    4. Install the library by Adafruit.

Step 5: Writing the Code

Here’s a simple sketch to get started with the R307 fingerprint sensor. This code will help you enroll a fingerprint and then match it with the stored ones.

				
					#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()
{
  Serial.begin(9600);
  while (!Serial); // For Leonardo/Micro/Zero
  delay(100);
  Serial.println("Adafruit Fingerprint sensor enrollment example");

  // 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);
  }
}

void loop()
{
  Serial.println("Waiting for valid finger...");
  getFingerprintID();
  delay(50); // Don't need to run this at full speed.
}

int 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 -1;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return -1;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      return -1;
    default:
      Serial.println("Unknown error");
      return -1;
  }

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

  // 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 -1;
  }
  else if (p == FINGERPRINT_NOTFOUND)
  {
    Serial.println("Did not find a match");
    return -1;
  }
  else
  {
    Serial.println("Unknown error");
    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;
}

				
			

Step 6: Upload and Test

    1. Connect your Arduino to the computer.
    2. Upload the code to your Arduino board.
    3. Open the Serial Monitor, set it to 9600 baud, and follow the on-screen instructions.

Now, when you place your finger on the sensor, the Arduino should be able to read it and provide feedback in the Serial Monitor.

Conclusion

You’ve successfully set up the R307 fingerprint sensor with the Arduino IDE! This setup can be the basis for various biometric security projects, such as door locks, attendance systems, and more.

2.2 19 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
Open chat
1
Hi, how can I help you?
Powered by