I am using a capacitive touch sensor to turn on a fingerprint sensor ( GT-521F). I want the fingerprint sensor to be active for 5 seconds after the touch sensor is activated to give time to read the finger. Currently the code works if you are touching the touch sensor and when its released the fingerprint sensor also turns off. So basically everything after "if (buttonState == HIGH) {" would run for 5 seconds after the touch sensor turns high.
#include "FPS_GT511C3.h"
#include "SoftwareSerial.h"
FPS_GT511C3 fps(D5, D6);
const int TOUCH_BUTTON_PIN = D1; // Input pin for touch state
int buttonState = 0; // Capacitive Touch State
const int buzzerPin = D2; // Pin number for buzzer
const int Magnet = D7; // Pin number for magnet
void setup()
{
Serial.begin(9600);
delay(100);
fps.Open();
fps.SetLED(false); //turn on LED so fps can see fingerprint
pinMode(TOUCH_BUTTON_PIN, INPUT); // Configure button pin as input
pinMode(buzzerPin, OUTPUT); // Configure button pin as output
}
void loop()
{
buttonState = digitalRead(TOUCH_BUTTON_PIN); // If a touch is detected, turn on the LED
if (buttonState == HIGH) {
Serial.print("Touching");
fps.SetLED(true);
// Identify fingerprint test
if (fps.IsPressFinger())
{
fps.CaptureFinger(false);
int id = fps.Identify1_N();
if (id <200) //<- change id value depending model you are using
{//if the fingerprint matches, provide the matching template ID
Serial.print("Verified ID:");
Serial.println(id);
digitalWrite(Magnet, HIGH); // turn the magnet on
tone(buzzerPin, 262, 1000);
delay(5000); // wait for 5 seconds
digitalWrite(Magnet, LOW); // turn the magnet off
}
else
{//if unable to recognize
Serial.println("Finger not found");
}
}
else
{
Serial.println("Please press finger");
}
delay(100);
} else {
fps.SetLED(false);
}
}