# Activate Finger Print Sensor

**URL:** <https://forum.arduino.cc/t/activate-finger-print-sensor/1127015>\
**Category:** Programming\
**Created:** [May 15, 2023, 1:42am UTC](https://forum.arduino.cc/t/activate-finger-print-sensor/1127015 "2023-05-15T01:42:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cartracing21](https://avatars.discourse-cdn.com/v4/letter/c/c0e974/32.png) [@cartracing21](https://forum.arduino.cc/u/cartracing21)\
**Post date:** [May 15, 2023, 1:42am UTC](https://forum.arduino.cc/t/activate-finger-print-sensor/1127015/1 "2023-05-15T01:42:54Z")

</div>

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.

```arduino
#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);
  }
}

```

---

<div class="post-metadata">

**Author:** ![ToddL1962](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/toddl1962/32/225060_2.png) [@ToddL1962](https://forum.arduino.cc/u/ToddL1962)\
**Post date:** [May 15, 2023, 5:33pm UTC](https://forum.arduino.cc/t/activate-finger-print-sensor/1127015/2 "2023-05-15T17:33:55Z")

</div>

I would suggest state change detection for the button and use millis() for the 5 second timeout. I felt generous and coded for you but I am not at a place where I can compile and test. Here are references for state change detection and millis() timing.

[State Change Detection](https://forum.arduino.cc/index.php?topic=711767.msg4782013#msg4782013)  
[Example-code for timing based on millis()](https://forum.arduino.cc/t/example-code-for-timing-based-on-millis-easier-to-understand-through-the-use-of-example-numbers-avoiding-delay/974017)

```arduino
#include "FPS_GT511C3.h"
#include "SoftwareSerial.h"

FPS_GT511C3 fps(D5, D6);
const int TOUCH_BUTTON_PIN = D1; // Input pin for 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()
{
  static unsigned long prevFingerprintMs;
  static bool waitingForFingerprint = false;
  static int prevButtonState = LOW;

  int buttonState = digitalRead(TOUCH_BUTTON_PIN); // If a touch is detected, turn on the LED

  // Check for button press
  if (buttonState != prevButtonState)
  {
    if (buttonState == HIGH)
    {
      // Button has been pressed. Start 5 second timer, turn on LED, and indicate we are
      // waiting for a fingerprint.
      Serial.print("Touching");
      prevFingerprintMs = millis();
      fps.SetLED(true);
      waitingForFingerprint = true;
    }
    prevButtonState = buttonState;
  }

  if (waitingForFingerprint)
  {
    if (millis() - prevFingerprintMs < 5000)
    {
      // 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");
        }
        fps.SetLED(false);
        waitingForFingerprint = false;
      }
      else
      {
        Serial.println("Please press finger");
      }
      delay(100);
    }
    else
    {
      // Timed out waiting for fingerprint
      fps.SetLED(false);
      waitingForFingerprint = false;
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![cartracing21](https://avatars.discourse-cdn.com/v4/letter/c/c0e974/32.png) [@cartracing21](https://forum.arduino.cc/u/cartracing21)\
**Post date:** [May 16, 2023, 1:49am UTC](https://forum.arduino.cc/t/activate-finger-print-sensor/1127015/4 "2023-05-16T01:49:20Z")

</div>

Thank you both so much. I just tested it and it works perfectly. Thanks again!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [November 12, 2023, 1:49am UTC](https://forum.arduino.cc/t/activate-finger-print-sensor/1127015/5 "2023-11-12T01:49:31Z")

</div>

Closed on November 12, 2023, 1:49am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
