Tag & Track: Automating Attendance with RFID and ESP8266

Smart RFID-Arduino system automates attendance for better accuracy, speed, and data integrity.

BeginnerShowcase (no instructions)6 hours86
Tag & Track: Automating Attendance with RFID and ESP8266

Things used in this project

Hardware components

Jumper wires (generic)
Jumper wires (generic)
×1
RFID Module (Generic)
×1
I2C 16x2 Arduino LCD Display Module
DFRobot I2C 16x2 Arduino LCD Display Module
×1
ESP8266 ESP-01
Espressif ESP8266 ESP-01
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit Diagram

Code

RFID ACCESS STATUS CODE

C/C++
With the help of this code we are able to check the attendance
#include <LiquidCrystal_I2C.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <SPI.h>
#include <MFRC522.h>
#include <Wire.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <WiFiClientSecure.h>

// Pin Definitions
#define RST_PIN D3
#define SS_PIN  D4
#define BUZZER_PIN D8

// RFID and LCD setup
MFRC522 mfrc522(SS_PIN, RST_PIN);
LiquidCrystal_I2C lcd(0x27, 16, 2);

// WiFi and Time setup
const char* ssid = "Galaxy A20s0282";
const char* password = "11111111";
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", 19800, 60000);  // UTC+5:30 IST

// Google Apps Script Web App URL
const char* scriptURL = "https://script.google.com/macros/s/AKfycby9knx2c7ZFVSxRpTKKD5a_eLClFWvXhVOf0W0_piuv5d_BXVu5w4--1xEaFBZsqWyv0Q/exec";

// Allowed UIDs
String allowedUIDs[] = {"12345678", "FoD60F949"};  
String getNameFromUID(String uid) {
  if (uid == "FD60F949") return "hamlin";
  // Add more mappings here if needed
  return "Unknown";
}
// Use uppercase UIDs

void setup() {
  Serial.begin(115200);
  SPI.begin();
  mfrc522.PCD_Init();
  pinMode(BUZZER_PIN, OUTPUT);
  digitalWrite(BUZZER_PIN, LOW);

  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Connecting WiFi");

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  lcd.clear();
  lcd.print("WiFi Connected");
  delay(1000);
  lcd.clear();
  lcd.print("Scan RFID Tag");

  timeClient.begin();
  Serial.println("System Ready: Scan RFID");
}

void loop() {
  timeClient.update();

  if (!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial())
    return;

  String uid = getUID();
  uid.toUpperCase();  // Ensure consistent UID format
  Serial.print("Scanned UID: ");
  Serial.println(uid);

  String name = getNameFromUID(uid);
  String nameWithUID = name + " (" + uid + ")";

  String timeStr = timeClient.getFormattedTime(); // HH:mm:ss
  String dateStr = getDate();                     // Custom date format

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("UID: " + uid);
  lcd.setCursor(0, 1);
  lcd.print(timeStr);
  delay(1000);

  if (isAccessGranted(uid)) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Access Granted");

    Serial.println("Access Granted");
    sendToGoogleSheet(nameWithUID, dateStr, timeStr);

  } else {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Access Denied!");
    Serial.println("Access Denied");
    tone(BUZZER_PIN, 1000, 500);  // 500ms beep
  }

  delay(3000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Scan RFID Tag");

  mfrc522.PICC_HaltA();
  mfrc522.PCD_StopCrypto1();
}

// -----------------------------
// Get UID as uppercase string
String getUID() {
  String uid = "";
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    if (mfrc522.uid.uidByte[i] < 0x10) uid += "0";
    uid += String(mfrc522.uid.uidByte[i], HEX);
  }
  uid.toUpperCase(); 
  return uid; 
}

// -----------------------------
// Check UID against allowed list
bool isAccessGranted(String uid) {
  for (String allowed : allowedUIDs) {
    if (uid == allowed)
      return true;
  }
  return false;
}

// -----------------------------
// Send UID, Date, Time to Google Sheet
void sendToGoogleSheet(String nameWithUID, String dateStr, String timeStr) {
  WiFiClientSecure client;
  client.setInsecure();

  HTTPClient http;
  http.setFollowRedirects(HTTPC_FORCE_FOLLOW_REDIRECTS);
  http.begin(client, scriptURL);
  http.addHeader("Content-Type", "application/x-www-form-urlencoded");

  // Send nameWithUID under 'uid' column
  String postData = "uid=" + nameWithUID + "&date=" + dateStr + "&time=" + timeStr;
  Serial.println("POST data: " + postData);

  int httpCode = http.POST(postData);

  if (httpCode > 0) {
    String payload = http.getString();
    Serial.println("POST Success: " + payload);
  } else {
    Serial.println("POST Failed. Error: " + http.errorToString(httpCode));
  }

  http.end();
}


// -----------------------------
// Generate date in dd-mm-yyyy format
String getDate() {
  time_t rawTime = timeClient.getEpochTime();
  struct tm* timeInfo = localtime(&rawTime);

  char dateBuffer[11];
  sprintf(dateBuffer, "%02d-%02d-%04d", timeInfo->tm_mday, timeInfo->tm_mon + 1, timeInfo->tm_year + 1900);
  return String(dateBuffer);
}

Credits

Joseph Hamlin
1 project • 1 follower
muhammad sadiq k
1 project • 1 follower
Nadish
1 project • 1 follower
Vismaya Haridas
1 project • 1 follower

Comments