RFID RC522 Attendance System Using Arduino with Data Logger
In this project, we have designed RFID RC522 Based Attendance System Using Arduino with Data Logger. MFRC522 RFID Reader is a very simple yet effective module. It is an RFID module and is used for scanning RFID cards. It’s a new technology and is expanding day by day. Nowadays it is extensively used in offices where employees have issued an RFID card and their attendance is marked when they touch their card to the RFID reader. We have seen it in many movies that when someone places one’s card over some machine then the door opens or closes. In short, its a new emerging technology which is quite useful.
In this project, we will make RFID MFRC522 based Time Attendance System Using Arduino Board. When you swipe an RFID tag next to the RFID reader, it saves the user UID and time in an SD card. It also shows if you are late or in time accordingly to a preset hour and minute. For this, we are interfacing the MFRC522 RFID SPI module with Arduino. We are also interfacing SD Card Module as a Datalogger where the data is saved in text format. Similarly, RTC Module DS3231 or DS1307 is used to store time information.
But before beginning you can see our earlier projects that are based on Attendance System:
1. RFID EM-18 Based Attendance System using Arduino & LCD Display
2. Fingerprint Sensor Based Biometric Attendance System using Arduino
You can also check the advance version of the same project:
IoT Based RFID Attendance System Using Arduino ESP8266 & Adafruit.io
Bill of Materials
S.N. | Components Name | Quantity | Purchase Links |
---|---|---|---|
1 | Arduino UNO Board | 1 | Amazon | AliExpress |
2 | RFID Module RC522 | 1 | Amazon | AliExpress |
3 | 16X2 LCD Display | 1 | Amazon | AliExpress |
4 | Potentiometer 10K | 1 | Amazon | AliExpress |
5 | 13.56 MHz RFID Cards | 1 | Amazon | AliExpress |
6 | Micro SD Card 8GB/16GB | 1 | Amazon | AliExpress |
7 | Card Reader | 1 | Amazon | AliExpress |
8 | RTC Module DS3231 | 1 | Amazon | AliExpress |
9 | Buzzer 5V | 1 | Amazon | AliExpress |
10 | LED 5mm Any Color | 2 | Amazon | AliExpress |
11 | Connecting Wires | 20 | Amazon | AliExpress |
12 | Breadboard | 1 | Amazon | AliExpress |
RFID MFRC522 Module
RC522 – RFID Reader / Writer 13.56MHz with Cards Kit includes a 13.56MHz RF reader cum writer module that uses an RC522 IC and two S50 RFID cards. The MF RC522 is a highly integrated transmission module for contactless communication at 13.56 MHz. RC522 supports ISO 14443A/MIFARE mode.
RC522 – RFID Reader features an outstanding modulation and demodulation algorithm to serve effortless RF communication at 13.56 MHz. The S50 RFID Cards will ease up the process helping you to learn and add the 13.56 MHz RF transition to your project.
The module uses SPI to communicate with microcontrollers. The open-hardware community already has a lot of projects exploiting the RC522 – RFID Communication, using Arduino.
The following table shows the connection between Arduino UNO & RFID MFRC522:
Note: different Arduino boards have different SPI pins. If you’re using another Arduino board, check the Arduino documentation.
SD Card Module
The micro- SD Card Module is a simple solution for transferring data to and from a standard SD card. The pin out is directly compatible with Arduino, but can also be used with other microcontrollers. It allows you to add mass storage and data logging to your project.
This module has an SPI interface which is compatible with any sd card and it uses 5V or 3.3V power supply which is compatible with Arduino UNO/Mega. SD module has various applications such as data logger, audio, video, graphics. This module will greatly expand the capability an Arduino can do with their poor limited memory.
The following table shows the connection between Arduino UNO & SD Card Module:
Note: different Arduino boards have different SPI pins. If you’re using another Arduino board, check the Arduino documentation.
DS3231 RTC Module
RTC means Real-Time Clock. RTC modules are simply TIME and DATE remembering systems that have battery setup which in the absence of external power keeps the module running. This keeps the TIME and DATE up to date. So we can have accurate TIME and DATE from the RTC module whenever we want.
DS3231 is a six terminal device, out of the two pins are not compulsory to use. It works on I2C Communication Protocols with SDA and SCL pins. So we have mainly four pins.</p
The following table shows the connection between Arduino UNO & DS3231 Module:
Note: different Arduino boards have different I2C pins. If you’re using another Arduino board, check the Arduino documentation.
Circuit Diagram & Connection
The circuit for this project RFID RC522 Based Attendance System Using Arduino with Data Logger is shown in the circuit schematics below.
In this circuit there are 3.3V and 5V devices, make sure you wire them correctly. Also, if you’re using different modules, check the recommend voltage before powering the circuit. Wire one module at a time and follow the pinout tables if needed.
Preparing & Setting Up SD Card
First, insert the SD Card of 16/32 GB in SD Card Reader and format using FAT32 Command:
Once the formatting is done, put the SD card in SD Card Module as in the assembled circuit above. Then upload the code given below to Arduino Board.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
#include <SPI.h> #include <SD.h> // set up variables using the SD utility library functions: Sd2Card card; SdVolume volume; SdFile root; // change this to match your SD shield or module; // Arduino Ethernet shield: pin 4 // Adafruit SD shields and modules: pin 10 // Sparkfun SD shield: pin 8 // MKRZero SD: SDCARD_SS_PIN const int chipSelect = 4; void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } Serial.print("\nInitializing SD card..."); // we'll use the initialization code from the utility libraries // since we're just testing if the card is working! if (!card.init(SPI_HALF_SPEED, chipSelect)) { Serial.println("initialization failed. Things to check:"); Serial.println("* is a card inserted?"); Serial.println("* is your wiring correct?"); Serial.println("* did you change the chipSelect pin to match your shield or module?"); while (1); } else { Serial.println("Wiring is correct and a card is present."); } // print the type of card Serial.println(); Serial.print("Card type: "); switch (card.type()) { case SD_CARD_TYPE_SD1: Serial.println("SD1"); break; case SD_CARD_TYPE_SD2: Serial.println("SD2"); break; case SD_CARD_TYPE_SDHC: Serial.println("SDHC"); break; default: Serial.println("Unknown"); } // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32 if (!volume.init(card)) { Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card"); while (1); } Serial.print("Clusters: "); Serial.println(volume.clusterCount()); Serial.print("Blocks x Cluster: "); Serial.println(volume.blocksPerCluster()); Serial.print("Total Blocks: "); Serial.println(volume.blocksPerCluster() * volume.clusterCount()); Serial.println(); // print the type and size of the first FAT-type volume uint32_t volumesize; Serial.print("Volume type is: FAT"); Serial.println(volume.fatType(), DEC); volumesize = volume.blocksPerCluster(); // clusters are collections of blocks volumesize *= volume.clusterCount(); // we'll have a lot of clusters volumesize /= 2; // SD card blocks are always 512 bytes (2 blocks are 1KB) Serial.print("Volume size (Kb): "); Serial.println(volumesize); Serial.print("Volume size (Mb): "); volumesize /= 1024; Serial.println(volumesize); Serial.print("Volume size (Gb): "); Serial.println((float)volumesize / 1024.0); Serial.println("\nFiles found on the card (name, date and size in bytes): "); root.openRoot(volume); // list all files in the card with date and size root.ls(LS_R | LS_DATE | LS_SIZE); } void loop(void) { } |
After uploading check the serial monitor. If the below messages get displayed then you can proceed further.
Source Code/Programs
Add the two libraries first before compiling the Code:
1. MFRC522 Library Link: Download
2. RTC Library Link: Download
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
#include <LiquidCrystal.h> LiquidCrystal lcd(3, 2, A0, A1, A2, A3); #include <MFRC522.h> // for the RFID #include <SPI.h> // for the RFID and SD card module #include <SD.h> // for the SD card #include <RTClib.h> // for the RTC // define pins for RFID #define CS_RFID 10 #define RST_RFID 9 // define select pin for SD card module #define CS_SD 4 // Create a file to store the data File myFile; // Instance of the class for RFID MFRC522 rfid(CS_RFID, RST_RFID); // Variable to hold the tag's UID String uidString; // Instance of the class for RTC RTC_DS1307 rtc; // Define check in time const int checkInHour = 9; const int checkInMinute = 5; //Variable to hold user check in int userCheckInHour; int userCheckInMinute; // Pins for LEDs and buzzer const int redLED = 6; const int greenLED = 7; const int buzzer = 5; void setup() { // Set LEDs and buzzer as outputs pinMode(redLED, OUTPUT); pinMode(greenLED, OUTPUT); pinMode(buzzer, OUTPUT); // Init Serial port Serial.begin(9600); lcd.begin(16,2); while(!Serial); // for Leonardo/Micro/Zero // Init SPI bus SPI.begin(); // Init MFRC522 rfid.PCD_Init(); // Setup for the SD card Serial.print("Initializing SD card..."); lcd.print("Initializing "); lcd.setCursor(0, 1); lcd.print("SD card..."); delay(3000); lcd.clear(); if(!SD.begin(CS_SD)) { Serial.println("initialization failed!"); lcd.print("Initializing "); lcd.setCursor(0, 1); lcd.print("failed!"); return; } Serial.println("initialization done."); lcd.print("Initialization "); lcd.setCursor(0, 1); lcd.print("Done..."); // Setup for the RTC if(!rtc.begin()) { Serial.println("Couldn't find RTC"); lcd.clear(); lcd.print("Couldn't find RTC"); while(1); } else { // following line sets the RTC to the date & time this sketch was compiled rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); } if(!rtc.isrunning()) { Serial.println("RTC is NOT running!"); lcd.clear(); lcd.print("RTC Not Running!"); } } void loop() { //look for new cards if(rfid.PICC_IsNewCardPresent()) { readRFID(); logCard(); verifyCheckIn(); } delay(10); } void readRFID() { rfid.PICC_ReadCardSerial(); lcd.clear(); Serial.print("Tag UID: "); lcd.print("Tag UID: "); uidString = String(rfid.uid.uidByte[0]) + " " + String(rfid.uid.uidByte[1]) + " " + String(rfid.uid.uidByte[2]) + " " + String(rfid.uid.uidByte[3]); Serial.println(uidString); lcd.setCursor(0, 1); lcd.print(uidString); delay(2000); // Sound the buzzer when a card is read tone(buzzer, 2000); delay(200); noTone(buzzer); delay(200); } void logCard() { // Enables SD card chip select pin digitalWrite(CS_SD,LOW); // Open file myFile=SD.open("DATA.txt", FILE_WRITE); // If the file opened ok, write to it if (myFile) { Serial.println("File opened ok"); lcd.clear(); lcd.print("File opened ok"); delay(2000); myFile.print(uidString); myFile.print(", "); // Save time on SD card DateTime now = rtc.now(); myFile.print(now.year(), DEC); myFile.print('/'); myFile.print(now.month(), DEC); myFile.print('/'); myFile.print(now.day(), DEC); myFile.print(','); myFile.print(now.hour(), DEC); myFile.print(':'); myFile.println(now.minute(), DEC); // Print time on Serial monitor Serial.print(now.year(), DEC); Serial.print('/'); Serial.print(now.month(), DEC); Serial.print('/'); Serial.print(now.day(), DEC); Serial.print(' '); Serial.print(now.hour(), DEC); Serial.print(':'); Serial.println(now.minute(), DEC); Serial.println("sucessfully written on SD card"); lcd.clear(); lcd.print(now.year(), DEC); lcd.print(':'); lcd.print(now.month(), DEC); lcd.print(':'); lcd.print(now.day(), DEC); lcd.print(' '); lcd.setCursor(11, 0); lcd.print(now.hour(), DEC); lcd.print(':'); lcd.print(now.minute(), DEC); lcd.setCursor(0, 1); lcd.print("Written on SD..."); delay(2000); myFile.close(); // Save check in time; userCheckInHour = now.hour(); userCheckInMinute = now.minute(); } else { Serial.println("error opening data.txt"); lcd.clear(); lcd.print("error opening data.txt"); } // Disables SD card chip select pin digitalWrite(CS_SD,HIGH); } void verifyCheckIn(){ if((userCheckInHour < checkInHour)||((userCheckInHour==checkInHour) && (userCheckInMinute <= checkInMinute))){ digitalWrite(greenLED, HIGH); delay(2000); digitalWrite(greenLED,LOW); Serial.println("You're welcome!"); lcd.clear(); lcd.print("You're Welcome!"); } else{ digitalWrite(redLED, HIGH); delay(2000); digitalWrite(redLED,LOW); Serial.println("You are late..."); lcd.clear(); lcd.print("You are Late..."); delay(3000); lcd.clear(); lcd.print("Put RFID to Scan"); } } |
Working of the Project
When the RFID reader reads an RFID tag, it saves the current time and the UID of the tag in an SD card. The Arduino communicates with the SD card using an SD card module.
You can set a check-in time to compare if you are on time or late. If you are on time, a green LED lights up, if you are late, a red LED lights up. The system also has a buzzer that beeps when a tag is read.
32 Comments
Rfid reader not working
Checked all the connections
It was not working in my case too. First check if SD Card module is working or not. Also, did u use 330-ohm resistor between mosi pins of SD Card Module and RFID
Sir rfid not working
sd card setep is finished
But when i show card to rfid the display doesnt change anything but showing initialization done
how to fix plss im doing this as sch project
I need to finish plss
I using 330 ohm too
RFID reader not working either, all connections are in. Also using the 330-ohm resistor. please help.
i am facing same problem did you find any solution.
did you find any solution
hey thanks great video, how does this attendance system can prevent people from swapping cards for absent people who never showed up in class, or is there anyway of preventing it beside the use of fingerprints based attendance system.
This code is for RTC DS1307. Plz can you show me the code for rtc ds 3231
Hi i interfaced RFID-RC522 (13.65MHZ) module it getting data from the card but it want to store the data in card day by day input date through IOT of the card was inserted then send print card number was reading the date and automatically if match card number the wifi send automatic data transform and updated in the computer but i tried this type using if equitation but how to transform the data in bulk please provide example.
Dear satya in my project I have same problem here. Have you found answer for that problem
Hi There , i used the code but its not working with a ds3231 rtc module. What can i do to fix it so that it will work.
RFID is not working
Sir did the code here work and run for u?
Hi bro it worked for me. The code that I have posted here is validated and verified. It should work fine unless there is a problem with the hardware and connection.
yes bro code is working
Thank you for the great project.
I was doing it as a project for my final year.
The project is working fine and I am able to store the attendance data to SD Card as explained.
Just one question, I want to add ESP8266-01 Module to it so that i can receive the data in MQTT.
Can you help me.
hey bro in lcd its says that initialization done but when i try to scan rfid card it is not working
Thank you for thank you for your valuable unique contribution on the web right now
Thanks Marcox
add 2.2K Resistor between SD card MISO and Arduino pin , it will fix the problem
I want to present instead of ID with name how should I repair the program.
Hi Bro RTC DS3231 Not Runing, how to solution?
Bonjours je souhaite également faire la même chose afficher le nom de la personne plutot que de montré le numéro de la carte comment faire ???
Sir after uploading the code to the board… it shows as ‘initialisation done’.. but after that nothing comes if i swipe the card nothing comes…it stops at ‘initialisation done’ and nothing after that.
Hi, to work with SD card 2Gb need to change what ?
Where to add the 10k potentiometer?
Where to add the 10k Potentiometer in the circuit?
OK. It’s working perfectly
is this code working properly for rtc 1307 , and is the lcd display working? Guys i nees a fast reply asap please.
How did you solve the MISO/MOSI connection between RFID and SD card Adapter , because both electronics use the same SPI.
hi can this code working with ds3231?
There is an issue of sharing spi bus..how to fix this
..??