Arduino programming help needed

Thread Starter

Eim

Joined Dec 28, 2012
5
Hi all.
I am almost finished a project with an Arduino Uno interfacing a fingerprint sensor, an LCD and a keypad. When a fingerprint is detected the LCD displays the message access granted and turns on a green led. When a correct password is entered the lcd displays the same message and turns the green led on. If an incorrect password is entered the message access denied is displayed and the red led stays on. Here is my problem. I need the lcd to display a message such as "Enter password or fingerprint" before either the password is entered or before a finger is placed on the sensor. I can get the message to appear on the lcd by using this:

Rich (BB code):
lcd.setCursor(0,0);
lcd.print("Enter Password");
lcd.setCursor(0,1);
lcd.print("Or Fingerprint");
What I need is for this message to be displayed, but then the lcd to clear once I go to enter the password or place a finger on the sensor. And also for when I am finished entering either the password or the fingerprint for the original message to appear again. I have tried many different ways but to no avail. Any help it would be much appreciated.
Here is the code I am using so far.

Rich (BB code):
#include <Adafruit_Fingerprint.h>
#include <Password.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
#if ARDUINO >= 100
#include <SoftwareSerial.h>
#else
#include <NewSoftSerial.h>
#endif
LiquidCrystal lcd(10,9,8,7,6,5);
 
int getFingerprintIDez();
 
 
#if ARDUINO >= 100
SoftwareSerial mySerial(2, 3);
#else
NewSoftSerial mySerial(2, 3);
#endif
 
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
 
 
Password password = Password( "147*" );
const byte ROWS = 4;
const byte COLS = 3; 
 
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0',' '}
};
 
byte rowPins[ROWS] = {13,A0,A1,A2}; 
byte colPins[COLS] = {A5,A4,A3}; 
const int buttonPin = 52;
int buttonState = 0;
 
 
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
 
#define redLedPin 11
#define greenLedPin 12
 
void setup() 
{
Serial.begin(9600);
Serial.println("fingertest");
 
 
 
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...");
pinMode(redLedPin, OUTPUT);
pinMode(greenLedPin, OUTPUT);
digitalWrite(redLedPin, LOW);
digitalWrite(greenLedPin, HIGH);
 
lcd.begin(16, 2); 
Serial.begin(9600);
keypad.addEventListener(keypadEvent); 
keypad.setDebounceTime(250);
}
 
void loop() 
{
getFingerprintIDez();
keypad.getKey();
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
lcd.clear();
lcd.setCursor(0, 1);
keypad.getKey();
 
}
 
}
 
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;
}
 
 
 
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;
}
 
 
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;
} 
 
 
Serial.print("Found ID #"); Serial.print(finger.fingerID); 
Serial.print(" with confidence of "); Serial.println(finger.confidence); 
}
 
 
int getFingerprintIDez() {
uint8_t p = finger.getImage();
if (p != FINGERPRINT_OK) return -1;
 
p = finger.image2Tz();
if (p != FINGERPRINT_OK) return -1;
 
p = finger.fingerFastSearch();
if (p != FINGERPRINT_OK) return -1;
 
 
digitalWrite(redLedPin, HIGH);
digitalWrite(greenLedPin, LOW);
lcd.print("Access Granted");
delay(3000);
lcd.clear();
digitalWrite(greenLedPin, HIGH);
delay(1000);
digitalWrite(redLedPin, LOW);
Serial.print("Found ID #"); Serial.print(finger.fingerID); 
Serial.print(" with confidence of "); Serial.println(finger.confidence);
return finger.fingerID; 
}
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
lcd.print(eKey);
switch (eKey){
case ' ': guessPassword(); break;
default:
password.append(eKey);
}
}}
 
void guessPassword(){
if (password.evaluate()){
digitalWrite(redLedPin,HIGH); 
digitalWrite(greenLedPin,LOW);
lcd.setCursor(0,1);
lcd.print("Access Granted"); 
password.reset(); 
delay(2000);
 
 
digitalWrite(greenLedPin, HIGH);
delay(1000);
digitalWrite(redLedPin, LOW);
 
lcd.clear();
}
 
 
else{
digitalWrite(redLedPin,LOW);
lcd.setCursor(0,1);
lcd.print("ACCESS DENIED ");
password.reset(); 
delay(3000);
lcd.clear();
}
}
Thanks very much.
 

Georacer

Joined Nov 25, 2009
5,182
Your loop() function looks pretty empty and illogical.

You wait for a finger scan and you write the result on the lcd.
Then you wait for a keystroke. Then you wait for a button press. If you get one, then you wait for another keystroke.

Moreover, I can't see where you print the initial message on the lcd.

Also, please use proper code identation when publishing your work. It makes reading it much easier.

Posting the question in the arduino forum might be a better idea, since more people are familiar with the libraries used. I have to read up Keypad.h in order to give you a definitive answer.
 

Thread Starter

Eim

Joined Dec 28, 2012
5
Thanks for your advice Georacer. I hadn't added the lcd print message in the code yet. That is why you couldn't see it. Thanks again.
 
Top