Reputation: 1
I've been working with Adafruit's RFID 8-wire fingerprint sensor to enroll and process fingerprints in a specific order. My goal is to take the most recent three fingerprints enrolled and use them, in the order they were added, to trigger a servo motor to rotate 90 degrees upon successful completion. However, I'm running into an issue where the sensor does not consistently recognize the fingerprints in the expected order, causing problems in the authentication process. This has made it difficult to ensure that the servo motor only activates when the correct sequence of fingerprints is detected. One of the main issues I encountered is that when I try to store the three most recent fingerprint IDs in a list, the sensor only processes two of them instead of all three. This happens even though all three fingerprints were successfully enrolled in the system. The program should recognize each fingerprint in sequence, but instead, it either skips an entry or fails to process the stored data correctly. This inconsistency has led to a frustrating debugging process as I try to pinpoint the exact cause of the problem. To work around this issue, I attempted to modify the system by allowing it to take four fingerprint inputs instead of three. Strangely, this adjustment allows the sensor to process three fingerprints correctly, but it is not an ideal solution since I don't fully understand why the issue arises in the first place. Ideally, the system should function correctly with just three fingerprint inputs without requiring an extra placeholder entry. The problem suggests that there may be an underlying issue with how the fingerprint IDs are stored, accessed, or compared in the code. At this point, I'm looking for any insight into what I might be missing in my implementation. Could there be a limitation in how the fingerprint sensor handles ID storage, or is there a flaw in how I'm structuring my list? I’ve checked my code multiple times, but the inconsistency in how the fingerprints are recognized has made troubleshooting difficult. If anyone has experience with this sensor or has encountered a similar issue, I would really appreciate any advice on how to resolve this.
#include <Adafruit_Fingerprint.h>
#include <Servo.h> // Include the Servo library
#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)
// For UNO and others without hardware serial, we must use software serial...
SoftwareSerial mySerial(2, 3); // pin #2 is IN from sensor (GREEN wire), #3 is OUT to sensor (WHITE wire)
#else
#define mySerial Serial1
#endif
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
Servo myServo; // Create a Servo object
// Array to store fingerprint IDs
uint8_t fingerprintList[4] = {0}; // Store up to 4 fingerprints
uint8_t currentIndex = 0; // Variable to track the current position in the array
void setup() {
Serial.begin(9600);
while (!Serial);
delay(100);
Serial.println("\n\nAdafruit Fingerprint Sensor Test");
// Initialize the fingerprint sensor
finger.begin(57600);
delay(5);
if (finger.verifyPassword()) {
Serial.println("Found fingerprint sensor!");
} else {
Serial.println("Did not find fingerprint sensor :(");
while (1) { delay(1); }
}
// Get sensor details
finger.getParameters();
finger.getTemplateCount();
if (finger.templateCount == 0) {
Serial.println("No fingerprints stored. Please enroll fingerprints.");
} else {
Serial.print("Sensor contains "); Serial.print(finger.templateCount);
Serial.println(" templates");
}
// Initialize the servo motor
myServo.attach(9); // Attach the servo to pin 9
myServo.write(0); // Set the initial position of the servo
}
void loop() {
int fingerprintID = getFingerprintID();
// If a fingerprint is detected, process it
if (fingerprintID != -1) {
// Check if the fingerprint is already stored
bool isDuplicate = false;
for (uint8_t i = 0; i < currentIndex; i++) {
if (fingerprintList[i] == fingerprintID) {
isDuplicate = true;
break;
}
}
// If it's not a duplicate, add it to the array
if (!isDuplicate) {
fingerprintList[currentIndex] = fingerprintID;
currentIndex++;
Serial.print("Fingerprint ID "); Serial.print(fingerprintID); Serial.println(" stored.");
}
// Check if stored fingerprints are in increasing order
bool inOrder = true;
for (uint8_t i = 0; i < currentIndex - 1; i++) {
if (fingerprintList[i] > fingerprintList[i + 1]) {
inOrder = false;
break;
}
}
if (!inOrder) {
Serial.println("Fingerprints are out of order. Resetting...");
clearFingerprintList();
}
// If we have 4 unique fingerprints in order, unlock the servo
if (currentIndex == 4 && inOrder) {
Serial.println("Unlocking...");
myServo.write(90); // Rotate the servo to 90 degrees
delay(1000); // Wait for 1 second
myServo.write(0); // Return the servo to its initial position
// Reset the array and index for new fingerprints
clearFingerprintList();
}
}
delay(50); // Delay between fingerprint checks
}
uint8_t getFingerprintID() {
uint8_t p = finger.getImage();
if (p != FINGERPRINT_OK) return -1;
p = finger.image2Tz();
if (p != FINGERPRINT_OK) return -1;
p = finger.fingerSearch();
if (p != FINGERPRINT_OK) return -1;
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
return finger.fingerID;
}
void clearFingerprintList() {
Serial.println("Clearing stored fingerprints...");
for (uint8_t i = 0; i < 4; i++) {
fingerprintList[i] = 0; // Clear the array
}
currentIndex = 0; // Reset the index
}
void reset() {
myServo.write(0); // Reset to initial position
}
Upvotes: 0
Views: 11