Fingerprint Lock Using Arduino Mega 2560

Introduction

 
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.
Connection:
 
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
  1. #include<Fingerprint.h>  
  2. #include<SoftwareSerial.h>  
  3. #include<Streaming.h>  
  4. #include<Servo.h>  
  5.   
  6. #define __Debug 1  
  7.   
  8. const int pinServo = 6;  
  9. const int angleServo = 60;  
  10.   
  11. #if __Debug  
  12. #define DBG(X) Serial.println(X)  
  13. #else  
  14. #define DBG(X)  
  15. #endif  
  16.   
  17. SoftwareSerial mySerial(A5, A4);  
  18. Fingerprint finger = Fingerprint( & mySerial);  
  19. Servo myservo;  
  20.   
  21. void open_close_door()   
  22. {  
  23.     myservo.attach(pinServo);  
  24.     for (int i = 20; i < angleServo; i++)   
  25.     {  
  26.         myservo.write(i);  
  27.         delay(5);  
  28.     }  
  29.     delay(2000);  
  30.     for (int i = (angleServo - 1); i >= 20; i--)  
  31.     {  
  32.         myservo.write(i);  
  33.         delay(5);  
  34.     }  
  35.     myservo.detach();  
  36. }  
  37.   
  38. void setup()   
  39. {  
  40.     Serial.begin(38400);  
  41.     finger.begin(19200);  
  42.     delay(500);  
  43.     DBG("setup ok!");  
  44. }  
  45.   
  46. void loop()   
  47. {  
  48.     if (getFingerprintIDez() >= 0)   
  49.     {  
  50.         open_close_door();  
  51.         DBG("get right finger, open door now!!");  
  52.         delay(2000);  
  53.     }  
  54.     delay(50);  
  55. }  
  56.   
  57. int getFingerprintIDez()   
  58. {  
  59.     if (!finger.verifyPassword())   
  60.     {  
  61.         DBG("Did not find fingerprint sensor :(");  
  62.         return -1;  
  63.     }  
  64.     uint8_t p = finger.getImage();  
  65.     if (p != FINGERPRINT_OK)   
  66.     {  
  67.         return -1;  
  68.     }  
  69.     p = finger.image2Tz();  
  70.     if (p != FINGERPRINT_OK)  
  71.     {  
  72.         return -1;  
  73.     }  
  74.     p = finger.fingerFastSearch();  
  75.     if (p != FINGERPRINT_OK)   
  76.     {  
  77.         return -1;  
  78.     }  
  79.     #if __Debug  
  80.         Serial.print("Found ID #");  
  81.         Serial.print(finger.fingerID);  
  82.         Serial.print(" with confidence of ");  
  83.         DBG(finger.confidence);  
  84.     #endif  
  85.       
  86.     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:


Recommended Ebook

Printing in C# Made Easy

Download Now!
Similar Articles