SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By iamtheream
#164898
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!

Code: Select all
#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);
		}  
          
	}
User avatar
By Ross Robotics
#164901
How is the servo powered?
Have you tried different pins for the servo?

Since you say it's working, get rid of all the Serial.print statements. They are no longer of any use as they are meant primarily for debugging.
By Mee_n_Mac
#164902
I will opine that there's a conflict btw the servo library and the softserial library. When receiving data the serial code uses some timer or is interrupting the servo code trying to time it's PW every 20 msec. I'd bet it's a known issue, Google Arduino, softserial, servo, conflict and see if anything pops up.
By iamtheream
#164919
The servo is powered by the Arduino 5V. I tried powering it with a 9V and same Arduino ground on another rail on the bread board but then it would not work at all. I have not tried a different pin for the servo, but I will tonight. It has to be something with the serial readings of RX and TX, because the "twitch" the servo is making goes to the beat of the serial prints in the monitor. Just cannot figure it out.
User avatar
By Ross Robotics
#164927
You should never power the servo with the Arduino. That is the quickest way to damage an Arduino. You should be powering the servo with a separate supply.