Hi, I am currently working on a project which uses a fingerprint sensor and a keypad for a security system. I managed to solve the part when the fingerprint sensor has to scan the fingerprint. I am having troubles when there is an unrecognized fingerprint and the password has to be introduced from the keypad. I am also using an lcd to display messages. So, my code reaches the part when it displays the message "Enter password", but after that the data introduced from the keypad is not displayed anymore. After those 10 seconds it comes back to displaying the "waiting for fingerprint message". How can I solve this to be able to introduce the password?
char Data[Password_length];
char Master[Password_length] = "123456*";
byte data_count = 0;
byte master_count = 0;
bool correct_password;
char custom_key;
bool running = true;
const byte ROWS = 4;
const byte COLS = 3;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte rowPins[ROWS] = {13, 12, 11, 10};
byte colPins[COLS] = {6, 5, 4};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(9600);
while (!Serial); // For Yun/Leo/Micro/Zero/...
delay(100);
Serial.println("\n\nAdafruit finger detect test");
lcd.init(); // initialize the lcd
lcd.backlight();
//pinMode(signalPinGreen, OUTPUT);
//pinMode(signalPinRed, OUTPUT);
//pinMode(PIN_BUZZER, OUTPUT);
//Serial.println("Enter password: ");
finger.begin(57600);
delay(5);
if (finger.verifyPassword()) {
Serial.println("Found fingerprint sensor!");
} else {
Serial.println("Did not find fingerprint sensor :(");
while (1) {
delay(1);
}
}
}
void loop() {
if (running) {
int fingerprintID = getFingerprintID();
if (fingerprintID != -1) {
if (fingerprintID == 2) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Waiting for");
lcd.setCursor(0, 1);
lcd.print("fingerprint...");
}
// Check if the fingerprint ID is the authorized one
if (fingerprintID == 1) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Access granted!");
delay(2000);
running = false;
}
if (fingerprintID != 1 && fingerprintID != 2) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Access denied!");
lcd.setCursor(0, 0);
//Serial.println("Enter password:");
lcd.print("Enter password:");
custom_key = customKeypad.getKey();
if (custom_key) {
Data[data_count] = custom_key;
lcd.setCursor(data_count, 1);
lcd.print(Data[data_count]);
Serial.println(Data[data_count]);
//Serial.println(Data[data_count]);
data_count++;
}
if (data_count == Password_length - 1) {
delay(1000);
lcd.clear();
if (!strcmp(Data, Master)) {
Serial.println("Correct!");
lcd.setCursor(0, 0);
lcd.print("Correct!");
delay(5000);
}
else {
Serial.println("Incorrect!");
lcd.setCursor(0, 0);
lcd.print("Incorrect!");
delay(5000);
}
clearData();
}
delay(10000);
}
delay(3000);
}
}
}
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.fingerSearch();
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);
return finger.fingerID;
}
void clearData() {
while (data_count != 0) {
Data[data_count--] = 0;
}
return;
}