Back to Advanced Projects

💳 RFID Attendance System

Scan RFID tags, track timestamps with an RTC, and log data to an SD card.

📋 Overview

This project integrates three separate SPI and I2C modules into a cohesive system. It reads an RFID card's unique ID, fetches the current date/time, and logs it to a text file on a MicroSD card.

What you'll learn: SPI communication with RC522 and SD modules, I2C with DS3231 RTC, file handling (read/write), and string manipulation.

Estimated time: 2-3 hours. Difficulty: ⭐⭐⭐ Intermediate.

🧩 Components Needed

ComponentSpecificationQtyNotes
Arduino Mega 25605V Logic1Lots of pins and memory
RC522 RFID ModuleSPI Interface, 3.3V1Includes cards/fobs
DS3231 RTC ModuleI2C Interface1Keeps time when powered off
MicroSD Card ModuleSPI Interface1Formats as FAT32
Breadboard & Wires1Many wires required

📖 Step-by-Step Tutorial

1

Format SD Card

Ensure your MicroSD card is formatted to FAT32 before inserting it into the module.
2

Wire the SPI Bus (Mega)

The Mega uses pins 50 (MISO), 51 (MOSI), and 52 (SCK) for SPI. Both the SD module and RC522 share these pins.
3

Wire Chip Selects (CS)

Assign unique CS pins. E.g., SD Card CS → Pin 53, RC522 SDA(SS) → Pin 49.
4

Wire the RTC

Connect DS3231 SDA → Pin 20, SCL → Pin 21 on the Mega.
5

Code Integration

Upload the combined sketch. When a card is scanned, it will print to Serial and write a log entry to log.txt on the SD card.
💡
SPI devices share MISO, MOSI, and SCK, but MUST have distinct CS (Chip Select) pins. Ensure you only pull one CS pin LOW at a time in code.

💻 Code / Configuration

rfid_attendance.ino
INO
// RFID Attendance System - Volt X
#include <SPI.h>
#include <MFRC522.h>
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"

#define SS_PIN 49
#define RST_PIN 48
#define SD_CS_PIN 53

MFRC522 rfid(SS_PIN, RST_PIN);
RTC_DS3231 rtc;

void setup() {
  Serial.begin(9600);
  SPI.begin();
  rfid.PCD_Init();
  
  if (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
  }
  
  if (!SD.begin(SD_CS_PIN)) {
    Serial.println("SD Card failed");

Reviews & Ratings

0 reviews
5★
0
4★
0
3★
0
2★
0
1★
0
...

Loading reviews...