In Focus

Fingerprint Lock Using Arduino Mega 2560

In this article I will explain about 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 capture the digital images.
  • The captured image is called live scan. 
  • It simply identifies the fingerprint and give 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 fingerprint sensor to the Gnd of the Arduino Mega 2560
  • The Vcc pin of  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                               // if debug mode  
  7.   
  8. const int pinServo      = 6;                            // servo pin  
  9. const int angleServo    = 60;                           // Rotation angle  
  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);                                // tx, rx  
  18.   
  19. Fingerprint finger = Fingerprint(&mySerial);  
  20. Servo myservo;                                                  // create servo object to control a servo  
  21.   
  22. void open_close_door()  
  23. {  
  24.     myservo.attach(pinServo);  
  25.     for(int i=20; i<angleServo; i++)  
  26.     {  
  27.         myservo.write(i);  
  28.         delay(5);  
  29.     }  
  30.   
  31.     delay(2000);  
  32.   
  33.     for(int i=(angleServo-1); i>=20; i--)  
  34.     {  
  35.         myservo.write(i);  
  36.         delay(5);  
  37.     }  
  38.     myservo.detach();  
  39.   
  40.   
  41. }  
  42.   
  43.   
  44. void setup()  
  45. {  
  46.   
  47.     Serial.begin(38400);  
  48.     finger.begin(19200);  
  49.     delay(500);  
  50.     DBG("setup ok!");  
  51. }  
  52.   
  53. void loop()                     // run over and over again  
  54. {  
  55.     if(getFingerprintIDez()>=0)  
  56.     {  
  57.         open_close_door();  
  58.         DBG("get right finger, open door now!!");  
  59.           
  60.         delay(2000);  
  61.     }  
  62.     delay(50);  
  63. }  
  64.   
  65.   
  66. // returns -1 if failed, otherwise returns ID #  
  67. int getFingerprintIDez()  
  68. {  
  69.   
  70.     if (!finger.verifyPassword())  
  71.     {  
  72.         DBG("Did not find fingerprint sensor :(");  
  73.         return -1;  
  74.     }  
  75.   
  76.     uint8_t p = finger.getImage();  
  77.     if (p != FINGERPRINT_OK)  
  78.     {  
  79.         return -1;  
  80.     }  
  81.   
  82.     p = finger.image2Tz();  
  83.     if (p != FINGERPRINT_OK)  
  84.     {  
  85.         return -1;  
  86.     }  
  87.   
  88.     p = finger.fingerFastSearch();  
  89.     if (p != FINGERPRINT_OK)  
  90.     {  
  91.         return -1;  
  92.     }  
  93.   
  94. #if __Debug  
  95.     Serial.print("Found ID #");  
  96.     Serial.print(finger.fingerID);  
  97.     Serial.print(" with confidence of ");  
  98.     DBG(finger.confidence);  
  99. #endif  
  100.   
  101.     return finger.fingerID;  
  102.   
  103. }  
Explanation:
  • When the fingerprint isthe  same, the sensor identifies it and prints the message as matched.
  • The servo motor also gets rotate to 60 degree direction.
  • When fingerprints do not match, a message is sent as "Not Matched."
 
Output:


                          Figure 2: Output.

Read more articles on Arduino: