Using Arduino, Adafruit fingerprint and SD card as attendance system

Hi! I've been a programmer for more than 3 years and I'm very familiar on working with visual basic (VB.NET). Right now, I'am studying arduino together with adafruit fingerprint scanner and SD card.

My project is about getting the attendance via fingerprint and I will discuss below my step by step plan. Please correct me if there is something wrong on my process.

I've use the enroll fingerprint module example of adafruit (code attached below as Fingerprint Enroll Module.txt)

By using it I can simply get the id of the fingerprint by using this variable

id = readnumber();

Now I'am planning to add another 2 user inputs. So, instead of just getting the user input of id I will also have name and status whether they are professor or student, as additional user inputs.

then upon getting the 3 user input I will use the SD card module (code is attached below named as SD Card Readwrite Module.txt) to write the said information in a format below

id, name, status

Example of accounts.txt contents

1, Cary Bondoc, Professor
2, Juan dela Cruz, Student
3, Sample Name, Professor

Then by using Fingerprint Search Module (code attached named as Fingerprint Search Module.txt) I can get the id of the fingerprint of the user who presses his/her thumb to the fingerprint sensor.

The id that I get can be used to get the name and status in the accounts.txt, the text file where I write the accounts.

Upon getting the id, name, status of the user I will simply add the current datetime to log the current event in the new text file named attendance.txt

example below

1, Cary Bondoc, Professor, 09/12/18 13:30
1, Cary Bondoc, Professor, 09/12/18 13:33
2, Juan Dela Cruz, Student, 09/12/18 13:35
1, Cary Bondoc, Professor, 09/12/18 13:36
2, Juan Dela Cruz, Student, 09/12/18 13:36

Note that the datetime format is not important and the name for all the records of attendance should be put to the attendance.txt. So, overall in the SD card I have 2 textfiles named accounts.txt and attendance.txt

All the codes that I've attached above are just sketch provided by adafruit fingerprint and arduino. I'am still planning on how I will approach these kind of system and I would like to know your thoughts whether my path is correct?

Fingerprint Enroll Module.txt (5.81 KB)

Fingerprint Search Module.txt (4.17 KB)

SD Card Readwrite Module.txt (1.78 KB)

Until now, everything you've describe is quite achievable. Out together those bits of code into one orogram and have a go. When/if you run into problems, post what you've got and we'll take a look at it.

Welcome to the Forum!

Thank you so much! I'am so stuck in this part of my plan

Now I'am planning to add another 2 user inputs. So, instead of just getting the user input of id I will also have name and status whether they are professor or student, as additional user inputs.

then upon getting the 3 user input I will use the SD card module (code is attached below named as SD Card Readwrite Module.txt) to write the said information in a format below

Right now, I am able to get the ID of the fingerprint then after validating the fingerprint the arduino will wait for 10 seconds before getting the user input in the format like this name,Student or Professor. I am aiming for the simplest approach for the meantime.

Unfortunately, after getting the user input and checking the text file inside the sd card it will write in an unknown text format. In my experience it is usually the incorrect baud rate. and I suspect this part of my code

void setup()
{
  Serial.begin(9600);
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println("\n\nAdafruit Fingerprint sensor enrollment");

  Serial.print("Initializing SD card...");
  if (!SD.begin(4)) {
    Serial.print("initialization failed!");
    while (1);
  }
  Serial.print("initialization done.");


  // 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) {
      delay(1);
    }
  }
}

This is my code overall code:

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

SoftwareSerial mySerial(2, 3);



Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

uint8_t id;
String userName;
uint8_t isProfessor;
char *myFileName = "acct.txt";
File myFile;


void setup()
{
  Serial.begin(9600);
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println("\n\nAdafruit Fingerprint sensor enrollment");

  Serial.print("Initializing SD card...");
  if (!SD.begin(4)) {
    Serial.print("initialization failed!");
    while (1);
  }
  Serial.print("initialization done.");


  // 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) {
      delay(1);
    }
  }
}

