#include #include // Define the pins for the fingerprint sensor #define mySerial Serial1 // Initialize the fingerprint sensor Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); // I2C address of the slave device const int I2C_SLAVE_ADDR = 0x08; void setup() { // Start serial communication for debugging Serial.begin(9600); // Start serial communication for the fingerprint sensor mySerial.begin(57600); finger.begin(57600); // Check if the fingerprint sensor is connected if (finger.verifyPassword()) { Serial.println("Found fingerprint sensor!"); } else { Serial.println("Did not find fingerprint sensor :("); while (1); } // Start I2C communication Wire.begin(); } void loop() { uint8_t p = finger.getImage(); switch (p) { case FINGERPRINT_OK: Serial.println("Image taken"); break; case FINGERPRINT_NOFINGER: Serial.println("No finger detected"); sendI2CData(0); return; case FINGERPRINT_PACKETRECIEVEERR: Serial.println("Communication error"); return; case FINGERPRINT_IMAGEFAIL: Serial.println("Imaging error"); return; default: Serial.println("Unknown error"); return; } // If the image is taken, convert it to a template p = finger.image2Tz(); switch (p) { case FINGERPRINT_OK: Serial.println("Image converted"); break; case FINGERPRINT_IMAGEMESS: Serial.println("Image too messy"); return; case FINGERPRINT_PACKETRECIEVEERR: Serial.println("Communication error"); return; case FINGERPRINT_FEATUREFAIL: Serial.println("Could not find fingerprint features"); return; case FINGERPRINT_INVALIDIMAGE: Serial.println("Could not find fingerprint features"); return; default: Serial.println("Unknown error"); return; } // Search for a matching fingerprint p = finger.fingerSearch(); if (p == FINGERPRINT_OK) { Serial.println("Fingerprint matched"); sendI2CData(1); delay(5000); // Send 1 if fingerprint matches } else if (p == FINGERPRINT_NOTFOUND) { Serial.println("Fingerprint not found"); sendI2CData(0); // Send 0 if fingerprint doesn't match } else { Serial.println("Communication error"); sendI2CData(0); } // Wait a bit before trying again delay(1000); } void sendI2CData(uint8_t data) { Wire.beginTransmission(I2C_SLAVE_ADDR); Wire.write(data); Wire.endTransmission(); }