Detect Invalid Fingerprint via Adafruit Fingerprint

Hi all,

I have the Adafruit fingerprint scanner and I’m using the adafruit fingerprint library.

I can get the fingerprint to execute the code I want when a valid finger is placed on the scanner, however, I want to implement code that is run if an invalid finger (not in the database) is detected.

So basically I want to have it so valid fingers run one thing, but ANY invalid/non stored finger runs a different code. Rather than just staying red if an invalid finger is on the sensor.

I have searched far and wide and found no conclusive way to do this.

Is anyone able to provide some assistance?

Show your code. At some point you made an if condition check once it is activated. Just use an else after.

if(fingerprintIsValid()){
  doSomething();
} else {
  doSomethingElse();
}

Thanks for the replies. I've tried this but it doesn't seem that simple. The code is a little bit complicated for me to understand so I've included it below.

This function is executed in the main loop (constantly checking for finger). This is from an example in the Adafruit fingerprint sensor library that I've just modified to run my own function when the fingerprint is correct.

As you can see, it executes the function "securityOFF();" when there is a valid finger present and matched in the fingerprint sensor database.

However, simply adding an "else" statement does not give the behaviour I'm looking for. Instead, nothing happens, unless the finger is valid.

Again, I want it to run alternate code for any invalid finger presented.

// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK)  return -1;

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

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

  // found a match!
  if (security == 1) {
    securityOFF();
    Serial.print("Found ID #"); Serial.print(finger.fingerID);
    Serial.print(" with confidence of "); Serial.println(finger.confidence);
    Serial.println();
  }

  else{
    fpsled[0] = CRGB::Orange;
    FastLED.show();
  }
  return finger.fingerID;
}

Any further insight would be greatly appreciated.

It may be better to get at the code which calls getFingerprintIDez() but based on what you supplied, this, although not very elegant, may work :

// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {

  bool proceed = true ;  // assume good

  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK )  proceed = false ;

  if ( proceed ) {
    p = finger.image2Tz();
    if (p != FINGERPRINT_OK )  proceed = false ;
  }

  if ( proceed ) {
    p = finger.fingerFastSearch();
    if (p != FINGERPRINT_OK)  proceed = false ;
  }


  if ( proceed == false ) {
    Serial.println("bad match" );
    //
    // Any other code you wish to write here
    //
    return -1 ;
  }




  // found a match!
  if (security == 1) {
    securityOFF();
    Serial.print("Found ID #"); Serial.print(finger.fingerID);
    Serial.print(" with confidence of "); Serial.println(finger.confidence);
    Serial.println();
  }

  else {
    fpsled[0] = CRGB::Orange;
    FastLED.show();
  }
  return finger.fingerID;
}

I wrote a whole tutorial about this: Arduino Optical Fingerprint Sensor.

For your issue, it sounds like you need to look at the fingerprint module status output. It typically (for Adafruit’s library) has 3 output parameters. One for detecting fingers, one for determining if it’s a valid fingerprint, and one determining if the fingerprint matches any in the database. Therefore, look at using if() and else() for those parameters. I outline it in the tutorial, but the snippet you want goes as follows:

finger_status = getFingerprintIDez();
  if (finger_status!=-1 and finger_status!=-2){
    digitalWrite(led_pin_accept,HIGH);
    delay(1000);
  } else{
    if (finger_status==-2){
      for (int ii=0;ii<5;ii++){
        digitalWrite(led_pin_deny,HIGH);
        delay(50);
        digitalWrite(led_pin_deny,LOW);
        delay(50);
      }
    }
    digitalWrite(led_pin_accept,LOW);
  }