0% found this document useful (0 votes)
12 views3 pages

Door Fingerprint Code

Uploaded by

derricknanyiru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

Door Fingerprint Code

Uploaded by

derricknanyiru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <Adafruit_Fingerprint.

h>

#include <Servo.h> // For servo motor control (optional)

SoftwareSerial mySerial(2, 3); // RX, TX for fingerprint sensor

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

#define LOCK_PIN 7 // Pin connected to the relay or servo controlling the


lock

void setup() {

Serial.begin(9600);

pinMode(LOCK_PIN, OUTPUT);

digitalWrite(LOCK_PIN, LOW); // Lock is engaged initially

finger.begin(57600);

if (finger.verifyPassword()) {

Serial.println("Fingerprint sensor found!");

} else {

Serial.println("Fingerprint sensor not detected. Please check wiring.");

while (1);

Serial.println("Ready to enroll fingerprints.");

enrollFingerprint(); // Run enrollment once to save fingerprint(s)

void loop() {

int fingerprintID = getFingerprintID();

if (fingerprintID != -1) {

Serial.println("Fingerprint recognized!");
unlockDoor();

delay(5000); // Door remains unlocked for 5 seconds

lockDoor();

delay(1000);

void enrollFingerprint() {

int id = 1; // ID number to assign to the fingerprint

Serial.print("Enrolling ID #"); Serial.println(id);

while (finger.getImage() != FINGERPRINT_OK);

if (finger.image2Tz(1) != FINGERPRINT_OK) return;

Serial.println("Remove finger");

delay(2000);

while (finger.getImage() != FINGERPRINT_NOFINGER);

Serial.println("Place same finger again");

while (finger.getImage() != FINGERPRINT_OK);

if (finger.image2Tz(2) != FINGERPRINT_OK) return;

if (finger.createModel() != FINGERPRINT_OK) return;

if (finger.storeModel(id) == FINGERPRINT_OK) {

Serial.println("Fingerprint enrolled successfully!");

} else {

Serial.println("Enrollment failed");

}
int getFingerprintID() {

if (finger.getImage() != FINGERPRINT_OK) return -1;

if (finger.image2Tz() != FINGERPRINT_OK) return -1;

if (finger.fingerSearch() != FINGERPRINT_OK) return -1;

return finger.fingerID;

void unlockDoor() {

Serial.println("Unlocking door...");

digitalWrite(LOCK_PIN, HIGH); // Activates the relay to unlock the door

void lockDoor() {

Serial.println("Locking door...");

digitalWrite(LOCK_PIN, LOW); // Deactivates the relay to lock the door

You might also like