Build an Arduino RFID attendance system with an RC522 reader, DS3231 real-time clock, micro SD card logging, 16×2 I2C LCD, buzzer and LEDs, with IN/OUT tracking and one-button card enrolment.
Need it ready-made? Buy Ready Project
This Arduino RFID attendance system records who comes in and who goes out, with the exact date and time. Each person taps an RFID card or key fob on an RC522 reader. The Arduino looks up the card, greets the person on a 16×2 LCD, and writes a line such as 2026-11-10,09:15:02,A1B2C3D4,Rahul,IN into a CSV file on a micro SD card. You can open that file in Excel or Google Sheets at the end of the month.
It is a big combination project for an office, classroom, workshop or tuition centre. It joins two SPI devices (the RFID reader and the SD card) on one bus, two I2C devices (the DS3231 clock and the LCD) on another, and stores the card list in the ATmega328P’s EEPROM so it survives power cuts. A push button lets you add new cards without changing the code.

How It Works
- Card reading: the RC522 reads the 4-byte UID of MIFARE Classic cards and fobs at 13.56 MHz over SPI. The same card scanned again within 3 seconds is ignored, so one tap is never counted twice.
- Card list in EEPROM: up to 20 cards are saved in EEPROM. Each slot holds the UID and the person’s current state (IN or OUT). Names come from the
NAMESlist in the code, in the order the cards were added; extra cards are called User 11, User 12 and so on. - IN/OUT toggle: the first scan of a day marks the person IN, the next marks them OUT, and so on. The state is kept in EEPROM, so a reset or power cut does not mix it up.
- Real-time clock: the DS3231 keeps accurate time from its coin cell even when the Arduino is off. On the first start the code sets it from your computer’s compile time, and you can correct it with a Serial command.
- SD card log: each scan appends one line to
ATTEND.CSVwith date, time, UID, name and status. The RC522 and SD card share the SPI pins and each has its own chip-select pin (D10 and D4), so only one talks at a time. - Feedback: a known card gives a green LED and a short beep with “Welcome” or “Bye” and the time on the LCD. An unknown card gives a red LED, a long beep and its UID on the screen.
- Adding cards: hold the button on D2 and tap a new card. It is saved in the next free slot and the LCD shows its name. Serial commands
list,dumpandsettimehelp with set-up and checking.
Components Required
- Arduino Uno R3 (ATmega328P) – 1
- RC522 RFID reader module (13.56 MHz) with cards or key fobs – 1 set
- DS3231 RTC module with CR2032 coin cell – 1
- Micro SD card module (5V type with on-board regulator) and a micro SD card, 2 to 32 GB, FAT32 – 1
- 16×2 LCD with I2C backpack (PCF8574, address 0x27 or 0x3F) – 1
- Active buzzer, 5V – 1
- 5 mm LEDs, 1 green and 1 red, with two 220 Ω resistors – 1 set
- Tactile push button for adding cards – 1
- Breadboard and jumper wires (male-to-male and male-to-female)
- USB cable or 9V/12V DC adapter for the Uno
Wiring Table
| Module / pin | Arduino Uno pin | Notes |
|---|---|---|
| RC522 SDA (SS) | D10 | RFID chip select |
| RC522 SCK | D13 | Shared SPI clock |
| RC522 MOSI | D11 | Shared SPI data out |
| RC522 MISO | D12 | Shared SPI data in |
| RC522 RST | D9 | |
| RC522 3.3V | 3.3V | Do not connect to 5V |
| RC522 GND | GND | |
| RC522 IRQ | Not connected | |
| SD module CS | D4 | SD chip select |
| SD module SCK / MOSI / MISO | D13 / D11 / D12 | Shared with the RC522 |
| SD module VCC | 5V | Module has its own 3.3V regulator and level shifter |
| SD module GND | GND | |
| DS3231 SDA and LCD SDA | A4 | Shared I2C data |
| DS3231 SCL and LCD SCL | A5 | Shared I2C clock |
| DS3231 VCC and LCD VCC | 5V | |
| DS3231 GND and LCD GND | GND | |
| Green LED anode (via 220 Ω) | D5 | Cathode to GND |
| Red LED anode (via 220 Ω) | D6 | Cathode to GND |
| Buzzer (+) | D7 | Buzzer (-) to GND |
| Add-card button | D2 and GND | Internal pull-up in code |
Connection Diagram
The illustration above shows the parts and how they sit around the Uno. It is a placement guide only, and the wire colours in it are not exact. The pin-accurate drawing below matches the wiring table, so follow it while you build.
Arduino Code
In the Arduino IDE, install these libraries from the Library Manager: MFRC522 (by GithubCommunity), RTClib (by Adafruit) and LiquidCrystal I2C (by Frank de Brabander). SPI, SD, Wire and EEPROM come with the IDE. Select Arduino Uno, then upload the sketch below. It was compiled for the Uno and uses about 24.7 KB of flash and 1.4 KB of RAM.
/*
Arduino RFID Attendance System
Arduino Uno + RC522 RFID + DS3231 RTC + micro SD card + 16x2 I2C LCD
+ buzzer + green/red LEDs + "Add card" button.
- Scan a registered card: logs IN or OUT (toggles) with date and time
to ATTEND.CSV on the SD card and greets the user on the LCD.
- Unknown card: red LED, long beep, UID shown so you can register it.
- Hold the button and scan a new card to add it (names saved in EEPROM
as "User 01", "User 02" ...; you can rename them in the NAMES list).
- Serial commands (9600 baud): "list" shows cards, "dump" prints the log,
"settime YYYY MM DD HH MM SS" sets the RTC.
Libraries: MFRC522 (GithubCommunity), RTClib (Adafruit), LiquidCrystal_I2C,
SD and SPI (built in), EEPROM (built in).
*/
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <EEPROM.h>
#include <MFRC522.h>
#include <RTClib.h>
#include <LiquidCrystal_I2C.h>
// ---------- Pins ----------
const uint8_t RFID_SS = 10; // RC522 SDA (SS)
const uint8_t RFID_RST = 9; // RC522 RST
const uint8_t SD_CS = 4; // SD card module CS
const uint8_t PIN_BUZZ = 7; // active buzzer (+)
const uint8_t PIN_GREEN = 5; // green LED (through 220 ohm)
const uint8_t PIN_RED = 6; // red LED (through 220 ohm)
const uint8_t PIN_ADD = 2; // "Add card" button to GND (internal pull-up)
// ---------- Card storage in EEPROM ----------
// Each slot: 4 bytes UID + 1 byte state (0 = OUT, 1 = IN). Byte 0 = card count.
const uint8_t MAX_CARDS = 20;
const uint8_t SLOT_SIZE = 5;
const int EE_BASE = 1;
// Optional friendly names for slots 0..9 (edit to your own names)
const char* const NAMES[] = {"Admin", "Rahul", "Priya", "Amit", "Neha",
"Rohan", "Sneha", "Vikas", "Anjali", "Karan"};
const uint8_t NAME_COUNT = sizeof(NAMES) / sizeof(NAMES[0]);
MFRC522 rfid(RFID_SS, RFID_RST);
RTC_DS3231 rtc;
LiquidCrystal_I2C lcd(0x27, 16, 2); // try 0x3F if the screen stays blank
bool sdOK = false;
unsigned long lastScan = 0;
uint8_t lastUid[4] = {0, 0, 0, 0};
// ---------- Small helpers ----------
void beep(uint16_t ms) { digitalWrite(PIN_BUZZ, HIGH); delay(ms); digitalWrite(PIN_BUZZ, LOW); }
void showIdle() {
lcd.clear();
lcd.setCursor(0, 0); lcd.print(F("Scan your card"));
DateTime n = rtc.now();
char buf[17];
snprintf(buf, sizeof(buf), "%02d/%02d %02d:%02d %s", n.day(), n.month(), n.hour(), n.minute(), sdOK ? "SD" : "--");
lcd.setCursor(0, 1); lcd.print(buf);
}
uint8_t cardCount() {
uint8_t c = EEPROM.read(0);
if (c > MAX_CARDS) { c = 0; EEPROM.update(0, 0); } // fresh EEPROM reads 255
return c;
}
int findCard(const uint8_t* uid) {
uint8_t n = cardCount();
for (uint8_t i = 0; i < n; i++) {
bool same = true;
for (uint8_t b = 0; b < 4; b++)
if (EEPROM.read(EE_BASE + i * SLOT_SIZE + b) != uid[b]) { same = false; break; }
if (same) return i;
}
return -1;
}
int addCard(const uint8_t* uid) {
uint8_t n = cardCount();
if (n >= MAX_CARDS) return -1;
for (uint8_t b = 0; b < 4; b++) EEPROM.update(EE_BASE + n * SLOT_SIZE + b, uid[b]);
EEPROM.update(EE_BASE + n * SLOT_SIZE + 4, 0); // starts as OUT
EEPROM.update(0, n + 1);
return n;
}
void nameOf(uint8_t slot, char* out, uint8_t len) {
if (slot < NAME_COUNT) strncpy(out, NAMES[slot], len - 1), out[len - 1] = 0;
else snprintf(out, len, "User %02d", slot + 1);
}
void uidToStr(const uint8_t* uid, char* out) {
snprintf(out, 12, "%02X%02X%02X%02X", uid[0], uid[1], uid[2], uid[3]);
}
bool logToSD(const DateTime& t, const char* uidStr, const char* name, const char* dir) {
if (!sdOK) return false;
File f = SD.open("ATTEND.CSV", FILE_WRITE);
if (!f) return false;
char line[64];
snprintf(line, sizeof(line), "%04d-%02d-%02d,%02d:%02d:%02d,%s,%s,%s",
t.year(), t.month(), t.day(), t.hour(), t.minute(), t.second(), uidStr, name, dir);
f.println(line);
f.close();
return true;
}
// ---------- Serial commands ----------
void handleSerial() {
static char cmd[40];
static uint8_t pos = 0;
while (Serial.available()) {
char c = Serial.read();
if (c == '\n' || c == '\r') {
if (pos == 0) continue;
cmd[pos] = 0; pos = 0;
if (!strcmp(cmd, "list")) {
uint8_t n = cardCount();
Serial.print(F("Cards: ")); Serial.println(n);
for (uint8_t i = 0; i < n; i++) {
uint8_t u[4]; char s[12], nm[17];
for (uint8_t b = 0; b < 4; b++) u[b] = EEPROM.read(EE_BASE + i * SLOT_SIZE + b);
uidToStr(u, s); nameOf(i, nm, sizeof(nm));
Serial.print(i + 1); Serial.print(F(". ")); Serial.print(s); Serial.print(' ');
Serial.print(nm); Serial.println(EEPROM.read(EE_BASE + i * SLOT_SIZE + 4) ? F(" (IN)") : F(" (OUT)"));
}
} else if (!strcmp(cmd, "dump")) {
File f = SD.open("ATTEND.CSV");
if (!f) { Serial.println(F("No log file")); }
else { while (f.available()) Serial.write(f.read()); f.close(); }
} else if (!strncmp(cmd, "settime", 7)) {
int Y, M, D, h, m, s;
if (sscanf(cmd + 7, "%d %d %d %d %d %d", &Y, &M, &D, &h, &m, &s) == 6) {
rtc.adjust(DateTime(Y, M, D, h, m, s));
Serial.println(F("Time set"));
showIdle();
} else Serial.println(F("Use: settime 2026 11 10 09 15 00"));
} else {
Serial.println(F("Commands: list, dump, settime YYYY MM DD HH MM SS"));
}
} else if (pos < sizeof(cmd) - 1) cmd[pos++] = c;
}
}
// ---------- Setup ----------
void setup() {
pinMode(PIN_BUZZ, OUTPUT);
pinMode(PIN_GREEN, OUTPUT);
pinMode(PIN_RED, OUTPUT);
pinMode(PIN_ADD, INPUT_PULLUP);
// Keep both SPI devices deselected before starting the bus
pinMode(SD_CS, OUTPUT); digitalWrite(SD_CS, HIGH);
pinMode(RFID_SS, OUTPUT); digitalWrite(RFID_SS, HIGH);
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.print(F("RFID Attendance"));
SPI.begin();
rfid.PCD_Init();
if (!rtc.begin()) {
lcd.setCursor(0, 1); lcd.print(F("RTC not found!"));
Serial.println(F("DS3231 not found, check SDA/SCL"));
while (true) delay(100);
}
if (rtc.lostPower()) {
rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // set from compile time
Serial.println(F("RTC time set from compile time"));
}
sdOK = SD.begin(SD_CS);
Serial.println(sdOK ? F("SD card ready") : F("SD card failed, logging off"));
if (sdOK && !SD.exists("ATTEND.CSV")) {
File f = SD.open("ATTEND.CSV", FILE_WRITE);
if (f) { f.println(F("Date,Time,UID,Name,Status")); f.close(); }
}
lcd.setCursor(0, 1); lcd.print(sdOK ? F("SD OK") : F("No SD card"));
beep(80);
delay(1200);
showIdle();
Serial.println(F("Ready. Type 'list', 'dump' or 'settime ...'"));
}
// ---------- Main loop ----------
void loop() {
handleSerial();
// Refresh the clock on the idle screen every 20 s
static unsigned long lastIdle = 0;
if (millis() - lastIdle > 20000) { lastIdle = millis(); showIdle(); }
if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) return;
uint8_t uid[4];
for (uint8_t b = 0; b < 4; b++) uid[b] = rfid.uid.uidByte[b];
rfid.PICC_HaltA();
rfid.PCD_StopCrypto1();
// Ignore the same card again within 3 seconds
if (millis() - lastScan < 3000 && memcmp(uid, lastUid, 4) == 0) return;
lastScan = millis();
memcpy(lastUid, uid, 4);
char uidStr[12];
uidToStr(uid, uidStr);
Serial.print(F("Card: ")); Serial.println(uidStr);
int slot = findCard(uid);
lcd.clear();
// Add mode: button held while scanning
if (digitalRead(PIN_ADD) == LOW) {
if (slot >= 0) { lcd.print(F("Already added")); beep(300); }
else {
slot = addCard(uid);
if (slot < 0) { lcd.print(F("Memory full")); beep(600); }
else {
char nm[17]; nameOf(slot, nm, sizeof(nm));
lcd.print(F("Card added:")); lcd.setCursor(0, 1); lcd.print(nm);
digitalWrite(PIN_GREEN, HIGH); beep(100); delay(100); beep(100);
}
}
delay(2000); digitalWrite(PIN_GREEN, LOW); lastIdle = millis(); showIdle();
return;
}
if (slot < 0) { // unknown card
lcd.print(F("Unknown card"));
lcd.setCursor(0, 1); lcd.print(uidStr);
digitalWrite(PIN_RED, HIGH); beep(700);
delay(1500); digitalWrite(PIN_RED, LOW); lastIdle = millis(); showIdle();
return;
}
// Known card: toggle IN/OUT and log it
int stAddr = EE_BASE + slot * SLOT_SIZE + 4;
uint8_t state = EEPROM.read(stAddr) ? 0 : 1;
EEPROM.update(stAddr, state);
const char* dir = state ? "IN" : "OUT";
DateTime now = rtc.now();
char nm[17]; nameOf(slot, nm, sizeof(nm));
bool saved = logToSD(now, uidStr, nm, dir);
char line2[17];
snprintf(line2, sizeof(line2), "%-3s %02d:%02d %s", dir, now.hour(), now.minute(), saved ? "" : "NOSD");
lcd.print(state ? F("Welcome ") : F("Bye "));
lcd.print(nm);
lcd.setCursor(0, 1); lcd.print(line2);
Serial.print(nm); Serial.print(' '); Serial.print(dir); Serial.println(saved ? F(" logged") : F(" NOT logged (SD)"));
digitalWrite(PIN_GREEN, HIGH); beep(120);
delay(2000); digitalWrite(PIN_GREEN, LOW); lastIdle = millis(); showIdle();
}
Setting Up and Testing
- Format the micro SD card as FAT32 and insert it before powering the Uno. The LCD should show “SD OK” and then “Scan your card” with the date and time.
- Open the Serial Monitor at 9600 baud. If the time is wrong, type for example
settime 2026 11 10 09 15 00and press Enter. - Edit the
NAMESlist in the code with your own people before you add cards. The first card you add gets the first name, the second card the second name, and so on. - Hold the button and tap each card once. The LCD shows “Card added” and the name. Type
listin the Serial Monitor to see all saved cards. - Release the button and tap a card. You should see “Welcome Rahul” and “IN 09:15”, and the next tap shows “Bye” and OUT.
- Type
dumpto print the whole log, or take out the SD card and openATTEND.CSVin a spreadsheet.
Troubleshooting
| Problem | Fix |
|---|---|
| Cards are never detected | Check the RC522 is on 3.3V, SDA on D10 and RST on D9. Hold the card flat and within 2 to 3 cm of the antenna. Run the MFRC522 DumpInfo example to confirm the reader works. |
| RFID stops working after the SD card starts | Some cheap SD modules do not release the MISO line. Make sure both CS pins are set HIGH at start (the code does this), or use an SD module with a 74LVC125 buffer that tri-states MISO, or add a 330 Ω resistor in the SD MISO line. |
| LCD shows “No SD card” | Format the card as FAT32 (cards over 32 GB use exFAT and will not work), check CS on D4, and power the module from 5V, not 3.3V. |
| LCD stays blank or shows boxes | Turn the blue contrast pot on the I2C backpack. If still blank, change 0x27 to 0x3F in the code. |
| “RTC not found!” | Check SDA on A4 and SCL on A5. Both the LCD and the DS3231 share these two pins. |
| Wrong date or time in the log | Use the settime command once. Fit a fresh CR2032 cell so the clock keeps time when power is off. |
| Two IN entries in a row for one person | This happens only if EEPROM was cleared. Tap the card once more to bring it back in step, or edit the CSV. |
| Unknown card even after adding | Hold the button the whole time you tap the card. The memory holds 20 cards; “Memory full” means you need to raise MAX_CARDS (EEPROM has room for about 200). |
Ideas to Extend
- Swap the Uno for an ESP32 or Wemos D1 Mini and send each entry to Google Sheets over Wi-Fi.
- Add a relay and a 12V solenoid lock so only registered cards open the door.
- Add an R307 fingerprint sensor for two-factor entry, or a DFPlayer Mini to speak the person’s name.
1 thought on “Arduino RFID Attendance System with RC522, DS3231 RTC, SD Card Logging & LCD”