A few minutes ago, I tried assembling a security access point composing of just an Arduino Uno and an access card reader. Everything went just as planned until I wanted to add a password to ensure that the program was being used by the intended user. I can't get the program to return the Access Granted message and it would just hang after I've entered the password. If anyone could help me debug the code I'd be extremely grateful.
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);
void setup()
{
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
Serial.println("Please ID yourself: ");
Serial.println();
}
void loop()
{
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
Serial.println("Card detected ");
Serial.print("Verifying ID ");
Serial.print(".");
delay(2000);
Serial.print(".");
delay(2000);
Serial.print(".");
Serial.print(".");
delay(2000);
Serial.print(".");
delay(2000);
Serial.println(".");
Serial.println("---------------------------------------------------------------------");
Serial.print("UID tag :");
String content= "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
content.toUpperCase();
if (content.substring(1) == "UID OF THE CARD")
{
Serial.println("User: Admin");
Serial.print("Please enter your password: ");
if (Serial.available())
{
if (Serial.read() == THE PASSWORD)
{
Serial.println("Access granted");
Serial.println();
}
`else`
`{`
`Serial.println("Password incorrect");`
`Serial.println();`
`}`
`}`
}
else {
Serial.println(" Access denied");
Serial.println();
delay(3000);
}
}