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