top of page

Fingerprint Alarm: Using an Adafruit finger print sensor with Arduino

  • Writer: Miles Lee
    Miles Lee
  • Jan 25, 2017
  • 3 min read

Don't need a key? All I need is my finger? That's awesome.

1. Bought fingerprint sensor form Adafruit (Adafruit.com) and learned from their tutorial how to use the sample code and library they supplied to make cool things happen.

2. Decided to write program myself. Scanned a fingerprint that runs the print through a small photographic database in Arduino, then outputs if the print is found or not. If the fingerprint is found in the database, then green LED blinks and the identity that the fingerprint correlates to in the database is shown in the serial console. But if the fingerprint is not found, then red LED blinks and an alarm goes off for about two seconds.

3. Made it fancier. Added a button on the device that allows the person to override the program and have the green LED show just incase the sensor malfunctioned. This would be useful when I put an electronic lock on the device.

More Information:

- Arduino

- Editor Application: Arduino

- If you want to do a project like this you need to download a library from Adafruit and should watch their tutorial for help.

Here it is:

/*

NOTE TO SELF:

- Pin #2 is IN from sensor (GREEN wire)

- Pin #3 is OUT from arduino (WHITE wire)

- HELPFUL WEB SITES:

-http://www.grantgibson.co.uk/2013/09/biometric-security-toy-box/

-http://sites.lwhs.org/devices/heidi-peterson-fingerprint-lock-box/

-http://www.instructables.com/id/DIY-Fingerprint-Scanning-Garage-Door-Opener/?ALLSTEPS

- After LCD screen works turn all the Serial.print messages

into notes(//) so it can prosses faster.

*/

#include <Servo.h>

#include <Adafruit_Fingerprint.h>

#if ARDUINO >= 100

#include <SoftwareSerial.h>

#include <NewSoftSerial.h>

#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

int getFingerprintIDez();

Servo myservo;

//int mytimer = 0; // A timer that is incremented each loop. Turns off device after inactivity.

//int logicSwitch = 13;

int speakerOut = A0;

int printID = -1; // Variable to store the current finger print identified (indexed from zero)

int unlockButton = 1;

int Red = 5;

int Green = 6;

#if ARDUINO >= 100

SoftwareSerial mySerial(2, 3);

NewSoftSerial mySerial(2, 3);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

////////////////////////////////////////////////////////////////////////////////////////

void setup()

{

lcd.begin(20, 4);

Serial.begin(9600);

Serial.println("fingertest");

Serial.println("HI");

Serial.println("Porperty of Miles");

lcd.println("HI");

lcd.println("Property of Miles");

pinMode(Red, OUTPUT);

pinMode(Green, OUTPUT);

myservo.attach(4);

myservo.write(0); // Only at the start

pinMode(speakerOut, OUTPUT);

pinMode(unlockButton, INPUT_PULLUP);

// pinMode(logicSwitch, INPUT); // Logic control of the power switch

// digitalWrite(logicSwitch, LOW); // Set Low for power on, High to power off

finger.begin(57600);

if (finger.verifyPassword()) {

Serial.println("Found fingerprint sensor!");

} else {

Serial.println("Did not find fingerprint sensor :(");

while (1);

}

Serial.println("Waiting for valid finger...");

delay(50);

myservo.detach(); // Detach the servo to save wear & power

}

/////////////////////////////////////////////////////////////

void loop()

