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

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

Hello and welcome back. In this project, we will learn how to make a DIY door lock system with the AS608 fingerprint sensor. For that, I have used an SG90 servo motor to control the door lock. This project is easy, and anyone can do it. You can use it for doors, cabinets, or safes. Also, I have used an Arduino UNO board for this project, but you can use any Arduino board you have. You’ll also see the lock status on a screen, and a buzzer will make sounds to notify you. If you want to know how the AS608 fingerprint sensor works and how to use this sensor with Arduino, please use this link. You can get a better understanding with this tutorial.

  • How to make a DIY door lock with RFID module – Click on me

OK, let’s do this project. The required components are given below.

Step 1

Firstly, identify these components.

Step 2

Secondly, connect the iron stick to the door lock. For that, use the pictures below.

Step 3

Thirdly, cut a piece of foam board or cardboard using the following size. Then, install the door lock on this board.

Step 4

Then, install the servo motor and connect the end of the iron stick to the servo horn.

Step 5

Now, connect the power pins (5v and GND) to the mini breadboard. Because we need multiple power outputs. For that, use the male-to-male jumper wires.

Step 6

Next, connect the fingerprint sensor, buzzer, servo motor, and LCD screen to the Arduino UNO board. For that, use the circuit diagram below. In this step, you have to solder the I2C module to the LCD screen. Also, please use the correct color wires in the fingerprint sensor.

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

Step 7

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

How to make a DIY door lock system with AS608 fingerprint sensor
  • Code and circuit diagram — Download
  • I2C library — Download
  • Adafruit Fingerprint Sensor Library — Download
  • Then, copy and paste the following program to 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 2.

Step 8

Now, copy and paste the main program on 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 = 2; // 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;
}
How to make a DIY door lock system with AS608 fingerprint sensor
  • Then, select the board and port. After, click the upload button.

Now, you can check your project using your fingerprints. The full video guide is below. So, we hope to see you in the next project. Have a good day.

Troubleshooting

  • Check all jumper wires.
  • Check the sensor wire colors.
  • Install the Fingerprint and I2C library files.
  • Enter the correct fingerprint ID.

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

Similar Posts

Leave a Reply

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