Creating an RFID Based Attendance Logger

by yuvrajkaniyar in Circuits > Arduino

137 Views, 1 Favorites, 0 Comments

Creating an RFID Based Attendance Logger

WhatsApp Image 2024-12-05 at 12.07.10_9a63a555.jpg
WhatsApp Image 2024-12-05 at 12.07.09_3522e954.jpg

This project implements a Radio-Frequency Identification (RFID) based system to streamline and automate attendance logging. The system reads unique RFID card IDs and logs them into a Google Sheet using a Google Apps Script Web App. It eliminates the need for manual record-keeping and provides a reliable, scalable, and cloud-based solution for attendance tracking.

Key Features:

  1. RFID Technology: Utilizes an RFID reader (e.g., MFRC522) to identify individuals through unique card IDs.
  2. Wi-Fi Connectivity: Connects the hardware to the internet using a microcontroller (ESP8266/ESP32) to communicate with the cloud.
  3. Google Sheets Integration: Logs attendance data (card ID and timestamp) directly into a Google Sheet for easy access and management.
  4. Automation: Attendance logging is fully automated and requires no manual intervention after setup.
  5. Scalability: The cloud-based logging mechanism supports multiple users and easy data analysis.


Set Up the Hardware

1. Set Up the Hardware

  1. Connect the RFID reader to the microcontroller.
  2. Write an Arduino sketch to read the RFID card's unique ID.
  3. Include a Wi-Fi connection script (if using ESP8266/ESP32) to send the data to a Google Apps Script endpoint.
  4. White LED: Connect one end to a GPIO pin (e.g., D5) of the ESP8266/ESP32 and the other to GND via a resistor (220Ω).
  5. Red LED: Connect one end to another GPIO pin (e.g., D6) of the ESP8266/ESP32 and the other to GND via a resistor (220Ω).

Sample Arduino Code (Using ESP8266/ESP32):

#include <SPI.h>
#include <MFRC522.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

// Pins for RFID
#define RST_PIN D1 // Reset pin
#define SS_PIN D2 // Slave Select pin

// LED Pins
#define GREEN_LED D5
#define RED_LED D6

MFRC522 rfid(SS_PIN, RST_PIN);

// Wi-Fi credentials
const char* ssid = "Your_WiFi_SSID"; // Replace with your Wi-Fi SSID
const char* password = "Your_WiFi_Password"; // Replace with your Wi-Fi password

// Google Apps Script URL
const char* googleScriptURL = "https://script.google.com/macros/s/yourscripturl"; // Enter your script url

void setup() {
Serial.begin(9600); // Initialize Serial Monitor
SPI.begin(); // Initialize SPI bus
rfid.PCD_Init(); // Initialize RFID reader

// Initialize LED pins
pinMode(GREEN_LED, OUTPUT);
pinMode(RED_LED, OUTPUT);
digitalWrite(GREEN_LED, LOW);
digitalWrite(RED_LED, LOW);

Serial.println("Connecting to Wi-Fi...");
WiFi.begin(ssid, password);

// Wait for Wi-Fi connection
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("\nWi-Fi Connected!");
}

void loop() {
// Check if an RFID card is present
if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) {
return;
}

// Read the RFID card's UID
String cardID = "";
for (byte i = 0; i < rfid.uid.size; i++) {
cardID += String(rfid.uid.uidByte[i], HEX);
}
cardID.toUpperCase();

Serial.println("Card ID: " + cardID);

// Send the card ID to Google Apps Script
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
String url = String(googleScriptURL) + "?cardID=" + cardID;
http.begin(url);

int httpResponseCode = http.GET();
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println("Response: " + response);

