How to make a button work if the fingerprint is matched only?

Friends,

I am new to Arduino and not from a programming background. I am working on a motorbike smart dashboard project for my degree. It includes security features like fingerprint and Real-time communication. I am using Arduino UNO, AS608 fingerprint sensor, relay, and some LEDs in the initial stage and further planning to connect it to the internet.

I am able to scan the fingerprints, control the relay using the buttons. I have two buttons one is a kill switch (on/off button) another one is a start switch (push button). Now I need to make the start button work if the fingerprint is matched only. If the fingerprint is matched start button can be used for 10 minutes then it should require a valid fingerprint again to use the button. Experts and experienced people, please help me.

#include <Adafruit_Fingerprint.h>


#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)

SoftwareSerial mySerial(2, 3);

const int Blue = 6;
const int Green = 7;
const int Red = 8;
const int PUSH_BUTTON_1 = 9;
const int PUSH_BUTTON_2 = 10;
const int RELAY_PIN_1 = 11;
const int RELAY_PIN_2 = 12;

int BUTTONstate1 = 0;
int BUTTONstate2 = 0;
int state = 0, relay2state=0;
volatile int finger_status = -1;

#else
// On Leonardo/M0/etc, others with hardware serial, use hardware serial!
// #0 is green wire, #1 is white
#define mySerial Serial1

#endif

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()
{
  Serial.begin(9600);
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println("\n\nAdafruit finger detect test");
  pinMode(6, OUTPUT); 
  pinMode(7, OUTPUT); 
  pinMode(8, OUTPUT);  
  pinMode(PUSH_BUTTON_1, INPUT_PULLUP); 
  pinMode(RELAY_PIN_1, OUTPUT);  digitalWrite(RELAY_PIN_1, HIGH);       
  pinMode(PUSH_BUTTON_2, INPUT_PULLUP); 
  pinMode(RELAY_PIN_2, OUTPUT);  digitalWrite(RELAY_PIN_2, HIGH);  

  
  finger.begin(57600);
  delay(5);
  if (finger.verifyPassword()) {
   Serial.println("Found fingerprint sensor!");
   }
   else
   {
    Serial.println("Did not find fingerprint sensor :(");
    while (1) { delay(1); }
  }

  Serial.println(F("Reading sensor parameters"));
  finger.getParameters();
  Serial.print(F("Status: 0x")); Serial.println(finger.status_reg, HEX);
  Serial.print(F("Sys ID: 0x")); Serial.println(finger.system_id, HEX);
  Serial.print(F("Capacity: ")); Serial.println(finger.capacity);
  Serial.print(F("Security level: ")); Serial.println(finger.security_level);
  Serial.print(F("Device address: ")); Serial.println(finger.device_addr, HEX);
  Serial.print(F("Packet len: ")); Serial.println(finger.packet_len);
  Serial.print(F("Baud rate: ")); Serial.println(finger.baud_rate);

  finger.getTemplateCount();

  if (finger.templateCount == 0) {
   Serial.print("Sensor doesn't contain any fingerprint data. Please run the 'enroll' example.");
  }
  else {
   Serial.println("Waiting for valid finger...");
   Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
  }
}

 void button() {
  BUTTONstate1 = digitalRead(PUSH_BUTTON_1); // read new state
  BUTTONstate2 = digitalRead(PUSH_BUTTON_2); // read new state
 
  if (BUTTONstate1 == HIGH) {
    digitalWrite(RELAY_PIN_1, HIGH);
  }
  else
  if (BUTTONstate1 == LOW) {
    digitalWrite(RELAY_PIN_1, LOW);
  }


  if (state == 0 && BUTTONstate2 == HIGH) {
    state = 1;
    relay2state=!relay2state;
  }
  if (state == 1 && BUTTONstate2 == LOW) {   
    state = 0;
  }
   digitalWrite(RELAY_PIN_2, relay2state);

}

void fp ()
{
  getFingerprintID();
  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.fingerSearch();
  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);
  return finger.fingerID;
}

// 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;
}

void loop()  {                   // run over and over again
button();
fp();
}

When the fingerprint is recognized, store the value of millis(). If the fingerprint is not recognized, set the stored value to zero. If the button is pressed and the stored value is not zero (bad fingerprint) and less than 10 minutes (600000UL milliseconds) ago, start the bike.

I am trying to code it but I am facing issues (I am very new to this). Could you help me with providing the code? :sob:

dhilipr:
I am trying to code it but I am facing issues (I am very new to this). Could you help me with providing the code? :sob:

No. I don't have a fingerprint reader to test with.

Find a library for your fingerprint reader. Use a library example to register fingerprints and check fingerprints against the registered ones. That will get you maybe 80% of the way to what you want.