uint8_t readnumber(void) {
  uint8_t num = 0;

  while (num == 0) {
    while (! Serial.available());
    num = Serial.parseInt();
  }
  return num;
}

void loop()                     // run over and over again
{
  Serial.println("Ready to enroll a fingerprint!");
  Serial.println("Please type in the ID # (from 1 to 127) you want to save this finger as...");
  id = readnumber();
  if (id == 0) {// ID #0 not allowed, try again!
    return;
  }
  Serial.print("Enrolling ID #");
  Serial.println(id);

  while (!getFingerprintEnroll() );
}

void writeReadSDCard(){
  
    delay(2000);
    // open the file. note that only one file can be open at a time,
    // so you have to close this one before opening another.
    myFile = SD.open(myFileName, FILE_WRITE);
    // if the file opened okay, write to it:
    if (myFile) { //if myFile is open, you can write
      Serial.print("Writing to "); Serial.println(myFileName);
      //myFile.print(id); myFile.print(","); myFile.print(userName); myFile.print(","); myFile.println("Professor");
      myFile.print(id); myFile.print(","); myFile.println(userName);
      // close the file:
      myFile.close();
      Serial.println("done.");
    } else {
      // if the file didn't open, print an error:
      Serial.print("error opening when writing on "); Serial.println(myFileName);
    }

    delay(2000);

    // re-open the file for reading:
    myFile = SD.open(myFileName);
    if (myFile) {
      Serial.print("Reading SD Card file named "); Serial.println(myFileName);

      // read from the file until there's nothing else in it:
      while (myFile.available()) {
        Serial.write(myFile.read());
      }
      // close the file:
      myFile.close();
      Serial.flush(); // wait for last transmitted data to be sent 
 
    } else {
      // if the file didn't open, print an error:
      Serial.println("error opening for reading");   Serial.print(myFileName);
    }
}



uint8_t getFingerprintEnroll() {

  int p = -1;
  Serial.print("Waiting for valid finger to enroll as #"); Serial.println(id);
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
      case FINGERPRINT_OK:
        Serial.println("Image taken");
        break;
      case FINGERPRINT_NOFINGER:
        Serial.println(".");
        break;
      case FINGERPRINT_PACKETRECIEVEERR:
        Serial.println("Communication error");
        break;
      case FINGERPRINT_IMAGEFAIL:
        Serial.println("Imaging error");
        break;
      default:
        Serial.println("Unknown error");
        break;
    }
  }

  // OK success!

  p = finger.image2Tz(1);
  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;
  }

  Serial.println("Remove finger");
  delay(2000);
  p = 0;
  while (p != FINGERPRINT_NOFINGER) {
    p = finger.getImage();
  }
  Serial.print("ID "); Serial.println(id);
  p = -1;
  Serial.println("Place same finger again");
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
      case FINGERPRINT_OK:
        Serial.println("Image taken");
        break;
      case FINGERPRINT_NOFINGER:
        Serial.print(".");
        break;
      case FINGERPRINT_PACKETRECIEVEERR:
        Serial.println("Communication error");
        break;
      case FINGERPRINT_IMAGEFAIL:
        Serial.println("Imaging error");
        break;
      default:
        Serial.println("Unknown error");
        break;
    }
  }

  // OK success!

  p = finger.image2Tz(2);
  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!
  Serial.print("Creating model for #");  Serial.println(id);

  p = finger.createModel();
  if (p == FINGERPRINT_OK) {
    Serial.println("Prints matched!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_ENROLLMISMATCH) {
    Serial.println("Fingerprints did not match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }


  Serial.print("ID "); Serial.println(id);
  p = finger.storeModel(id);
  if (p == FINGERPRINT_OK) {
    Serial.println("Stored!");

    delay(10000);
    
      userName = Serial.readString();// read the incoming data as string
      Serial.println(userName);

      writeReadSDCard();

        


  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_BADLOCATION) {
    Serial.println("Could not store in that location");
    return p;
  } else if (p == FINGERPRINT_FLASHERR) {
    Serial.println("Error writing to flash");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }
}

And this is the result:

Thank you so much for assisting me in my first arduino project