Hello, 

In this tutorial, we are going to learn how to make a Fingerprint locker using Arduino.

Hardware Required

   1. Door Lock
   2. Fingerprint Sensor 

   3. Arduino UNO
   4. Jumper wires
   5.12v Dc Power Supply Adapter
   6. IRFZ44N Power MOSFET

Software Required

  1. Arduino IDE

Working principle of the Fingerprint sensor

  • Generally, the fingerprint scanner works in two ways. First is the optical one, another is the capacitive one. The optical fingerprint has a light inside it. This light will be flashed to the finger and it will capture the picture digitally. 

  • Then it converts this fingerprint pattern into a source code of 0 and 1. This code is unique as each fingerprint is unique. And this code can be used to identify the fingerprint. If the fingerprint source code matches the authorized one, then and only then access is granted by the sensor to the system. 

R307 Optical fingerprint scanner

  • This fingerprint scanner involves two processes. One is fingerprint enrollment. After the fingerprint has been enrolled and stored. The second process is fingerprint matching.

  •  The exterior of the fingerprint sensor is as follows:

Solenoid door lock

  • This 12V Electromagnetic Solenoid Lock can be used for locking storage shelves, file cabinets, etc. You can control the opening and closing of the lock with the help of programming. But for the lock to work, it must be connected to a power supply as this is an electromagnetic lock. The lock works as the current disconnects, and it will unlock as the instant power is on.

IRFZ44N MOSFET

  • IRFZ44N is an advanced HEXFET Power MOSFET that utilizes advanced processing techniques to achieve extremely low on-resistance per silicon area. This benefit, combined with the fast switching speed and ruggedized device design that exFAT power MOSFETs are well known for, provides the designer with an extremely efficient and reliable device for use in a wide variety of applications. 

Circuit Diagram

  • The circuit diagram for the Fingerprint locker is mentioned below. 

  • The gate and the source pins on MOSFET are connected to the Arduino Uno on GND and digital pin 12 respectively. The drain pin is connected to the solenoid lock. 

  • The Tx and Rx pins on the fingerprint sensor are connected to the digital pins 2 and 3 respectively. 5V is connected to 5V and GND to GND.

  • The positive terminal on the solenoid lock is connected to the Vin on the Arduino Uno.

Working Concept of the Fingerprint locker

  • As we now know, the fingerprint scanner works in two processes. Fingerprint enrollment and matching. Similarly, it also works in the same way in this project.

  • At first, we have to store the fingerprint in the sensor via fingerprint enrollment. Once the fingerprint is stored, we can start with fingerprint matching.

  • Whenever the enrolled print matches the current fingerprint, the scanner sends those signals to the Arduino Uno. The Arduino in turn sends the signal to the solenoid door lock to unlock if the fingerprint matches.

  • An IRFZ44N MOSFET has been connected between the solenoid lock and the Arduino Uno. A MOSFET is a semiconductor device that is generally used to amplify electronic signals in devices. 

Arduino Code

  • The circuit diagram and libraries can be downloaded here.

  • Below given is the code to save the fingerprint onto the Arduino board.

#include 
#include 
SoftwareSerial mySerial(2, 3);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

uint8_t id;

void setup()  
{
  Serial.begin(9600);
  while (!Serial);  
  delay(100);
  Serial.println("\n\nFingerprint sensor enrollment");

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

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

void loop()                  
{
  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) {
     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;
    }
  }

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


  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;
  }
  
  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;
  }   
}
  • After saving the code on the Arduino board, now upload the final code for the fingerprint locker.
#include 
#include 

SoftwareSerial mySerial(2, 3);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()  
{
  Serial.begin(9600);
  while (!Serial);  
  delay(100);
  Serial.println("fingertest");
  pinMode(12, OUTPUT);

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

  finger.getTemplateCount();
  Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
  Serial.println("Waiting for valid finger...");
}

void loop()                    

{
  getFingerprintIDez();
  delay(50);            
  digitalWrite(12, LOW);
}

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

  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;
  }
  
  p = finger.fingerFastSearch();
  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;
  }   
  
  Serial.print("Found ID #"); Serial.print(finger.fingerID); 
  Serial.print(" with confidence of "); Serial.println(finger.confidence); 

  return finger.fingerID;
}

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;
 
  digitalWrite(12, HIGH);
  delay(3000);
  digitalWrite(12, LOW);

  Serial.print("Found ID #"); Serial.print(finger.fingerID); 
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
  return finger.fingerID; 
}

  • Upload the first code to the Arduino board, this code is for fingerprint enrollment. Open the Serial monitor after uploading the code, Enroll your finger image to the Arduino board.

  • The Arduino can take data for up to 127 different fingerprints.

  • Once you are done with the enrollment, then upload the second code to the Arduino board. This is the final code for the Fingerprint locker using Arduino. 

Now your Fingerprint locker is ready to use!