I am using this code.. But everytime after one rfid tag is read by the reader, I have to manually press the reset button on the arduino before scanning the next tag. I want to do this operation after every 10 or 20 seconds from one tag scanning without manually pressing the reset button. What changes I have to make to this code??
/*
* source: http://www.electroschematics.com/11301/arduino-rfid-reader-rc522-access-control-system/
* Read a card using a mfrc522 reader on your SPI interface
* Pin layout should be as follows (on Arduino Uno):
* MOSI: Pin 11 / ICSP-4
* MISO: Pin 12 / ICSP-1
* SCK: Pin 13 / ISCP-3
* SS: Pin 10
* RST: Pin 9
*/
#include <SPI.h>
#include <RFID.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address----------------------------------------------
#define SS_PIN 10
#define RST_PIN 9
RFID rfid(SS_PIN,RST_PIN);
int startAlarm = false;
int resetAlarm = 2;
int relay = 6;
int alarm = 8;
int serNum[5];
int cards[][5] = {
{00,162,227,135,198} // card 1
};
bool access = false;
void setup()
{
// Setup size of LCD 20 characters and 2 lines
lcd.begin(20,2); //------------------------------------------------------
// Back light on
lcd.backlight(); //---------------------------------------------------------
lcd.setCursor(0,0); //----------------------------------------------
lcd.print("SCAN your ID"); //------------------------------------------------
Serial.begin(9600);
SPI.begin();
rfid.init();
pinMode(resetAlarm, INPUT);
pinMode(relay, OUTPUT);
pinMode(alarm, OUTPUT);
digitalWrite(relay, HIGH); // or LOW if you have a regular relay------------------------------(ALREADY CHANGED)
attachInterrupt(0, reset_alarm, LOW);
}
void loop()
{
if(rfid.isCard()){
if(rfid.readCardSerial()){
Serial.print(rfid.serNum[0]);
Serial.print(",");
Serial.print(rfid.serNum[1]);
Serial.print(",");
Serial.print(rfid.serNum[2]);
Serial.print(",");
Serial.print(rfid.serNum[3]);
Serial.print(",");
Serial.print(rfid.serNum[4]);
Serial.println("");
for(int x = 0; x < sizeof(cards); x++){
for(int i = 0; i < sizeof(rfid.serNum); i++ ){
if(rfid.serNum[i] != cards[x][i]) {
access = false;
break;
} else {
access = true;
}
}
if(access) break;
}
}
if(access){
Serial.println("Welcome!");
startAlarm = false;
digitalWrite(relay, LOW); // HIGH with regular relay (I have already changed the code) //------------------------------
lcd.setCursor(0,0); //----------------------------------------------------------------------------------------------
lcd.print("Access Granted"); //-------------------------------------------------------------------------------------------
delay(3000);
lcd.clear();
lcd.setCursor(0,0); //----------------------------------------------
lcd.print("SCAN your ID"); //------------------------------------------------
//---------------------------------------------------------------
} else {
Serial.println("Not allowed!");
startAlarm = true;
digitalWrite(relay, HIGH); // LOW with regular relay (I have already changed the code)----------------------------------
lcd.setCursor(0,0); //------------------------------------------------------------------------------------
lcd.print("Invalid Access "); //------------------------------------------------------------------------------------
delay(3000);
lcd.clear(); //--------------------------------------------
lcd.setCursor(0,0); //----------------------------------------------
lcd.print("SCAN your ID"); //------------------------------------------------
}
}
if(startAlarm) {
digitalWrite(alarm, HIGH);
} else {
digitalWrite(alarm, LOW);
}
rfid.halt();
}
void reset_alarm(){
startAlarm = false;
}