Optical Fingerprint Sensor with Arduino


Fingerprint Sensor is an alternative device for security and verification purposes. In modern technology, it is included in high-end smartphones as an alternative unlock against pass codes or pattern swipes. One application of the fingerprint sensor is that of an attendance monitoring system, which is widely used in offices.

We are going to create a system which will greet a user when a fingerprint is recognized.

Hardware Used

  • Optical Fingerprint Reader Sensor (R307)
  • 16×2 or 20×4 LCD
  • Breadboard
  • Jumper Wires
    Potentiometer [For Display Contrast]

    If the 16×2 or 20×4 LCD does not have header pin connections soldered, you may need the following tools

    • Soldering Iron (Optional)
    • Soldering Lead (Optional)
    • Header Pins (Optional) [Solder to Fingerprint Sensor wires for stable wire connections]

    You can buy all this Hardware at Createlabz.

    Software Used

    • Arduino IDE
    • SFGDemo (Windows Exclusive Application)
      • Alternatively, you can use this: https://www.sunrom.com/get/981100

    Library Used

    The library used for implementing this mini-project is “Adafruit_Fingerprint.h”, which can be downloaded in the Arduino Library Manager. Otherwise, download the zip files and extract to your Arduino Installation Directory (Default is in C:/Program Files(x86)/Arduino/Libraries)

    Application Description

    There are different types of fingerprint recognition available in the market, such as optical, capacitive, and ultrasonic scanners. For this particular model, it utilizes an optical scanner.

    This type of scanner relies on capturing and comparing fingerprints and then processes  the image using an algorithm to detect unique patterns on the fingerprint. These unique patterns can range from fingerprint ridges or unique marks, which are transformed into Black and White images.

    The higher the resolution of the optical scanner, the lower false positives will return.

    The R307 Fingerprint Sensor can store up to ~1000 templates.

    Enrolling Fingerprints!

    There are two ways to enroll fingerprints: Using Arduino as USB to TTL (through Hardware Serial), and Uploading Codes to the Arduino to enroll fingerprints (through Software Serial).

    Hardware Serial

    1. Extract and run the “SFGDemo.exe” application. Be sure to run the program as Administrator.
    2. Upload a Blank sketch to Arduino.
    3. Set-up the hardware as shown in SET-UP THE HARDWARE (1) .
    4. Click “Open Device(O)” below the Initialization. Select the COM PORT you are using. It is typically found at the lower right of the Arduino IDE.
    5. If the device is successfully connected, it will display the following:


      Default: Baudrate = 57600,Package Size= 128 Bytes,Secure Level=3


    6. To register a fingerprint, click the “Enroll” Button. The “Con Enroll” stands for continuous enrollment of fingerprints.

    Software Serial

    1. Set-up the hardware as shown in the SET-UP THE HARDWARE (2).
    2. Instead of coding from scractch, we will use the Adafruit Fingerprint Enrollment Example from their library.
    3. Open the Arduino’s Serial Monitor. It will prompt the following:

    4. For this mini-project, we will save a fingerprint to ID# “1” (Note : The actual ID # stored is 1 less than the input number. In this example, typing “1” will save the fingerprint to “0” in the device) . After some few steps, it will display the following:


    Searching The Fingerprints !

    As similar to the enrollment procedure, we can use the Windows Application, or search using an uploaded Arduino Code. Searching for the registered fingerprints in the Windows application will be left as an exercise to the user.

    To search the fingerprints using Arduino, upload the sketch below. Change the names in the “listName” array accordingly. (Note: To simplify things, we used arrays to store names. Arrays have an index that starts from 0. In the example, the name “Niko” is referenced to the ID #0)

    Set-up the Hardware

    To see if your connections are correct, there should be a Blue Light flashing inside the fingerprint sensor.




    Note: The Green and Blue wires are not needed for this mini-project.


    “Blank sketch”/”Minimum Sketch” to use the Arduino as USB to TTL :

    void setup() {
      // put your setup code here, to run once:
    void loop() {
      // put your main code here, to run repeatedly:

    Final Output:

    #include <Adafruit_Fingerprint.h>
    #include <LiquidCrystal.h>
    // initialize the library with the numbers of the interface pins
    SoftwareSerial mySerial(2, 3);
    LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
    Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
    String listNames[] = {"Niko", "Kevin"};
    void setup()  
      lcd.begin(16, 2);
      lcd.print("R307 Fingerprint Sensor Test");
      // set the data rate for the sensor serial port
      if (finger.verifyPassword()) {
        Serial.println("Found fingerprint sensor!");
      } else {
        Serial.println("Did not find fingerprint sensor :(");
        while (1) { delay(1); }
      lcd.print("Sensor contains "); lcd.print(finger.templateCount); lcd.println(" templates");
      lcd.println("Waiting for valid finger...\n");
    void loop()                     // run over and over again
      delay(100);            //don't ned to run this at full speed.
    // 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)  
        lcd.print("Unregistered Fingerprint !");
        lcd.print("Hello " + listNames[finger.fingerID]);
      return finger.fingerID; 


    Code Breakdown


    Generally used to verify if the R307 Fingerprint Sensor is connected


    Fetches the total amount of template stored in the fingerprint sensor


    Gives the total amount of template stored in the fingerprint sensor


    Fingerprint sensor applications adds a level of security to a system. Since fingerprint is unique to an individual, there is a low chance for a fingerprint sensor to false trigger. False triggering can be resolved by increasing the fingerprint resolution/clarity for better security. Larger resolution means larger storage size needed, and may need more time to load/read.






    The post Optical Fingerprint Sensor with Arduino appeared first on CreateLabz.

    ArduinoBiometricsFingerprintFingerprint sensorKnowledgebaseR307R307 fingerprint sensorSecurity

    Leave a comment

    All comments are moderated before being published