// Turn on the green LED for success
digitalWrite(GREEN_LED, HIGH);
delay(1000); // Keep the LED on for 1 second
digitalWrite(GREEN_LED, LOW);
} else {
Serial.println("Error: Unable to send data");

// Turn on the red LED for failure
digitalWrite(RED_LED, HIGH);
delay(1000); // Keep the LED on for 1 second
digitalWrite(RED_LED, LOW);
}
http.end();
} else {
Serial.println("Wi-Fi Disconnected!");

// Blink the red LED to indicate Wi-Fi issue
for (int i = 0; i < 3; i++) {
digitalWrite(RED_LED, HIGH);
delay(200);
digitalWrite(RED_LED, LOW);
delay(200);
}
}

// Halt RFID reading until the next card
rfid.PICC_HaltA();
}


Create Google Apps Script

WhatsApp Image 2024-12-05 at 12.21.34_7fb61c80.jpg
WhatsApp Image 2024-12-05 at 12.22.15_735505d3.jpg
WhatsApp Image 2024-12-05 at 12.22.46_e0702864.jpg
  1. Open a Google Sheet for logging attendance.
  2. Go to Extensions > Apps Script.
  3. Paste the following script:
//javascript
//Copy code
function doGet(e) {
// Get the RFID card ID from the URL parameter
var cardID = e.parameter.cardID;

if (!cardID) {
return ContentService.createTextOutput("Missing cardID");
}

// Open the active Google Sheet
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();

// Get the current timestamp
var timestamp = new Date();

// Log the card ID and timestamp
sheet.appendRow([timestamp, cardID]);

return ContentService.createTextOutput("Attendance logged for cardID: " + cardID);
}


Save and Deploy the Script:

WhatsApp Image 2024-12-05 at 12.25.33_38c050ca.jpg
WhatsApp Image 2024-12-05 at 12.24.16_ced50ad2.jpg
WhatsApp Image 2024-12-05 at 12.30.28_6ea74176.jpg
  1. Click on Deploy > New Deployment.
  2. Select Web app.
  3. Set Anyone with the link as the access level.
  4. Copy the Web app URL and use it in the Arduino code.

Test the System

WhatsApp Image 2024-12-05 at 12.07.09_3522e954.jpg
WhatsApp Image 2024-12-05 at 12.07.09_b7632842.jpg
WhatsApp Image 2024-12-05 at 12.43.44_1b7a8ecd.jpg
  1. Power up the RFID system and ensure it connects to Wi-Fi.
  2. Scan an RFID card.
  3. Check if the card's unique ID and timestamp are logged in the Google Sheet ( Here I am used NFC since resource was unavailable).


How It Works:

  1. White LED (D5):
  2. Lights up for 1 second if the card ID is successfully logged in the Google Sheet.
  3. Red LED (D6):
  4. Lights up for 1 second if there’s an error in sending the data.
  5. Blinks three times if the device is disconnected from Wi-Fi.

Next Steps:

  1. Hardware:
  2. Connect the LEDs and resistors to the specified GPIO pins.
  3. Testing:
  4. Scan an RFID card and observe the LED behavior:
  5. White LED: Successful attendance logging.
  6. Red LED: Error or Wi-Fi issues.


Conclusion

This project provides an efficient and automated solution for attendance tracking using RFID technology and Google Sheets. By integrating an RFID reader with an ESP8266/ESP32 microcontroller, you can scan RFID cards and automatically log the attendance data into a Google Sheet via a Google Apps Script web app. The addition of LEDs offers immediate feedback for system status, helping users understand whether the attendance logging was successful or if there were any issues (e.g., Wi-Fi disconnection or errors).


Key Takeaways:

  1. Automated Attendance: Reduces manual effort and ensures real-time attendance tracking.
  2. Cloud Integration: Utilizes Google Sheets for easy access, analysis, and storage of data.
  3. Scalability: Ideal for schools, offices, or events, and can be expanded to include additional features like user names or status tracking.
  4. Ease of Use: Simple setup with clear visual feedback using LEDs.

With this solution, you can efficiently manage attendance with minimal human intervention and have a cloud-based log that’s accessible from anywhere.