Hi everyone, I am doing the project for my exam which consists of a safety lock with rfid, everything goes as it should go apart when the solenoid lock is unlocked, which once opened closes and from there on the module rfid no longer works.
this is the code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
#define LED_G 5
#define LED_R 4
#define RELAY 3
#define BUZZER 2
#define ACCESS_DELAY 8000
#define DENIED_DELAY 1000
MFRC522 mfrc522(SS_PIN, RST_PIN);
LiquidCrystal_I2C lcd(0x27,20,4);
void setup()
{
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
pinMode(LED_G, OUTPUT);
pinMode(LED_R, OUTPUT);
pinMode(RELAY, OUTPUT);
pinMode(BUZZER, OUTPUT);
noTone(BUZZER);
digitalWrite(RELAY, LOW);
Serial.println("Put your card to the reader...");
Serial.println();
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Prego appoggi pure la sua card");
}
void loop()
{
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
lcd.clear();
Serial.print("Numero : ");
lcd.setCursor(0, 0);
lcd.print("Numero:");
lcd.setCursor(0, 1);
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();
Serial.print("Permesso? ");
lcd.clear();
content.toUpperCase();
if (content.substring(1) == "B3 5D 89 91")
{
Serial.println("codice giusto entrare");
Serial.println();
lcd.setCursor(0, 0);
lcd.print("accesso autorizzato,puo' entrare");
delay(500);
digitalWrite(RELAY, HIGH);
digitalWrite(LED_G, HIGH);
delay(ACCESS_DELAY);
digitalWrite(RELAY, LOW);
digitalWrite(LED_G, LOW);
}
else {
Serial.println("codice errato riprovi");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("accesso negato, riprovi");
digitalWrite(LED_R, HIGH);
tone(BUZZER, 300);
delay(DENIED_DELAY);
digitalWrite(LED_R, LOW);
noTone(BUZZER);
}
}
void reset_state()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Prego appoggi pure la sua card");
digitalWrite( LED_G , LOW);
digitalWrite( LED_R , LOW);
}
What should I do in your opinion?