IoT-enabled Appointment Device
Fingerprint Sensor Code
#include <Button.h>
#include <LiquidCrystal.h> //for the screen
#include <FPS_GT511C3.h> //the fps (fingerprint scanner) library
#include <SoftwareSerial.h>//used by fps library
//Setting up the pins for the LCD and the fps
LiquidCrystal lcd(13, 12, 11, 10, 9, 8); //pinouts for LCD
FPS_GT511C3 fps(2, 3); //RX, TX
Button button1 = Button(4, PULLDOWN);
Button button2 = Button(5, PULLDOWN);
int b1 = 0;
int b2 = 0;
int firstRun = 0;
int temp = 0;
boolean isFinger = false; //true if the fps detects a finger on the scanner
int timer = 0; //this is for when there is too long of a delay, it turns off
void setup(){
//for debugging
//Serial.begin(9600);
//Serial.begin(9600);
fps.UseSerialDebug = false; //set to true for fps debugging through serial
//initializing the libraries
lcd.begin(16,2);
fps.Open();
fps.SetLED(true); //the fps LED
delay(30);
}
void loop(){
temp = 0;
firstRun = 0;
lcd.clear();
lcd.print("The prof is IN"); //the command to print to the LCD
lcd.setCursor(0, 1); //sets the cursor to the 0th column in the 1st row
lcd.print("Verify if student");
delay(150);
buttonState();
if(b1 == 1){
if(firstRun == 0){
lcd.clear();
lcd.print("Please put"); //the command to print to the LCD
lcd.setCursor(0, 1); //sets the cursor to the 0th column in the 1st row
lcd.print(" your finger ");
delay(150);
//scan and identify the finger when one is put on it
waitForFinger();
timer = 0; //resets timer for timeout
lcd.clear(); //clears the screen and sets the cursor to 0,0
fps.CaptureFinger(false); //captures the finger for identification
int id = fps.Identify1_N(); //identifies print and stores the id
if(id < 20){
lcd.print("Student Verified"); //success message
lcd.setCursor(0,1);
switch(id){
case 1:
lcd.print("2010-12345");
delay(10000);
lcd.clear();
//valid_resp();
lcd.print("Message sent"); //this is where the sending of the data to the server will take place
break;
case 2:
lcd.print("2011-12345");
delay(10000);
lcd.clear();
//valid_resp();
lcd.print("Message sent");
break;
case 3:
lcd.print("2010-13665");
delay(10000);
lcd.clear();
//valid_resp();
lcd.print("Message sent");
break;
case 4:
lcd.print("2012-21324");
delay(10000);
lcd.clear();
//valid_resp();
lcd.print("Message sent");
break;
case 5:
lcd.print("2013-12343");
delay(10000);
lcd.clear();
//valid_resp();
lcd.print("Message sent");
break;
case 6:
lcd.print("2010-21623");
delay(10000);
lcd.clear();
//valid_resp();
lcd.print("Message sent");
break;
case 7:
lcd.print("2012-32132");
delay(10000);
lcd.clear();
//valid_resp();
lcd.print("Message sent");
break;
case 8:
lcd.print("2013-23245");
delay(10000);
lcd.clear();
//valid_resp();
break;
case 9:
lcd.print("2011-34324");
delay(10000);
lcd.clear();
//valid_resp();
break;
case 10:
lcd.print("2010-14345");
delay(10000);
lcd.clear();
//valid_resp();
lcd.print("Message sent");
break;
}
delay(1500);
//sends simple pattern to attiny inside garage (for security)
}
else{
lcd.print("Fingerprint is"); //if print isn't recognized
lcd.setCursor(0,1);
lcd.print(" unverified ");
delay(2000);
lcd.clear();
lcd.print("Please try again");
delay(500);}
}}
if (b2 == 1){
if(firstRun == 0){
lcd.clear();
lcd.print("Please put"); //the command to print to the LCD
lcd.setCursor(0, 1); //sets the cursor to the 0th column in the 1st row
lcd.print(" your finger ");
waitForFinger(); //tap to continue to enroll
//save a new fingerprint
while(temp!=1){
//save a new fingerprint
//prints message to lcd
lcd.clear();
lcd.print(" So you want to ");
lcd.setCursor(0,1);
lcd.print("scan a new one? ");
delay(2000);
//Copied and slightly modified from the enroll example:
int enrollid = 1;
//choosing which id to overwrite/create
//release your finger when you want to write to the id printed on the screen
waitForFinger(); //waits for the fps to be pressed
if(fps.IsPressFinger() == true){
lcd.clear();
lcd.print(" 1? ");
delay(1000);
if(fps.IsPressFinger() == true){
lcd.clear();
lcd.print(" 2? ");
delay(1000);
if(fps.IsPressFinger() == true){
lcd.clear();
lcd.print(" 3? ");
delay(1000);
if(fps.IsPressFinger() == true){
lcd.clear();
lcd.print(" 4? ");
delay(1000);
if(fps.IsPressFinger() == true){
lcd.clear();
lcd.print(" 5? ");
delay(1000);
if(fps.IsPressFinger() == true){
lcd.clear();
lcd.print(" 6? ");
delay(1000);
if(fps.IsPressFinger() == true){
lcd.clear();
lcd.print(" 7? ");
delay(1000);
if(fps.IsPressFinger() == true){
lcd.clear();
lcd.print(" 8? ");
delay(1000);
if(fps.IsPressFinger() == true){
lcd.clear();
lcd.print(" 9? ");
delay(1000);
if(fps.IsPressFinger() == true){
lcd.clear();
lcd.print(" 10? ");
delay(1000);
enrollid = 10; //can be expanded to up to 20
}
else enrollid = 9;
}
else enrollid = 8;
}
else enrollid = 7;
}
else enrollid = 6;
}
else enrollid = 5;
}
else enrollid = 4;
}
else enrollid = 3;
}
else enrollid = 2;
}
else enrollid = 1;
}
//warning if there is already data in this id slot
if(fps.CheckEnrolled(enrollid)){
lcd.clear();
lcd.print(" Warning! ID #");
lcd.print(enrollid);
lcd.setCursor(0,1);
lcd.print(" has data. OK? ");
waitForFinger(); //waits for the fps to be pressed
fps.DeleteID(enrollid); //delete data
delay(100);
}
//Enroll
fps.EnrollStart(enrollid);
lcd.clear();
lcd.print("Place finger to ");
lcd.setCursor(0,1);
lcd.print("enroll #");
lcd.print(enrollid); //prints id that is being enrolled
waitForFinger(); //waits for the fps to be pressed
//captures the finger and saves to memory three times for accurate data
bool bret = fps.CaptureFinger(true); //high quality pic for enrollment
int iret = 0; //error stuff
if (bret != false){ //first enroll
lcd.clear();
lcd.print(" Remove finger ");
fps.Enroll1();
while(fps.IsPressFinger() == true) delay(100); //waits until no finger
lcd.clear();
lcd.print(" Press again ");
waitForFinger(); //waits for the fps to be pressed
bret = fps.CaptureFinger(true);
if (bret != false){ //second enroll
lcd.clear();
lcd.print(" Remove finger ");
fps.Enroll2();
while(fps.IsPressFinger() == true) delay(100);
lcd.clear();
lcd.print("Press yet again ");
waitForFinger();
bret = fps.CaptureFinger(true);
if (bret != false){ //third enroll
iret = fps.Enroll3();
if (iret == 0){ //checks to see if there are any errors
lcd.clear();
lcd.print(" Success! ");
delay(2000);
temp=1;
}
else{ //if the enrollment fails in any way
lcd.clear();
lcd.print("Fail. Try again ");
delay(1000);
}
}
lcd.clear();
lcd.print("3");
delay(1000);
}
lcd.clear();
lcd.print("2");
delay(1000);
}
lcd.clear();
lcd.print("1");
delay(1000);
}
} }
delay(250);}
void buttonState() {
delay(100);
b1 = button1.isPressed();
b2 = button2.isPressed();
}
void waitForFinger(){
timer = 0; //resets the timer everytime this function starts
while(fps.IsPressFinger() == false){ //timeout
timer++;
delay(100);
if (timer>=80){
timer = 0; //reset timer
break;
}
}
timer = 0; //resets the timer everytime this function ends
}
void valid_resp(){
lcd.clear();
String consult = "Consult";
String advise = "Advise";
int curs_pos = 0; // 0 if Advise/ 1 if Consult
lcd.print(advise);
lcd.setcursor(0,1);
lcd.print(consult);
while(1){
buttonState();
if(b1 == 1){
curs_pos = !curs_pos;
if(curs_pos){
lcd.clear();
lcd.print(advise);
lcd.setcursor(0,1);
lcd.print("> " + consult);
else{
lcd.clear();
lcd.print(">" + advise);
lcd.setcursor(0,1);
lcd.print(consult);
}
if(b2 == 1){
if(curs_pos){
// sendemail containing student #, name
// "<student_name> would like to ask for advice for thesis"
break;
else{
// sendemail containing student #, name
// "<student_name> would like to consult
break;
}
}
}
}