Attendance RFID
This is the Arduino driven project where we use the NFC tags to setup the attendance system, to get started with this i shall be providing code for the two file, one for setting up the NFC tags to get the Details of the Tags. this two files are required for successful working of model
NOTE: when you just copy and paste the code into the arduino make sure to download the libraries
1. NFC setup
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println(F("Read personal data on a MIFARE PICC:")); //shows in serial that it is ready to read
}
void loop() {
MFRC522::MIFARE_Key key;
for (byte i = 0; i < 6; i++) key.keyByte[i] = 0xFF;
byte block;
byte len;
MFRC522::StatusCode status;
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
Serial.println(F("**Card Detected:**"));
mfrc522.PICC_DumpDetailsToSerial(&(mfrc522.uid)); //dump some details about the card
//mfrc522.PICC_DumpToSerial(&(mfrc522.uid)); //uncomment this to see all blocks in hex
Serial.print(F("Name: "));
byte buffer1[18];
block = 4;
len = 18;
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 4, &key, &(mfrc522.uid)); //line 834 of MFRC522.cpp file
if (status != MFRC522::STATUS_OK) {
Serial.print(F("Authentication failed: "));
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
status = mfrc522.MIFARE_Read(block, buffer1, &len);
if (status != MFRC522::STATUS_OK) {
Serial.print(F("Reading failed: "));
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
for (uint8_t i = 0; i < 16; i++)
{
if (buffer1[i] != 32)
{
Serial.write(buffer1[i]);
}
}
Serial.print(" ");
byte buffer2[18];
block = 1;
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 1, &key, &(mfrc522.uid)); //line 834
if (status != MFRC522::STATUS_OK) {
Serial.print(F("Authentication failed: "));
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
status = mfrc522.MIFARE_Read(block, buffer2, &len);
if (status != MFRC522::STATUS_OK) {
Serial.print(F("Reading failed: "));
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
for (uint8_t i = 0; i < 16; i++) {
Serial.write(buffer2[i] );
}
Serial.println(F("\n**End Reading**\n"));
delay(1000); //change value if you want to read cards faster
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
}
//*****************************************************************************************//
REMEMBER: the above code is for just getting the unique key present in the nfc or rfid tags after that you have to use the excel code setup to configure the nfc tags like inserting the values like name or number.
2. Circuit Diagram
3. The Excel Code Setup
#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]={0x00,0x00,0x00,0x00};//first UID card
byte Name2[4]={0x00,0x00,0x00,0x00};//second UID card
//if you want the arduino to detect the cards only once
int NumbCard[2];//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=123456;//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=789101;//user number
j=1;//Second number in the NumbCard array : NumbCard[j]
}
else{
digitalWrite(GreenLed,LOW);
digitalWrite(RedLed,HIGH);
goto cont;//go directly to line 85
}
}
if(NumbCard[j] == 1){//to check if the card already detect
//if you want to use LCD
//Serial.println("Already Exist");
}
else{
NumbCard[j] = 1;//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");
// }
}
REMEMBER: this above code is used to configure the NFC tags after that you have to configure the excel sheet using the macros so that whenever the data is fetched it gets it working.
I have also included the readme file so go through it.
NOTE: the code provided is complete but there is one more step that is the excel sheet file which i have provided the google drive link you can get it from there also these files are completely available in zip or folder format you can download.