#include <Adafruit_Fingerprint.
h>
#define LED_PIN 13 // Define the digital LED pin
SoftwareSerial mySerial(2, 3); // RX, TX for fingerprint module
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
void setup() {
pinMode(LED_PIN, OUTPUT); // Set the LED pin as an output
finger.begin(57600);
if (finger.verifyPassword()) {
Serial.println("Fingerprint module connected");
} else {
Serial.println("Fingerprint module error");
while (1); // Halt if module connection fails
}
}
void loop() {
if (verifyFingerprint()) {
digitalWrite(LED_PIN, HIGH); // Turn on the LED
delay(2000); // LED on for 2 seconds
digitalWrite(LED_PIN, LOW); // Turn off the LED
delay(1000); // Delay before next verification
}
}
bool verifyFingerprint() {
uint8_t id = finger.getImage();
if (id != FINGERPRINT_OK) {
return false; // No fingerprint detected
}
id = finger.image2Tz();
if (id != FINGERPRINT_OK) {
return false; // Image conversion failed
}
id = finger.fingerFastSearch();
if (id == FINGERPRINT_OK) {
finger.fingerFastSearch(); // Search again for multiple verifications
return true; // Fingerprint verified
} else {
return false; // Verification failed
}
}