{

if(digitalRead(unlockButton) == LOW)

{

Serial.println("unlock");

myservo.attach(4);

myservo.write(180);

delay(500);

myservo.detach();

lcd.clear();

lcd.print("Unlock");

delay(1000);

}

printID = getFingerprintIDez();

digitalWrite(Red, HIGH);

if(printID >= 0)

{

Serial.println("good");

// Valid fingerprint

digitalWrite(Red, LOW);

digitalWrite(Green, HIGH);

delay(400); // Wait

digitalWrite(Green, LOW);

delay(10); // Wait

digitalWrite(Red, HIGH);

myservo.attach(4);

myservo.write(180);

delay(500);

myservo.detach();

// mytimer = 0; // Reset the timer, device still in use

}

else if (printID == -2) {

// Bad scan

Serial.println("oops");

delay(50);

Serial.println("Image Error");

delay(50);

Serial.println("Please try again");

delay(50);

digitalWrite(speakerOut,100); // BUZZ!!!!

delay(500);

digitalWrite(speakerOut,0);

lcd.clear();

lcd.println("Oops");

delay(50);

lcd.println("Image Error");

delay(50);

lcd.println("Try Again");

delay(1000);

}

else if(printID == -3) {

// Invalid Finger!

digitalWrite(speakerOut,200); // Different buzz

delay(500);

digitalWrite(speakerOut,0);

Serial.println("no");

delay(50);

Serial.println("Access Denied");

delay(50);

lcd.clear();

lcd.println("NO");

delay(50);

lcd.println("Access Denied");

delay(1000);

}

/*

delay(100);

if(mytimer >= 100)

{

digitalWrite(logicSwitch, HIGH); // Device has been idle for 100 loops, turn off by setting the Pololu switch high

Serial.println("Power down");

}

else

{

mytimer++;

}

*/

}

//////////////////////////////////////////////////////////////////////////////

uint8_t getFingerprintID() {

uint8_t p = finger.getImage();

switch (p) {

case FINGERPRINT_OK:

Serial.println("Image taken");

break;

case FINGERPRINT_NOFINGER:

Serial.println("No finger detected");

return p;

case FINGERPRINT_PACKETRECIEVEERR:

Serial.println("Communication error");

return p;

case FINGERPRINT_IMAGEFAIL:

Serial.println("Imaging error");

return p;

default:

Serial.println("Unknown error");

return p;

}

// OK success!

p = finger.image2Tz();

switch (p) {

case FINGERPRINT_OK:

Serial.println("Image converted");

break;

case FINGERPRINT_IMAGEMESS:

Serial.println("Image too messy");

return p;

case FINGERPRINT_PACKETRECIEVEERR:

Serial.println("Communication error");

return p;

case FINGERPRINT_FEATUREFAIL:

Serial.println("Could not find fingerprint features");

return p;

case FINGERPRINT_INVALIDIMAGE:

Serial.println("Could not find fingerprint features");

return p;

default:

Serial.println("Unknown error");

return p;

}

// OK converted!

p = finger.fingerFastSearch();

if (p == FINGERPRINT_OK) {

Serial.println("Found a print match!");

} else if (p == FINGERPRINT_PACKETRECIEVEERR) {

Serial.println("Communication error");

return p;

} else if (p == FINGERPRINT_NOTFOUND) {

Serial.println("Did not find a match");

return p;

} else {

Serial.println("Unknown error");

return p;

}

////////////////////////////////////////////////////////////////////////

// found a match!//

Serial.print("Found ID #"); Serial.print(finger.fingerID);

Serial.print(" with confidence of "); Serial.println(finger.confidence);

}

// returns -1 if failed, otherwise returns ID #

int getFingerprintIDez() {

uint8_t p = finger.getImage();

if (p != FINGERPRINT_OK) return -1;

p = finger.image2Tz();

if (p != FINGERPRINT_OK) return -2;

p = finger.fingerFastSearch();

if (p != FINGERPRINT_OK) return -3;

// ID Part

switch(finger.fingerID)

{

case 1:

Serial.println(" Hi Self! ");

lcd.clear();

lcd.println("Hi Self!");

delay(1000);

break;

case 2:

Serial.println(" Hi Malia ");

lcd.clear();

lcd.println("Hi Malia");

delay(1000);

break;

case 3:

Serial.println(" Hi Mom! ");

lcd.clear();

lcd.println("Hi Mom!");

delay(1000);

break;

}

// found a match!

Serial.print("Found ID #"); Serial.print(finger.fingerID);

Serial.print(" with confidence of "); Serial.println(finger.confidence);

return finger.fingerID;

}

 
 
 

Comments


© 2017 by Miles Lee. Proudly created with Wix.com

bottom of page