RFID class attendance with SD card
Build it step by step
0 of 7 doneTest the reader
Print UIDs.
Test the SD card
Write a line.
Set the RTC
Check the time shows.
Make roll.csv
UID and name per line.
Match a tap to a name
Show it on the LCD.
Log to attendance.csv
Date, time, UID and name.
Add the 10 minute rule
Ignore repeats.
How do you build an RFID class attendance with SD card?
Students tap MIFARE cards on an RC522 reader and each tap is saved with date and time to a CSV file the teacher opens in a spreadsheet. You need Arduino Uno R3, RC522 RFID reader, RFID tags 13.56 MHz (MIFARE Classic 1K) × 10, DS3231 RTC module, MicroSD Card Module, 16x2 LCD with I2C backpack (PCF8574) and Active buzzer 5 V. It takes 7 steps and about 150 minutes.
- Level
- Intermediate
- Time
- About 150 min
- Parts
- 7
Wiring
| From | To | Why |
|---|---|---|
| RC522 SDA (SS) | Uno D10 | Reader chip select |
| SD module CS | Uno D4 | Card chip select |
| RC522 and SD SCK, MOSI, MISO | Uno D13, D11, D12 | Shared SPI bus |
| RC522 RST | Uno D9 | Reset |
| RC522 3.3V and GND | Uno 3.3V and GND | Power (never 5 V) |
| SD module VCC and GND | Uno 5V and GND | Power |
| RTC and LCD SDA, SCL | Uno A4, A5 | Shared I2C bus |
| RTC and LCD VCC, GND | Uno 5V, GND | Power |
| Buzzer plus and minus | Uno D8 and GND | Beep |
Code
Each card has a unique number, the UID, which the reader can read in a moment. The sketch looks that number up in a list on the SD card to find the name, then adds a line with the date and time to a CSV file that opens in any spreadsheet. A second tap within ten minutes is ignored, so a student cannot be counted twice by accident. The reader and the SD card share the same three SPI wires and each has its own chip-select wire, so only one listens at a time. Because the roll list holds names, keep to your school's rules on student data: tell students what is recorded, store only what you need, and keep the card in a safe place. A card's number can be copied, so this is a convenience for marking attendance and not proof of identity; for anything that matters, the teacher should still check. Set the RTC once and fit its coin cell, so the time survives a power cut. Arduino IDE, board "Arduino Uno".
Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// RFID class attendance: a tap is matched to roll.csv on the SD card and logged to attendance.csv with date and time.
// roll.csv has one line per card: UID in capital hex with no spaces, a comma, then the name (for example 04A1B2C3,Asha).
// Libraries: MFRC522, SD, RTClib, LiquidCrystal_I2C. Board: Arduino Uno.
#include <SPI.h>
#include <SD.h>
#include <MFRC522.h>
#include <RTClib.h>
#include <LiquidCrystal_I2C.h>
MFRC522 rfid(10, 9);
RTC_DS3231 rtc;
LiquidCrystal_I2C lcd(0x27, 16, 2);
const byte SD_CS = 4;
const unsigned long REPEAT_MS = 600000UL; // ignore a second tap within 10 minutes
String lastUid[8]; unsigned long lastTime[8]; byte nLast = 0;
String uidString() {
String s;
for (byte i = 0; i < rfid.uid.size; i++) { if (rfid.uid.uidByte[i] < 0x10) s += "0"; s += String(rfid.uid.uidByte[i], HEX); }
s.toUpperCase(); return s;
}
String findName(const String& uid) {
File f = SD.open("roll.csv");
String name = "";
while (f && f.available()) {
String line = f.readStringUntil('\n'); line.trim();
int c = line.indexOf(',');
if (c > 0 && line.substring(0, c) == uid) { name = line.substring(c + 1); break; }
}
if (f) f.close();
return name;
}
bool recentlySeen(const String& uid) {
for (byte i = 0; i < nLast; i++) if (lastUid[i] == uid) { if (millis() - lastTime[i] < REPEAT_MS) return true; lastTime[i] = millis(); return false; }
if (nLast < 8) { lastUid[nLast] = uid; lastTime[nLast] = millis(); nLast++; }
return false;
}
void show(const String& a, const String& b) { lcd.clear(); lcd.print(a); lcd.setCursor(0, 1); lcd.print(b); }
void setup() {
SPI.begin();
pinMode(8, OUTPUT); pinMode(SD_CS, OUTPUT); digitalWrite(SD_CS, HIGH);
rfid.PCD_Init();
lcd.init(); lcd.backlight();
rtc.begin();
if (!SD.begin(SD_CS)) { show("SD card error", ""); while (true) {} }
show("Tap your card", "");
}
void loop() {
if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) return;
String uid = uidString();
String name = findName(uid);
if (name == "") { show("Unknown card", uid); tone(8, 300, 500); }
else if (recentlySeen(uid)) { show(name, "already marked"); tone(8, 600, 200); }
else {
DateTime n = rtc.now();
File f = SD.open("attendance.csv", FILE_WRITE);
if (f) {
char line[64];
snprintf(line, sizeof(line), "%04d-%02d-%02d,%02d:%02d:%02d,", n.year(), n.month(), n.day(), n.hour(), n.minute(), n.second());
f.print(line); f.print(uid); f.print(','); f.println(name); f.close();
show(name, "marked present"); tone(8, 1500, 150);
} else show("Write error", "");
}
rfid.PICC_HaltA();
delay(1200);
show("Tap your card", "");
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Known card | Name shown, marked present |
| Same card again | Already marked |
| Unknown card | Message and low beep |
| CSV file | Opens with correct times |
If it does not work
SD error
Format as FAT32 and check the chip select.
Reader not found
Check 3.3 V and the SS wire.
Wrong time
Set the RTC from the example sketch.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the RFID class attendance with SD card?
Arduino Uno R3, RC522 RFID reader, RFID tags 13.56 MHz (MIFARE Classic 1K) × 10, DS3231 RTC module, MicroSD Card Module, 16x2 LCD with I2C backpack (PCF8574) and Active buzzer 5 V.
How long does the RFID class attendance with SD card take to build?
About 150 minutes for a intermediate maker, in 7 steps.
How do I know the RFID class attendance with SD card works?
Known card: Name shown, marked present. Same card again: Already marked. Unknown card: Message and low beep.
SD error: what should I check?
Format as FAT32 and check the chip select.
Reader not found: what should I check?
Check 3.3 V and the SS wire.
Wrong time: what should I check?
Set the RTC from the example sketch.
