Polling System Application with Arduino

In this project, we are installing a polling system with MFRC522 RFID Reader and Arduino. Each time the RFID reader is taught a card-pass, we save the user UID and time to an SD card. We can also see if the user is late based on a preset time and minute.

Project Overview

With this project, you will have learned and implemented concepts such as RFID, SD Card, RTC Module, SPI communication. We use rfid reader to learn UID of cards, SD card module to record this data, timestamps of recorded data and RTC time module to check late arrival. If the card is read on time, the LED will turn green, and if you are late, the LED will light up red. It also provides a warning sound with the help of a buzzer to understand that the card is being read.

Required Materials

arduino rfid polling

  • Arduino UNO
  • SD Card Module and SD Card
  • RTC Module (used DS3231)
  • MFRC522 RFID Module and Suitable Card
  • LED and 220 Ohm Resistance
  • Breadboard and Cables

What is RFID?

Radio frequency identification (RFID) is the use of radio waves to read and capture information stored on a label attached to an object. A label can be read up to a few meters, and the reader to watch does not need to be directly within sight. arduino rfid polling

MFRC522 RFID Module

In this project we use the MRFC522 RFID reading module to read RFID tags. You can use it in a different RFID reading module, but in terms of library compatibility and easy operation, this module may be your primary choice. The RFID system needs tags and a reader: Tags are added to the object to be defined, in this example we use a Keychain and an electromagnetic card. Some stores also use paper-shaped RFID tags to identify input systems products or counts. Each tag has its own unique ID(UID). arduino rfid polling The RFID readerworks both as a transmitter and as a receiver. First it sends the reading signal to the label, and then waits for the response to the sent signal. In this way, it establishes a two-way communication. yJcvD The MFRC522 RFID reader works with 3.3V and use SPI or I2C protocols as a way of communicating. You can access the RFID library that we will use in this content here, which only supports the SPI bus, which is why we make connections in accordance with the SPI bus.

Installation of the MFRC522 Library

  1. First you need to download the library, if you have not downloaded it from the link at the top, you can download it here.
  2. After you download the library folder, you can remove the folder and copy it directly to the folder where the Arduino libraries are installed. Or add the .zip folder you downloaded directly from the Arduino IDE to the Draft > library > . Add ZIP Library… you can add it to the library location by following the path.

arduino rfid polling

RFID Connection Schema

RFID PinsArduino UNO
SdaDigital 10
SCKDigital 13
MOSIDigital 11
MISODigital 12
RSTDigital 9

Each Arduino card use different SPI pins, these pin connections are made for Arduino UNO.


The IRQ pin comes up as an acronym for "Interrupt request", which means interrupt in this project, which leaves it blank because we will not use interrupt.

Interrupt: A interrupt request (or IRQ) is a hardware signal sent to a processor that temporarily stops a running program and instead allows a interrupt handler, a special program, to run.

SD Card Module

You can use any SD Card Module for writing to an SD Card. The library used by this module comes installed and ready to use in the Arduino IDE. a7bAX

SD Card Module Connection Schema

SD Card Module PinsArduino UNO
CsDigital 4
MOSIDigital 11
CLKDigital 13
MISODigital 12

Preparing the SD Card for Use

Due to the module and library we use, we must format the SD Card as FAT16 or FAT32. You can do this for Windows and Linux operating systems by following these steps:


Additional programs or virtual servers are required to format FAT16 and FAT32 file systems on Mac OS operating systems.

For Windows

Connect your SD Card to your computer with the SD Card adapter. Then go to My Computer and right-click on the SD Card to click "Format/Format". vP6TQ Select FAT32 and start the formatting process. arduino rfid polling

For Linux Distributions

Open the terminal and run the following code.


The terminal prints a list of all the sections and related information that are installed: the area used, the available space, the percentage of space used, and the path to which it is connected. Find your SD card from the list. In this example, the SD Card driver appears as /dev/sdb1, so be careful that this path may be different for you. arduino rfid polling As a second step, we need to disassemble the installed SD Card "unmount". You can disassemble it with the code below.

sudo umount /dev/sdb1

arduino rfid polling After the disassembly is complete, you can format any file format you want. Since we will use FAT32 in this project, you must use this code:

sudo mkfs.vfat /dev/sdb1

