Hello all,
I am working on a project with a fingerprint scanner to move a dc motor. But when I try to identify a fingerprint in the loop function, it doesn't loop. I tested it with println("loop") command to see if it's actually not looping and the line showed once. Please help, what could be the problem?
#include "FPS_GT511C3.h"
#include "SoftwareSerial.h"
// set up software serial pins for Arduino's w/ Atmega328P's
// FPS (TX) is connected to pin 4 (Arduino's Software RX)
// FPS (RX) is connected through a converter to pin 5 (Arduino's Software TX)
FPS_GT511C3 fps(4, 5); // (Arduino SS_RX = pin 4, Arduino SS_TX = pin 5),
//H-Bridge pins to control the motor
#define IN1 6
#define IN2 7
void setup()
{
Serial.begin(9600); //set up Arduino's hardware serial UART
pinMode (IN1, OUTPUT);
pinMode (IN2, OUTPUT);
delay(100);
fps.Open();
fps.SetLED(true);
//Enroll(); //begin enrolling fingerprint
Serial.println("setup");
}
void loop()
{
Identify();
delay(5000);
Serial.println("loop");
}
void Identify()
{
fps.SetLED(true);
waitForFinger();
// Identify fingerprint test
if (fps.IsPressFinger())
{
fps.CaptureFinger(false);
int id = fps.Identify1_N();
if (id <20) //<- change id value depending model you are using
{//if the fingerprint matches, provide the matching template ID
Serial.print("Verified ID:");
Serial.println(id);
//turning the motor counterclockwise
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
delay(5000);
//stop
digitalWrite(IN1,HIGH);
delay(1000);
//turning the motor clockwise
digitalWrite(IN2,LOW);
delay(5000);
//stop
digitalWrite(IN1,LOW);
delay(1000);
}
else
{//if unable to recognize
Serial.println("Finger not found");
}
}
else
{
Serial.println("Please press finger");
}
delay(100);
}
void Enroll()
{
// Enroll test
// find open enroll id
int enrollid = 0;
bool usedid = true;
while (usedid == true)
{
usedid = fps.CheckEnrolled(enrollid);
if (usedid==true) enrollid++;
}
fps.EnrollStart(enrollid);
// enroll
Serial.print("Press finger to Enroll #");
Serial.println(enrollid);
while(fps.IsPressFinger() == false) delay(100);
bool bret = fps.CaptureFinger(true);
int iret = 0;
if (bret != false)
{
Serial.println("Remove finger");
fps.Enroll1();
while(fps.IsPressFinger() == true) delay(100);
Serial.println("Press same finger again");
while(fps.IsPressFinger() == false) delay(100);
bret = fps.CaptureFinger(true);
if (bret != false)
{
Serial.println("Remove finger");
fps.Enroll2();
while(fps.IsPressFinger() == true) delay(100);
Serial.println("Press same finger yet again");
while(fps.IsPressFinger() == false) delay(100);
bret = fps.CaptureFinger(true);
if (bret != false)
{
Serial.println("Remove finger");
iret = fps.Enroll3();
if (iret == 0)
{
Serial.println("Enrolling Successful");
}
else
{
Serial.print("Enrolling Failed with error code:");
Serial.println(iret);
}
}
else Serial.println("Failed to capture third finger");
}
else Serial.println("Failed to capture second finger");
}
else Serial.println("Failed to capture first finger");
}
void waitForFinger(){
static int timer; //contains timeout counter
timer = 0; //resets the timer everytime this function starts
while(!fps.IsPressFinger()){ //timeout of eight seconds
timer++;
delay(100);
if (timer>=80 && !fps.IsPressFinger()){
fps.SetLED(false);
}
}
timer = 0; //resets the timer everytime this function ends
}