In this article, I will explain how to create a Fingerprint Lock using
Arduino Mega 2560. It will be used to identify the same user in the same way that a fingerprint scanner works.
Parts
- Fingerprint sensor
- Arduino Mega 2560
- Servo motor
- Jumper wires
Fingerprint Sensor
Figure 1: Fingerprint Sensor
- It is an electronic device and captures digital images.
- The captured image is called a live scan.
- It simply identifies the fingerprint and gives the result.
- It can easily match the fingerprint.
Step 1: Connection From Servo Motor To Arduino Mega 2560,
- The servo first pin can be connected to the Gnd.
- The second pin can be connected to the VCC.
- The third pin can be connected to the digital pin 06 of the Arduino Mega 2560.
Step 2: Connection From Fingerprint Sensor To Arduino Mega 2560,
- The Gnd pin of the fingerprint sensor to the Gnd of the Arduino Mega 2560
- The Vcc pin of the fingerprint sensor to the 5v of the Arduino Mega 2560
- The Rx pin can be connected to the A4 of the Arduino Mega 2560.
- The Tx pin can be connected to the A5 of the Arduino Mega 2560.
Programming
- #include<Fingerprint.h>
- #include<SoftwareSerial.h>
- #include<Streaming.h>
- #include<Servo.h>
-
- #define __Debug 1
-
- const int pinServo = 6;
- const int angleServo = 60;
-
- #if __Debug
- #define DBG(X) Serial.println(X)
- #else
- #define DBG(X)
- #endif
-
- SoftwareSerial mySerial(A5, A4);
- Fingerprint finger = Fingerprint( & mySerial);
- Servo myservo;
-
- void open_close_door()
- {
- myservo.attach(pinServo);
- for (int i = 20; i < angleServo; i++)
- {
- myservo.write(i);
- delay(5);
- }
- delay(2000);
- for (int i = (angleServo - 1); i >= 20; i--)
- {
- myservo.write(i);
- delay(5);
- }
- myservo.detach();
- }
-
- void setup()
- {
- Serial.begin(38400);
- finger.begin(19200);
- delay(500);
- DBG("setup ok!");
- }
-
- void loop()
- {
- if (getFingerprintIDez() >= 0)
- {
- open_close_door();
- DBG("get right finger, open door now!!");
- delay(2000);
- }
- delay(50);
- }
-
- int getFingerprintIDez()
- {
- if (!finger.verifyPassword())
- {
- DBG("Did not find fingerprint sensor :(");
- return -1;
- }
- 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;
- }
- #if __Debug
- Serial.print("Found ID #");
- Serial.print(finger.fingerID);
- Serial.print(" with confidence of ");
- DBG(finger.confidence);
- #endif
-
- return finger.fingerID;
- }
Explanation:
- When the fingerprint is the same, the sensor identifies it and prints the message as matched.
- The servo motor also gets rotate to the 60-degree direction.
- When fingerprints do not match, a message is sent as "Not Matched."
Output:
Figure 2: Output.
Read more articles on Arduino: