The code is posted below ( based on code from - https://github.com/sparkfun/Fingerprint_Scanner-TTL ), I’m trying to get the finger print I stored on the device to open a servo. The FPS scanner ( https://www.sparkfun.com/products/11792 ) is reading the prints perfectly. Hooked in to the Uno’s RX and TX pins to communicate through the serial.
The problem lies in the servo. It is turning the full 90 degrees and back to 0 degrees when my finger is id’ed, but glitches when it is non-active or not called in the code. I’ve done a lot of trouble shooting and the hardware is fine (tried a simple sweep sketch). By putting delay(2000)'s in I found where the problem is but cannot fix it. Every time serial is communicating the the TX pin on the FPS to check for a print, the servo twitches.
Any insight into why this is happening or a possible solution would be awesome. Thanks guys!
#include "LIB_GT511C3.h"
#include "SoftwareSerial.h"
#include <Servo.h>
#define SERVO_PIN 9 // sets servo to pin 9
int count = 0; // current display count
int pos = 0; // variable to store the servo position
int nonactiveLED = 13;
int readingLED = 12;
int idLED = 11;
int deniedLED = 10;
// Hardware setup - FPS connected to:
// digital pin 4(arduino rx, fps tx)
// digital pin 5(arduino tx - 560ohm resistor - fps tx - 1000ohm resistor - ground)
// this voltage divider brings the 5v tx line down to about 3.2v so we dont fry our fps
FPS_GT511C3 fps(4, 5);
Servo myservo; // create servo object to control the lock
void setup()
{
Serial.begin(9600);
delay(100);
fps.Open();
fps.SetLED(true);
myservo.attach(SERVO_PIN); // attaches the servo to pin 9
pinMode(nonactiveLED, OUTPUT);
pinMode(readingLED, OUTPUT);
pinMode(idLED, OUTPUT);
pinMode(deniedLED, OUTPUT);
}
void loop()
{
digitalWrite(nonactiveLED, HIGH);
// Identify fingerprint test
if (fps.IsPressFinger())
{
count++;
}
{
delay(50);
switch (count) {
case 0:
openDoor();
Serial.print("Door Is Open");
break;
case 1:
closeDoor();
Serial.print("Door Is Closer");
break;
case 2:
openDoor();
Serial.print("Door Is Open");
break;
case 3:
closeDoor();
Serial.print("Door Is Closer");
break;
case 4:
openDoor();
Serial.print("Door Is Open");
count = 0;
break;
}
}
}
void openDoor()
{
fps.CaptureFinger(false);
int id = fps.Identify1_N();
if (id <200)
{
digitalWrite(nonactiveLED, LOW);
delay(50);
digitalWrite(readingLED, HIGH);
delay(50);
digitalWrite(readingLED, LOW);
Serial.print("Verified ID:");
Serial.println(id);
myservo.write(0); // tell servo to go to 0 degrees
digitalWrite(idLED, HIGH);
delay(2000);
digitalWrite(idLED, LOW);
digitalWrite(nonactiveLED, HIGH);
}
else
{
Serial.println("Finger not found");
digitalWrite(deniedLED, HIGH);
delay(2000);
digitalWrite(deniedLED, LOW);
}
}
void closeDoor()
{
fps.CaptureFinger(false);
int id = fps.Identify1_N();
if (id <200)
{
digitalWrite(nonactiveLED, LOW);
delay(50);
digitalWrite(readingLED, HIGH);
delay(50);
digitalWrite(readingLED, LOW);
Serial.print("Verified ID:");
Serial.println(id);
myservo.write(90); // tell servo to go to 90 degrees
digitalWrite(idLED, HIGH);
delay(2000);
digitalWrite(idLED, LOW);
digitalWrite(nonactiveLED, HIGH);
}
else
{
Serial.println("Finger not found");
digitalWrite(deniedLED, HIGH);
delay(2000);
digitalWrite(deniedLED, LOW);
}
}