Arduino UNO - Adafruit Fingerprint Sensor

Hello
I’m working on an integrated fingerprint sensor that would be able to give an access on a fingerprint match or deny access on False image.
Though I have found this code very useful, and it helped me to light an LED on true match. Thu, My question is how do I light another LED on unmatched fingerprint image.

[int getFingerprintIDez() {
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK)
  return -1;] // what does return -1 indicates here? 

// found a match! This can light up an LED at Pin 11 
  digitalWrite(12,LOW);
  digitalWrite(11,HIGH);
  delay(2000);
  digitalWrite(11,LOW);
  delay(500);
  digitalWrite(12,HIGH);
  Serial.println("ACCESS GRANTED"); 


But what if fingerprint is not matched and same it can light an LED at pin 10.

Access_on_Green.ino (2.2 KB)

  return -1;] // what does return -1 indicates here?

It is simply returning a value to the caller that says that there was no match.

Instead of turning on the LED there, you should be turning it on or off, based on the return code, where the function is called.

Here is the complete code.

[


#include <Adafruit_Fingerprint.h>
#if ARDUINO >= 100
 #include <SoftwareSerial.h>
#else
 #include <NewSoftSerial.h>
#endif

int getFingerprintIDez();

// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (WHITE wire)
#if ARDUINO >= 100
SoftwareSerial mySerial(2, 3);
#else
NewSoftSerial mySerial(2, 3);
#endif

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()  
{
  Serial.begin(9600);
  Serial.println("          Fingerprint Sensor");  
  Serial.println("");
  Serial.println("");
  
  pinMode(10,OUTPUT); 
  pinMode(11,OUTPUT);
  pinMode(12,OUTPUT);
  
  // set the data rate for the sensor serial port
  finger.begin(57600);
  
}

void loop()                     // run over and over again
{
  getFingerprintIDez();
  digitalWrite(12,HIGH);
}

// 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!
  digitalWrite(12,LOW);
  digitalWrite(11,HIGH);
  delay(2000);
  digitalWrite(11,LOW);
  delay(500);
  digitalWrite(12,HIGH);
  Serial.println("ACCESS GRANTED"); 

  return finger.fingerID; 
}]

Instead of returning -1 value to caller, i would turn on LED first. and then it should get back to function to scan again.
  getFingerprintIDez();

The function returns a value, telling you whether the fingerprint scanned was known, or not. You through that value away. Good going!

Perhaps you should save it, so you can determine which pin to turn on or off.

Thank you for helping.
Yet I'm not so good at programming.

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

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

Could it be possible when  (p != FINGERPRINT_OK) and instead of return -1 it turn on the LED. 
As in IF ElSE statement, if gives one value, else another.

Could it be possible when (p != FINGERPRINT_OK) and instead of return -1 it turn on the LED.

Possible, yes. Good design? Not even close. The function getFingerprintIDez() would need to be renamed to something like getFingerprintIDezAndTurnOneOneOfABunchOfLEDS(), which is clearly a dumb idea.

The function should do exactly what it is named, and nothing else. The function that calls that function should do something based on the return code.

Since what you want to do is a bad idea, I don't intend to help you do it.

Turning on an LED is just a beginning to understand the problem and to learn basics about programming, Later on i would add either an electronic lock or to send a warning message through GSM on false detection.
Im new to it, and I will need help from experienced person like you.

Turning on an LED is just a beginning to understand the problem and to learn basics about programming, Later on i would add either an electronic lock or to send a warning message through GSM on false detection.
Im new to it, and I will need help from experienced person like you.

Treat the function like digitalRead(). It returns a value. You do not consider putting more code in the digitalRead() function. You should not consider putting more code in your function.

Save the value that the function returns:

int rc = getFingerprintIDez();

Then. in loop(), decide what to do based on the value in rc.

I still could not do any progress. I don't have good knowledge about complicated programming.
Please help me to create a function, and i can use it here.

Please help me to create a function, and i can use it here.

A function to do what? What have you tried? What does your code look like now?

