June 17, 2025

Components Required

  1. Arduino Uno
  2. Adafruit Fingerprint Sensor
  3. 16×2 LCD Display (Optional)
  4. Relay Module
  5. Connecting Wires

Code Setup

The code uses Adafruit_Fingerprint.h to interface with the fingerprint sensor, set up the serial communication, and handle fingerprint enrollment and identification.

Step-by-Step Guide

1. Circuit Connection

  • Connect TX of Fingerprint Sensor to Pin 2 of Arduino.
  • Connect RX of Fingerprint Sensor to Pin 3 of Arduino.
  • Connect Relay Module to Pin 4 of Arduino.
  • Ensure 5V and GND connections are securely made to power the sensor and relay.

2. Code Walkthrough

  1. Include Required Libraries
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>

2. Initialize Components

SoftwareSerial mySerial(2, 3);  // Fingerprint sensor on pins 2 (RX) and 3 (TX)
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
#define RELAY_PIN 4
#define ACCESS_DELAY 3000

3. Setup Function

  • Start the serial communication at 9600 baud for debugging.
  • Initialize the fingerprint sensor at 57600 baud.
  • Check for sensor detection and readiness.
  • Set RELAY_PIN as an output and turn it off initially.
void setup() {
   Serial.begin(9600);
   finger.begin(57600);
   if (!finger.verifyPassword()) {
       Serial.println("Fingerprint sensor not found!");
       while (1) { delay(1); }
   }
   pinMode(RELAY_PIN, OUTPUT);
   digitalWrite(RELAY_PIN, HIGH); // Switch off relay initially
}

3. Fingerprint Enrollment and Verification

  • Fingerprint Enrollment:
    • The user can assign a unique ID to each fingerprint for storage.
    • Follow the on-screen instructions for enrolling and verifying a fingerprint.
  • Fingerprint Verification:
    • The system verifies fingerprints using getFingerprintEnroll() and getFingerPrint().
    • If verified, the system triggers the relay to unlock the connected device for 3 seconds (ACCESS_DELAY).

4. Testing the System

  • Upload the code to the Arduino and open the Serial Monitor to follow the enrollment process.
  • Once fingerprints are stored, place a finger on the sensor to verify if it grants access by unlocking the relay for the set duration.

Daigram

FingerPrint_Lock_System Cod

#include <Adafruit_Fingerprint.h>

SoftwareSerial mySerial(2, 3);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

#define RELAY_PIN       4
#define ACCESS_DELAY    3000 // Keep lock unlocked for 3 seconds 


void setup()
{
  // set the data rate for the sensor serial port
  finger.begin(57600);
  delay(5);
  if (finger.verifyPassword()) 
  {
  } 
  else 
  {
    while (1) { delay(1); }
  }
  
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, HIGH);   //Switch off relay initially. Relay is LOW level triggered relay so we need to write HIGH.
}

void loop()
{
  if ( getFingerPrint() != -1)
  {
    digitalWrite(RELAY_PIN, LOW);
    delay(ACCESS_DELAY);
    digitalWrite(RELAY_PIN, HIGH);   
  }  
  delay(50);            //Add some delay before next scan.
}

// returns -1 if failed, otherwise returns ID #
int getFingerPrint() 
{
  int 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!
  return finger.fingerID;
}

FingerPrint_Enroll Cod

#include <Adafruit_Fingerprint.h>

SoftwareSerial mySerial(2, 3);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

uint8_t id;

void setup()
{
  Serial.begin(9600);
  while (!Serial);  
  delay(100);

  // 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();
  finger.getTemplateCount();
  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);
  Serial.print(F("Total finger prints stored: ")); Serial.println(finger.templateCount);
}

uint8_t readnumber(void) 
{
  uint8_t num = 0;

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

void loop() 
{
  Serial.println("\n\nReady to enroll a fingerprint!");
  Serial.println("Please type in -1 to delete all the stored finger prints...");  
  Serial.println("Please type in the ID # (from 1 to 127) you want to save the finger as...");
  id = readnumber();
  if (id == 0) // ID #0 not allowed, try again!
  {
     return;
  }
  if (id == uint8_t(-1))
  {
    Serial.print("Cleared all finger prints from database");
    finger.emptyDatabase();
    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:
      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:
      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;
}

About The Author

46 thoughts on “Arduino Fingerprint Door Lock

  1. This design is spectacular! You most certainly know
    how to keep a reader entertained. Between your wit and your
    videos, I was almost moved to start my own blog (well, almost…HaHa!) Great
    job. I really enjoyed what you had to say, and more than that,
    how you presented it. Too cool!

  2. Excellent blog here! Also your site rather a lot up very fast!

    What host are you the usage of? Can I am getting your associate link to your
    host? I want my web site loaded up as quickly as yours lol

  3. My partner and I stumbled over here by a different web address and thought I may as well check things out.
    I like what I see so now i am following you.
    Look forward to checking out your web page yet
    again.

  4. What you posted made a lot of sense. But, think on this, suppose you added a
    little content? I mean, I don’t want to tell you
    how to run your website, however suppose you added a post
    title that grabbed a person’s attention? I mean Arduino Fingerprint Door
    Lock Robotics lab is a little plain. You ought to look at Yahoo’s front page and note
    how they create news headlines to get people
    to open the links. You might add a video or a related pic or two to grab readers interested about everything’ve got to say.

    Just my opinion, it might make your website a little livelier.

  5. Hi this is somewhat of off topic but I was wanting to know if
    blogs use WYSIWYG editors or if you have to
    manually code with HTML. I’m starting a blog soon but have no coding expertise so
    I wanted to get guidance from someone with experience. Any help would be greatly appreciated!

  6. I’ve been exploring for a little for any high quality articles or weblog posts in this kind of area .
    Exploring in Yahoo I finally stumbled upon this web site.
    Studying this information So i am glad to exhibit that I’ve
    a very good uncanny feeling I came upon just what
    I needed. I most certainly will make sure to don?t forget this website and provides it a
    glance on a continuing basis.

  7. Hello excellent blog! Does running a blog similar to this require a lot of work?
    I have very little understanding of computer programming however I
    had been hoping to start my own blog in the near future.
    Anyway, should you have any recommendations
    or tips for new blog owners please share. I
    understand this is off subject but I simply wanted to
    ask. Appreciate it!

  8. Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates.

    I’ve been looking for a plug-in like this for quite some time and was hoping
    maybe you would have some experience with something like this.
    Please let me know if you run into anything.
    I truly enjoy reading your blog and I look forward to your new updates.

  9. Great beat ! I would like to apprentice while you amend your site, how could i subscribe for
    a blog website? The account helped me a acceptable
    deal. I had been a little bit acquainted of
    this your broadcast provided bright clear idea

  10. I’ve been surfing on-line more than 3 hours lately, but I by
    no means discovered any fascinating article like yours.

    It’s lovely worth enough for me. Personally, if all webmasters and bloggers made good content material
    as you did, the net will likely be much more helpful than ever
    before.

  11. Have you ever thought about publishing an ebook or guest authoring
    on other websites? I have a blog centered on the same ideas you discuss and would really like to have you share some stories/information. I know my visitors would enjoy your work.
    If you are even remotely interested, feel free to shoot me an e mail.

  12. Hello to all, how is all, I think every one is getting more from this web page, and your
    views are pleasant for new people.

Leave a Reply

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