In this project you’re going to build a time attendance system with MFRC522 RFID Reader and Arduino. 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.
Before getting started it’s important to layout the project main features:

Here’s a list of the required components for this project:
You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!
In this project we’re using the MFRC522 RFID reader and that’s the one we recommend you to get (although this project may also be compatible with other RFID readers).
RFID means radio-frequency identification. RFID uses electromagnetic fields to transfer data over short distances and it’s useful to identify people, to make transactions, etc.
An RFID system needs tags and a reader:


The MFRC522 RFID reader works at 3.3V and it can use SPI or I2C communication. The library we’re going to use to control the RFID reader only supports SPI, so that’s the communication protocol we’re going to use.
To learn more about the RFID reader with the Arduino read: Security Access using MFRC522 RFID Reader with Arduino
This project uses the MFRC522.h library to control the RFID reader. This library doesn’t come installed in Arduino IDE by default, so you need to install it. Go to Sketch > Include library > Manage libraries and search for MFRC522 or follow the next steps:
The following table shows the reader pinout for a future reference:
| SDA | Digital 10 |
| SCK | Digital 13 |
| MOSI | Digital 11 |
| MISO | Digital 12 |
| IRQ | Don’t connect |
| GND | GND |
| RST | Digital 9 |
| 3.3V | 3.3V |
Note: different Arduino boards have different SPI pins. If you’re using another Arduino board, check the Arduino documentation.
When a tag is read, its UID and time are saved on an SD card so that you can keep track of check ins. There are different ways to use an SD card with the Arduino. In this project we’re using the SD card module shown in figure below – it works with micro SD card.

There are different models from different suppliers, but they all work in a similar way, using the SPI communication protocol. To communicate with the SD card we’re going to use a library called SD.h, that comes already installed in Arduino IDE by default.
To learn more about the SD card module with the Arduino read: Guide to SD Card Module with Arduino
The following table shows the SD card module pinout for a future reference:
| VCC | 3.3V |
| CS | Digital 4 |
| MOSI | Digital 11 |
| CLK | Digital 13 |
| MISO | Digital 12 |
| GND | GND |
Note: different Arduino boards have different SPI pins. If you’re using another Arduino board, check the Arduino documentation.
The first step when using the SD card module with Arduino is formatting the SD card as FAT16 or FAT32. Follow the instructions below.
1) To format the SD card, insert it in your computer. Go to My Computer and right click on the SD card. Select Format as shown in figure below.

2) A new window pops up. Select FAT32, press Start to initialize the formatting process and follow the onscreen instructions.

(This step is optional. This is an additional step to make sure the SD card module is working properly.)
Insert the formatted SD card in the SD card module.
Connect the SD card module to the Arduino as shown in the circuit schematics below or check the pinout table.
Note: depending on the module you’re using, the pins may be placed in a different location.
To make sure everything is wired correctly and the SD card is working properly, in the Arduino IDE window go to File> Examples > SD > CardInfo.
Upload the code to your Arduino board. Make sure you have the right board and COM port selected.
Open the Serial Monitor at a baud rate of 9600 and the SD card information will be displayed. If everything is working properly you’ll see a similar message on the serial monitor.

To keep track of time, we’re using the SD1307 RTC module. However, this project works just fine with the DS3231, which is very similar. One main difference between them is the accuracy. The DS3231 is much more accurate than the DS1307. The figure below shows the SD1307 model.

The module has a backup battery installed. This allows the module to retain the time, even when it’s not being powered up.
This module uses I2C communication and we’ll use the RTCLib.h library to read the time from the RTC.
To learn more about the DS1307 real time clock with the Arduino read: Guide for Real Time Clock (RTC) Module with Arduino (DS1307 and DS3231)
The following table shows the RTC module pinout for a future reference:
| SCL | A5 |
| SDA | A4 |
| VCC | 5V (check your module datasheet) |
| GND | GND |
Note: different Arduino boards have different I2C pins. If you’re using another Arduino board, check the Arduino documentation.
To install the RTCLib.h go to Sketch > Include library > Manage libraries and search for RTCLib or follow the next steps:
The circuit for this project 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.

Here’s how your circuit should look like after assembling.