Other file formats are: NTFS:

sudo mkfs.ntfs /dev/sdb1


sudo mkfs.exfat /dev/sdb1

Testing the SD Card (Optional)

In fact, this step is not necessary, but sometimes problems can occur when working with the SD Card Module when formatting is not progressing properly. In this step, you can test both your SD card and your SD Card Module. Connect the SD Card Module to your Arduino UNO card as arduino rfid polling follows: After completing the connections, open the Arduino IDE and install the SD > CardInfo instance in the File > Samples > To Arduino UNO. After the installation is complete, open the Serial Display with 9600 baudrates and check the output. If everything is normal and correct, you need to print it out as follows. jeKhu

RTC Module

We need to use the RTC module to track time. There are many alternatives available for this module, for example, DS3231, DS1307, DS1302, we use DS3231 in this project, if you have a different RTC module you can choose it.


DS3231 and DS1307 use the I2C protocol, while DS1302 use the serial communication protocol. That's why you need to make some changes to the code to use it in this project.

JFOB0 You can also plug batteries into the CR2032 battery compartment of the module we use, allowing the module to track time even when it is not connected to a source. Let's note that these modules have a slight deviation share.

RTC Module Connection Schema

RTC Module PinsArduino UNO

RTCLib Library Setup

  1. First you need to download the library, you can download it here.
  2. After you download the library folder, you can remove the folder and copy it directly to the folder where the Arduino libraries are installed. Or add the .zip folder you downloaded directly from the Arduino IDE to the Draft > library > . Add ZIP Library… you can add it to the library location by following the path.

We have finished the library installations and information of the modules we use piece by piece, and now we can look at the entire project through a large lens.

Circuit Diagram

What you should pay attention to here is to make the 3.3V and 5V connections correctly, arduino rfid polling and the last image of the Circuit will be as follows: arduino rfid polling

Project ID

#include // RFID
#include // RFID and SD card
#include // SD card
#include // RTC
#define CS_RFID 10
#define RST_RFID 9
#define CS_SD 4 
File file;
String uidString;
RTC_DS1307 rtc;
const int checkInHour = 9;
const int checkInMinute = 5;
int userCheckInHour;
int userCheckInMinute;
const int redLED = 6;
const int greenLED = 7;
const int buzzer = 5;
void setup() {
  pinMode(redLED, OUTPUT);  
  pinMode(greenLED, OUTPUT);
  pinMode(buzzer, OUTPUT);
  while(! Serial;
  rfid. PCD_Init(); 
  Serial.print("Preparing SD card...");
  if(! SD.begin(CS_SD)) {
    Serial.println("Unexpected error in preparation!");
  Serial.println("initialization done.");
  if(!rtc.begin()) {
    Serial.println("RTC not found");
  else {
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  if(!rtc.isrunning()) {
    Serial.println("RTC mode does not work!");
void loop() {
  if(rfid. PICC_IsNewCardPresent()) {
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]);
  tone(buzzer, 2000); 
void logCard() {
  file=SD.open("DATA.txt", FILE_WRITE);
  if (file) {
    Serial.println("The file was urgent");
    file.print(", ");   
    DateTime now = rtc.now();
    file.print(now.year(), DEC;
    file.print(now.month(), DEC;
    file.print(now.day(), DEC;
    file.print(now.hour(), DEC;
    file.println(now.minute(), DEC;
    Serial.print(now.year(), DEC;
    Serial.print(now.month(), DEC;
    Serial.print(now.day(), DEC;
    Serial.print(' ';
    Serial.print(now.hour(), DEC;
    Serial.println(now.minute(), DEC;
    Serial.println("SD written on card");
    userCheckInHour = now.hour();
    userCheckInMinute = now.minute();
  else {
    Serial.println("data.txt emergency ");  
void verifyCheckIn(){
  if((userCheckInHour < checkInHour)||((userCheckInHour==checkInHour) && (userCheckInMinute <= checkInMinute))){
    digitalWrite(greenLED, HIGH);
    digitalWrite(redLED, HIGH);

Reading Data from an SD Card

After running the circuit and reading a few cards, the data will be written sequencing in the text file data.txt in the SD Card. You can check it by opening it with your favorite text editor. arduino rfid polling