Attempting to get the return value, i save it and later i recall its value to use whether to give a digital ouput on some pins.

 printID = getFingerprintIDez();
  if(printID >= 0) 
    {
      Serial.println("matched");
      digitalWrite(11,HIGH);
      delay(500);
      digitalWrite(11,LOW);
      
    }
     
    else if (printID == -2)
    {
    // Bad scan
    digitalWrite(12,HIGH);
      }  // RED led!!!!
  
  else if(printID == -3) {
    // Invalid Finger!
    digitalWrite(10,HIGH);
    delay(500);
      digitalWrite(10,LOW); 
    Serial.println("unmatched");
       // LED 
  }

Did you make changes to the getFingerprintIDez() function? The one posted earlier had code in it that didn't belong in it. It returned either -1 (fingerprint not recognized) or 0 or more to indicate which fingerprint it found. It did not return -2 or -3.

The code you posted does something. You didn't say what it does. That differs, obviously, from what you want. You didn't say how.

Now, post ALL of your code.

#include <Adafruit_Fingerprint.h>
#if ARDUINO >= 100
 #include <SoftwareSerial.h>
#else
 #include <NewSoftSerial.h>
#endif

int getFingerprintIDez();
int printID = -1; // This will Return value i.e 0,-1,-2, -3

// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (WHITE wire)
#if ARDUINO >= 100
SoftwareSerial mySerial(2, 3);
#else
NewSoftSerial mySerial(2, 3);
#endif

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()  
{
  Serial.begin(9600);
  Serial.println("fingertest");
    
  pinMode(12, OUTPUT); // Yellow LED For Operation
  pinMode(11,OUTPUT); //  GREEN LED For Access Granted
  pinMode(10,OUTPUT); //  RED LED   For Access denied 
  
  
  
  // set the data rate for the sensor serial port
  finger.begin(57600);
  
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1);
  }
  Serial.println("Waiting for valid finger...");
}

void loop()                     // run over and over again
{
   printID = getFingerprintIDez();
   digitalWrite(12,HIGH); 
  if(printID >= 0) 
    {
    digitalWrite(12,LOW);
    digitalWrite(11,HIGH);
    delay(2000);
    digitalWrite(11,LOW);
    delay(500);
    digitalWrite(12,HIGH);
    Serial.println("ACCESS GRANTED"); 
      
    }
     
    else if (printID == -2)
    {
    Serial.println("Bad scan");
    digitalWrite(10,HIGH);
      }  
  
 
  else if(printID == -3) {
    // Invalid Finger!
    digitalWrite(10,HIGH);
    delay(500);
      digitalWrite(10,LOW); 
    Serial.println("Invalid Finger");
  }
}
 
uint8_t getFingerprintID() {
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println("No finger detected");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }
 
  // OK success!
 
  p = finger.image2Tz();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }
   
  // OK converted!
  p = finger.fingerFastSearch();
  if (p == FINGERPRINT_OK) {
    Serial.println("Found a print match!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
    Serial.println("Did not find a match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }   
   
  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID); 
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
   
 
}
 
// 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 -2;
 
  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK)  return -3;
   
  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID); 
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
  return finger.fingerID; 
}

Thank you for your help.
Now I would make it to perform an operation, if there is unmatched, it gives an error and send a text message.
Through Siemens TC35, Its easy to operate and using AT Commands.

But If you could suggest me any other module, or either a mobile that can operate with arudino.

Psst, you forgot something:

The code you posted does something. You didn't say what it does. That differs, obviously, from what you want. You didn't say how.

The above code, turn on an Green LED and print Access granted on serial monitor. While on false detection, it turns on red led, and print invalid finger.
Now instead of turning on an led, could it be possible to send a text message, with confidence number or fingerprint ID# if its matched. Or maybe send a warning message if the fingerprint is not matched.

Now instead of turning on an led, could it be possible to send a text message, with confidence number or fingerprint ID# if its matched. Or maybe send a warning message if the fingerprint is not matched.

Yes it would be possible.

Which Thank you for your help.
Now I would make it to perform an operation, if there is unmatched, it gives an error and send a text message.
Through Siemens TC35, Its easy to operate and using AT Commands.

But If you could suggest me any other module, or either a mobile that can operate with arudino.

please help :cry:
how to show the fingerprint data in storage into HEX, because I want to connect the fingerprint data to program c # / vb .. or is there another solution?
sorry my grammar is bad

thank you

how to show the fingerprint data in storage into HEX

http://arduino.cc/en/Serial/Print