Upload the following code to your Arduino. Make sure you have the right Board and COM Port selected.
/* * Rui Santos * Complete Project Details https://randomnerdtutorials.com */ #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); 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..."); if(!SD.begin(CS_SD)) { Serial.println("initialization failed!"); return; } Serial.println("initialization done."); // Setup for the RTC if(!rtc.begin()) { Serial.println("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!"); } } void loop() { //look for new cards if(rfid.PICC_IsNewCardPresent()) { readRFID(); logCard(); verifyCheckIn(); } delay(10); } void readRFID() { rfid.PICC_ReadCardSerial(); Serial.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); // Sound the buzzer when a card is read tone(buzzer, 2000); delay(100); noTone(buzzer); delay(100); } 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"); 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"); myFile.close(); // Save check in time; userCheckInHour = now.hour(); userCheckInMinute = now.minute(); } else { Serial.println("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!"); } else{ digitalWrite(redLED, HIGH); delay(2000); digitalWrite(redLED,LOW); Serial.println("You are late..."); } }
Note: double-check that you have the needed libraries installed.
The code starts by importing the needed libraries. The MFRC522 for the RFID reader, the SD for the SD card module and the RTClib for the RTC. You also include the SPI library for SPI communication with the RFID and SD card module.
#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
Then, you define the pins for the RFID reader and the SD card module. For the RFID, the SCK pin (CS_RFID) is connected to pin 10 and the RST pin (RST_RFID) is connected to pin 9. For the SD card module, the Chip Select pin (CS_SD) is connected to pin 4.
// define pins for RFID #define CS_RFID 10 #define RST_RFID 9 // define chip select pin for SD card module #define CS_SD 4
You create a File called myFile to store your data.
File myFile;
Then, you create an instance for the RFID and for the RTC:
// Instance of the class for RFID MFRC522 rfid(CS_RFID, RST_RFID); // Instance of the class for RTC RTC_DS1307 rtc;
You create a string variable uidString that holds the UID tags.
String uidString;
The following lines create variables to define the check in time hour and minute. In this case, we’re defining the check in hour to 9h05m AM. You can change the check in time by changing these values:
// Define check in time const int checkInHour = 9; const int checkInMinute = 5;
You also need to create variables to hold the user’s check in hour. These variables will save the hour a certain UID tag was read. The following variables hold the check in hour and the check in minute.
//Variable to hold user check in int userCheckInHour; int userCheckInMinute;
Finally you attribute the pin numbers to the LEDs and buzzer.
// Pins for LEDs and buzzer const int redLED = 6; const int greenLED = 7; const int buzzer = 5;
Next, in the setup() you set the LEDs and buzzer as outputs.
// Set LEDs and buzzer as outputs pinMode(redLED, OUTPUT); pinMode(greenLED, OUTPUT); pinMode(buzzer, OUTPUT);
After that, each module is initialed.
In this code you create 3 functions: readRFID(), logCard() and verifyCheckIn().
The readRFID() function reads the tag UID, saves it in the uidString variable and displays it on the serial monitor. Also, when it reads the tag, the buzzer makes a beep sound.
The logCard() function creates a file on your SD card called DATA.txt. You can edit the name of the file, if you want, on the following line.
myFile=SD.open("DATA.txt", FILE_WRITE);Then, it saves the uidString (that holds the UID of the tag) on the SD card and the current time.
myFile.print(uidString);
// 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.print(now.minute(), DEC);It also saves the user check In hour and minute in the following variables for further comparison with the predefined check in time.
userCheckInHour = now.hour(); userCheckInMinute = now.minute();
The verifyCheckIn() function simply compares the user check in time with the predefined check in hour and gives feedback accordingly. If the user is late, the red LED lights up; if the user is on time, the green LED lights up.
After studying the created functions, the loop() is pretty straightforward to understand.
First, the code checks if an RFID tag was swiped. If yes, it will read the RFID UID, log the UID and the time into the SD card, and then it will give feedback to the user by lighting up one of the LEDs.
To check the data saved on the SD card, remove it from the SD card module and insert it on your computer.
Open the SD card folder and you should have a file called DATA.txt.

Open the file using a text editor. You’ll have something as follows:

Notice that each value is separated by commas. This makes it easier if you want to import this data to Excel, Google Sheets, or other data processing software.
Copyright ©2025. All Rights Reserved Emblab THE RAVE INNOVATION