How to make a DIY door locker system using a fingerprint sensor

How to make a DIY door locker system using a fingerprint sensor

Hello and welcome back. In this project, we will learn how to make a DIY door locker system using a fingerprint sensor. For this project, I mainly used the Arduino UNO board as the controller. The AS608 fingerprint sensor is used to store and recognize authorized fingerprints. I also used a low-cost and simple door lock mechanism made using a servo motor, which moves to lock and unlock the door when a valid fingerprint is detected.

For example, I used a simple door structure, but you can apply this system to a real door, a safety box, a cupboard, or any other suitable place. I think this is a good project for beginners who want to learn about Arduino, fingerprint sensors, and basic security systems.

Ok, let’s do this project step by step. The required components are given below.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, identify these components.

Step 2

Secondly, let’s create the door structure. For this, I used a 5 mm foam board. You can also use cardboard or any other suitable material for this purpose.

Step 3

Thirdly, make holders for mounting the LCD screen and the fingerprint sensor. For this, use the picture below.

Step 4

Next, install the door hinges on the door structure.

Step 5

Now, connect the door locker to the servo horn using an iron stick. Then, install this structure on the back side of the door.

Step 6

Afterward, connect all the components to the Arduino UNO board. For this, use the circuit diagram below.

How to make a DIY door lock system with AS608 fingerprint sensor

Step 7

Now, connect the Arduino UNO board to the computer. Then, enroll your fingerprints. For that, follow the instructions below.

  • Code and circuit diagram — Download
  • I2C library — Download
  • Adafruit Fingerprint Sensor Library — Download
  • Then, copy and paste the following program into the Arduino IDE.
#include <LiquidCrystal_I2C.h>
#include <Adafruit_Fingerprint.h>

LiquidCrystal_I2C dis(0x27, 16, 2);
SoftwareSerial mySerial(2, 3); // TX/RX
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

uint8_t id;

void setup() {
  Serial.begin(9600);
  dis.init();
  dis.backlight();
  dis.setCursor(1, 0);
  dis.print("Place your");
  dis.setCursor(7, 1);
  dis.print("finger->");
  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);
    }
  }

  finger.getParameters();
}

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);
  dis.clear();
  dis.setCursor(0, 0);
  dis.print("ID: ");
  dis.print(id);
  p = finger.storeModel(id);
  if (p == FINGERPRINT_OK) {
    Serial.println("Stored!");
    dis.print(" 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;
}
  • Now, select the board and port. After, click the upload button.
  • Next, open the serial monitor and enter an ID value between 1 and 127. Then, follow the instructions on the serial monitor. I have enrolled one fingerprint with ID 1.

Step 8

Now, copy and paste the main program into the Arduino IDE and enter your ID.

#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <Servo.h>
#include <Adafruit_Fingerprint.h>

#define buzzer 4
#define servoPin 5
#define doorLock 80
#define doorOpen 170
Servo servo;

SoftwareSerial mySerial(2, 3);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
LiquidCrystal_I2C dis(0x27, 16, 2);

byte ID = 1; // Enter your fingerprint ID
bool Switch = true;

void setup() {
  Serial.begin(57600);
  servo.attach(servoPin);
  servo.write(doorLock);
  dis.init();
  dis.backlight();
  pinMode(buzzer, OUTPUT);
  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);
    }
  }

  finger.getParameters();
  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() {
  int value = getFingerprintIDez();
  dis.setCursor(1, 0);
  dis.print("Place your");
  dis.setCursor(7, 1);
  dis.print("finger->");

  if (value == ID) {
    if (Switch) {
      dis.clear();
      dis.setCursor(3, 0);
      dis.print("Successful");
      digitalWrite(buzzer, HIGH);
      delay(500);
      digitalWrite(buzzer, LOW);
      servo.write(doorLock);
      dis.clear();
      Switch = false;
    } else if (Switch == false) {
      dis.clear();
      dis.setCursor(3, 0);
      dis.print("Successful");
      digitalWrite(buzzer, HIGH);
      delay(500);
      digitalWrite(buzzer, LOW);
      servo.write(doorOpen);
      dis.clear();
      Switch = true;
    }
  } else if (value == -2) {
    dis.clear();
    dis.setCursor(3, 0);
    dis.print("Try again!");
        digitalWrite(buzzer, HIGH);
        delay(100);
        digitalWrite(buzzer, LOW);
        delay(100);
        digitalWrite(buzzer, HIGH);
        delay(100);
        digitalWrite(buzzer, LOW);
        delay(100);
        digitalWrite(buzzer, HIGH);
        delay(100);
        digitalWrite(buzzer, LOW);
        delay(100);
        dis.clear();
  }
}

// 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 -2;

  return finger.fingerID;
}
  • Then, select the board and port. After, click the upload button.

Step 9

Finally, remove the USB cable and provide an external power supply to the Arduino UNO board. For this, I used two Li-ion batteries. Then, you can test your project using your registered fingerprint.

Ok, enjoy this project. The full video guide is given below. We hope to see you in the next project. Have a great day!

In this project, we will learn how to make a DIY door locker system using a fingerprint sensor

Similar Posts

Leave a Reply

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