So I'm doing a RFID project. how do I make more cards be scanned.
basically I want 1 Tag and 4 cards to be scanned, but only 1 tag and 1 card are being scanned.
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10 //RX slave select
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
byte card_ID[4]; //card UID size 4byte
byte Name1[4]={0x8B,0xBA,0xC8,0x01};//first UID card
byte Name2[4]={0x67,0x1E,0x02,0x04};//second UID card
byte Name3[4]={0xA1,0xC7,0x01,0x04};//third UID card
byte Name4[4]={0x8E,0x55,0x00,0x04};//fourth UID card
byte Name5[4]={0xBA,0x12,0x02,0x04};//fifth UID card
//if you want the arduino to detect the cards only once
int NumbCard[5];//this array content the number of cards. in my case i have just two cards.
int j=0;
int const RedLed=6;
int const GreenLed=5;
int const Buzzer=8;
String Name;//user name
long Number;//user number
int n ;//The number of card you want to detect (optional)
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println("CLEARSHEET"); // clears starting at row 1
Serial.println("LABEL,Date,Time,Name,Number");// make four columns (Date,Time,[Name:"user name"]line 48 & 52,[Number:"user number"]line 49 & 53)
pinMode(RedLed,OUTPUT);
pinMode(GreenLed,OUTPUT);
pinMode(Buzzer,OUTPUT);
}
void loop() {
//look for new card
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;//got to start of loop if there is no card present
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;//if read card serial(0) returns 1, the uid struct contians the ID of the read card.
}
for (byte i = 0; i < mfrc522.uid.size; i++) {
card_ID[i]=mfrc522.uid.uidByte[i];
if(card_ID[i]==Name1[i]){
Name="Name 1";//user name
Number=100000;//user number
j=0;//first number in the NumbCard array : NumbCard[j]
}
else if(card_ID[i]==Name2[i]){
Name="Name 2";//user name
Number=590000;//user number
j=1;//first number in the NumbCard array : NumbCard[j]
}
else if(card_ID[i]==Name3[i]){
Name="Name 3";//user name
Number=690000;//user number
j=2;//first number in the NumbCard array : NumbCard[j]
}
else if(card_ID[i]==Name4[i]){
Name="Name 4";//user name
Number=790000;//user number
j=3;//first number in the NumbCard array : NumbCard[j]
}
else if(card_ID[i]==Name5[i]){
Name="Name 5";//user name
Number=890000;//user number
j=4;//first number in the NumbCard array : NumbCard[j]
}
else{
digitalWrite(GreenLed,LOW);
digitalWrite(RedLed,HIGH);
goto cont;//go directly to line 85
}
}
if(NumbCard[j] == 5){//to check if the card already detect
//if you want to use LCD
//Serial.println("Already Exist");
}
else{
NumbCard[j] = 5;//put 1 in the NumbCard array : NumbCard[j]={1,1} to let the arduino know if the card was detecting
n++;//(optional)
Serial.print("DATA,DATE,TIME," + Name);//send the Name to excel
Serial.print(",");
Serial.println(Number); //send the Number to excel
digitalWrite(GreenLed,HIGH);
digitalWrite(RedLed,LOW);
digitalWrite(Buzzer,HIGH);
delay(30);
digitalWrite(Buzzer,LOW);
Serial.println("SAVEWORKBOOKAS,Names/WorkNames");
}
delay(1000);
cont:
delay(2000);
digitalWrite(GreenLed,LOW);
digitalWrite(RedLed,LOW);
//if you want to close the Excel when all card had detected and save Excel file in Names Folder. in my case i have just 2 card (optional)
//if(n==2){
// Serial.println("FORCEEXCELQUIT");
// }
}