Untitled
unknown
plain_text
5 months ago
1.9 kB
4
Indexable
#include <Adafruit_Fingerprint.h> #include <Servo.h> // Define connections for fingerprint sensor #define rxPin 2 // Connect TX from sensor to pin 2 #define txPin 3 // Connect RX from sensor to pin 3 Adafruit_Fingerprint finger(&Serial1); // Use Serial1 for communication Servo myServo; // Initial position for the servo int servoOpenPos = 180; int servoClosedPos = 0; void setup() { // Initialize serial communication Serial.begin(9600); while (!Serial) delay(10); // Wait for Serial monitor to open Serial.println("Initializing Fingerprint Sensor..."); // Initialize fingerprint sensor finger.begin(57600); if (finger.verifyPassword()) { Serial.println("Fingerprint sensor initialized successfully!"); } else { Serial.println("Failed to initialize fingerprint sensor. Please check connections."); while (1); } // Attach the servo motor myServo.attach(9); // Connect the servo to pin 9 myServo.write(servoClosedPos); // Start with servo closed Serial.println("Servo initialized."); } void loop() { Serial.println("Place your finger on the sensor..."); // Wait for a fingerprint if (getFingerprintID() == 1) { Serial.println("Fingerprint verified!"); // Move servo to open position myServo.write(servoOpenPos); delay(3000); // Keep it open for 3 seconds // Move servo back to closed position myServo.write(servoClosedPos); } else { Serial.println("Fingerprint not recognized. Try again."); } delay(1000); // Small delay between attempts } // Function to get fingerprint ID int getFingerprintID() { int result = finger.getImage(); if (result != FINGERPRINT_OK) return -1; result = finger.image2Tz(); if (result != FINGERPRINT_OK) return -1; result = finger.fingerFastSearch(); if (result != FINGERPRINT_OK) return -1; return finger.fingerID; }
Editor is loading...
Leave a Comment