arduino mega 2560 : Adafruit Fingerprint Sensor

i am creating a project using fingerprint sensor.
i want to identify whose fingerprint is logging in.
can you please help me creating this project

_1_thesis.ino (461 Bytes)

Why are you using SoftwareSerial on a Mega with 4 hardware serial ports?

There is no reason to post the code as an attachment when it is so small.

#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>


SoftwareSerial mySerial(10, 11);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
int ID = 0;

void setup(void) {

  startFingerprintSensor();
  Serial.begin(9600);

  Serial.println("scan finger");
}

void loop() {
  ID = getFingerprintID();
  delay(100);
  if (ID == 10) {
    Serial.println("moks pogi");
  }
  if (ID == 11) {
    Serial.println("moks napaka pogi");
  }
  
 

}

What does this code actually do? What does it not do that you want it to do? What does it do that you do not want it to do?

What does this code actually do? What does it not do that you want it to do? What does it do that you do not want it to do?

if i scan my finger, the monitor will print my name. but this code have error and i cant figure what is that error. i read the and download the sample codes from adafruit and i summed up with this code. by i have missing something. i cant figure it out

this is the sample code from adafruit and i add some if function but it doesnt appear when im testing it.

#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>

int getFingerprintIDez();
int ID;


SoftwareSerial mySerial(10, 11);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);



void setup()  
{
  while (!Serial); 
  
  Serial.begin(9600);
  Serial.println("Adafruit finger detect test");

  // 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
{
  getFingerprintIDez();
  delay(50);            //don't ned to run this at full speed.
}

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!
 

 ID=finger.fingerID;
  
  Serial.print("Found ID #"); Serial.print(finger.fingerID); 
  Serial.print(" with confidence of "); Serial.println(finger.confidence); 



  if (ID == 14) {
    Serial.print("moks"); }
  if (ID == 11) {
    Serial.print("moks 2"); }



}

// 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!
  Serial.print("Found ID #"); Serial.print(finger.fingerID); 
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
  return finger.fingerID; 
}

this is the sample code from adafruit and i add some if function but it doesnt appear when im testing it.

What DOES appear?

Why are you using SoftwareSerial when the Mega has 4 hardware serial ports?

What DOES appear?

it only print the id number and the confidence rate.

Why are you using SoftwareSerial when the Mega has 4 hardware serial ports?

it said in the sample codes that if im using mega change the serial ports to 10 and 11... i've try enrolling enrolling some fingerprint and it works.

it only print the id number and the confidence rate.

Is that from the Serial.print() statements in getFingerprintIDez() or those in getFingerprintID()? Which function do you call? The one that actually cares about the value or the one that just prints the value?

i cant fully understand what are those function is all about... where can i see the function like getFingerprintID() and finger.fingerID that is used in the sample program from adafruit. is it in the library ? where are those function written?

where can i see the function like getFingerprintID()

It's in YOUR sketch.

and finger.fingerID

finger is an instance of the Adafruit_Fingerprint class, so you need to look at the Adafruit_Fingerprint.h and Adafruit_Fingerprint.cpp for details.