Hello all im trying to create a security system that requires an rfid tag, a pin, and a finger scan to work. so far ive gotten the first two parts to work but im running into issues with the third part. When i try to
have the code switch to the fingerprint portion it compiles but the lcd flickers after scanning the rfid tag. Im not sure if its because of the codes logic or the program being to intense.Also i get errors when i try to add the function that starts to scan fingerprints i get an error. Any help would be greatly appreciated. (This may be the second time i posted this. If it is i apologize i couldnt find the first post)
#include <Adafruit_Fingerprint.h>
#include <LiquidCrystal.h> //include LCD library (standard library)
#include <Keypad.h> //include keypad library - first you must install library (library link in the video description)
#include <SPI.h> // This sketch uses the SPI.h library
#include <MFRC522.h> // This sketch uses the MFRC522.h library
#define redLED 10 //define the LED pins
#define greenLED 11
#define SS_PIN 53
#define RST_PIN 13
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
char* pin = "7597"; //create a pin
char pinlength = 0; //keypad position
char pinenter[4]; // store entered pin
String keycardcode = "BB 9A 2B 1B" ;//accepted key card uids
int j = 0;
boolean RfidMode = true;
boolean FingerMode = true;
int getFingerprintIDez();
SoftwareSerial mySerial(42, 43);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
const byte rows = 4; //number of the keypad's rows and columns
const byte cols = 4;
char keyMap [rows] [cols] = { //define the cymbols on the buttons of the keypad
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins [rows] = {1, 2, 3, 4}; //pins of the keypad
byte colPins [cols] = {5, 6, 7, 8};
Keypad myKeypad = Keypad( makeKeymap(keyMap), rowPins, colPins, rows, cols);
LiquidCrystal lcd (A0, A1, A2, A3, A4, A5); // pins of the LCD. (RS, E, D4, D5, D6, D7)
void setup() {
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
lcd.begin(16, 2); // LCD SCREEN
pinMode(redLED, OUTPUT); //set the LED as an output
pinMode(greenLED, OUTPUT);
finger.begin(57600);
}
void loop () {
//--------------------------------------------------------------------------------------------------------
if (RfidMode == true)
{
lcd.setCursor(0, 0);
lcd.print(" Welcome ");
lcd.setCursor(0, 1);
lcd.print (" Scan Key Card" );
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
// Rading the the key card
String keycard = "";
for (byte i = 0; i < mfrc522.uid.size; i++)
{
keycard.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
keycard.concat(String(mfrc522.uid.uidByte[i], HEX));
}
keycard.toUpperCase();
//Checking the key card
if (keycard.substring(1) == keycardcode)
{
//If Key card is correct
lcd.clear();
lcd.print(" Key Card Accepted ");
digitalWrite(greenLED, HIGH);
delay(3000);
digitalWrite(greenLED, LOW);
lcd.clear();
lcd.print(" Enter Pin ");
RfidMode = false; // change rfid mode to false and get pin
}
else
{
//IF key card is wrong
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Wrong Key card ");
lcd.setCursor(0, 1);
lcd.print(" Access Denied!!! ");
digitalWrite(redLED, HIGH);
delay(3000);
digitalWrite(redLED, LOW);
lcd.clear();
}
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// When switch to enter Pin
if (RfidMode == false ) {
pinlength = myKeypad.getKey();
if (pinlength)
{
pinenter[j++] = pinlength;
lcd.print("*");
}
if (j == 4) // waits for 4 keys to be input
{
delay (200);
if (!(strncmp(pinenter, pin, 4))) //Checks if pin entered is a match
{
lcd.clear();
lcd.print(" Pin Accepted ");
digitalWrite(greenLED, HIGH);
delay (3000);
digitalWrite(greenLED, LOW);
lcd.clear();
j = 0;
FingerMode= true ; // Make finger mode true
}
else //if pin is wrong
{
lcd.clear();
lcd.print(" Wrong Pin ");
digitalWrite(redLED, HIGH);
delay (3000);
digitalWrite(redLED, LOW);
lcd.clear();
j = 0;
RfidMode = true; // Make rfid mode true
}
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if ( FingerMode == true){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" scan finger");
}
}
}