How to Use an ESP8266 Smart Classroom Attendance System in Lahore, Pakistan

An ESP8266 smart classroom attendance system uses Wi-Fi to automate student attendance. Each student taps an RFID card on the reader, the NodeMCU reads the card's ID, and the record goes straight to a Firebase cloud database with the real date and time — no registers, no manual counting. Teachers can check attendance from a mobile or PC.

It is a student and final year project — a working system you can demonstrate in a real classroom with a few cards.

ESP8266 Smart Classroom Attendance System Circuit Diagram

How the System Works

  1. A student taps an RFID card or tag on the RC522 reader.
  2. The NodeMCU reads the card's unique ID (UID) over SPI.
  3. The NodeMCU gets the real date and time from the internet (NTP, Pakistan time).
  4. The record is sent to Firebase Realtime Database under /Attendance/<card UID>/.
  5. The LCD shows the card ID and "Marked OK" so the student gets instant confirmation.

Main Components Needed

  • ESP8266 NodeMCU
  • RFID reader (RC522) with cards/tags
  • 16×2 LCD with I2C module (address 0x27)
  • Jumper wires
  • Breadboard
  • 5V power source (USB adapter or power bank)
  • Firebase account (free)

Circuit Diagram Overview

RC522 PinNodeMCU Pin
VCC3.3V (not 5V — the RC522 is a 3.3V module)
GNDGND
SDA (SS)D4
SCKD5
MOSID7
MISOD6
RSTD8
LCD PinNodeMCU Pin
SDAD2
SCLD1
VCC / GND5V / GND
ComponentPrice / link
ESP8266 NodeMCUNodeMCU ESP8266 CH340 WiFi Board — Rs 590
40-Pin Jumper Wires 30cm40-Pin Jumper Wires 30cm — Rs 180
MB102 BreadboardMB102 Breadboard 830 Points — Rs 250

The RC522 RFID reader, RFID cards/tags, 16×2 LCD and 5V power source do not have individual listings in the QKZEE shop — they are available at the Hall Road shop on request.

Set Up Firebase (Free)

  1. Go to console.firebase.google.com and click Add project. Name it (for example classroom-attendance) and continue. Google Analytics is optional — you can skip it.
  2. In the left menu, go to Build → Realtime Database → Create database. Choose a location and start in test mode (fine for a student demo — note that test-mode rules expire after 30 days).
  3. Copy the database URL from the Realtime Database page — it looks like https://classroom-attendance-default-rtdb.firebaseio.com.
  4. Go to Project settings (gear icon) → General → Your apps → Web app (</>), register the app, and copy the Web API Key (apiKey).
  5. Go to Build → Authentication → Sign-in method and enable Anonymous sign-in (the sketch signs in anonymously, so the database rules can stay locked to signed-in users).
  6. Paste the API key and database URL into the sketch where marked.

Required Libraries

Install these from the Arduino IDE Library Manager (Sketch → Include Library → Manage Libraries):

  • Firebase Arduino Client Library for ESP8266 and ESP32 by Mobizt (the current Firebase library — header Firebase_ESP_Client.h)
  • MFRC522 by GithubCommunity
  • LiquidCrystal I2C by Frank de Brabander

Complete Arduino Code

/*
  ESP8266 Smart Classroom Attendance System
  Board: NodeMCU ESP8266 (ESP-12E).
  RC522 RFID reader (SPI) + 16x2 I2C LCD + Firebase Realtime Database.
  On each card tap: reads the card UID, gets the real date and time
  from NTP, and stores the record under /Attendance/<UID>/ in Firebase.
*/

#include <ESP8266WiFi.h>
#include <Firebase_ESP_Client.h>
#include <SPI.h>
#include <MFRC522.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <time.h>

// ---- Replace these with your own ----
const char* WIFI_SSID = "YOUR_WIFI_NAME";
const char* WIFI_PASS = "YOUR_WIFI_PASSWORD";
#define API_KEY "YOUR_FIREBASE_WEB_API_KEY"
#define DATABASE_URL "https://YOUR-PROJECT-ID.firebaseio.com"

#define SS_PIN D4
#define RST_PIN D8

MFRC522 mfrc522(SS_PIN, RST_PIN);
LiquidCrystal_I2C lcd(0x27, 16, 2);

FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;

String getRFID() {
  String uidString = "";
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    if (mfrc522.uid.uidByte[i] < 0x10) uidString += "0";
    uidString += String(mfrc522.uid.uidByte[i], HEX);
  }
  uidString.toUpperCase();
  return uidString;
}

String getDateTime() {
  // Pakistan time (UTC+5) from NTP
  time_t now = time(nullptr);
  struct tm* t = localtime(&now);
  char buf[20];
  strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", t);
  return String(buf);
}

void setup() {
  Serial.begin(115200);
  SPI.begin();
  mfrc522.PCD_Init();

  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Attendance System");
  lcd.setCursor(0, 1);
  lcd.print("Starting...");
  delay(2000);
  lcd.clear();

  WiFi.begin(WIFI_SSID, WIFI_PASS);
  Serial.print("Connecting to WiFi");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("\nWiFi connected!");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  // Real date and time from the internet (Pakistan, UTC+5)
  configTime(5 * 3600, 0, "pool.ntp.org", "time.nist.gov");

  // Firebase setup (current library: Firebase_ESP_Client)
  config.api_key = API_KEY;
  config.database_url = DATABASE_URL;
  // Anonymous sign-in, so the database rules can stay locked to signed-in users
  if (Firebase.signUp(&config, &auth, "", "")) {
    Serial.println("Firebase sign-up OK");
  } else {
    Serial.println("Firebase sign-up failed");
  }
  Firebase.begin(&config, &auth);
  Firebase.reconnectWiFi(true);

  lcd.setCursor(0, 0);
  lcd.print("System Ready!");
  lcd.setCursor(0, 1);
  lcd.print("Scan RFID Card...");
  Serial.println("System Ready! Scan RFID Card...");
}

void loop() {
  if (!mfrc522.PICC_IsNewCardPresent()) return;
  if (!mfrc522.PICC_ReadCardSerial()) return;

  String cardID = getRFID();
  String dateTime = getDateTime();

  Serial.print("Card Detected: ");
  Serial.println(cardID);

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Card: ");
  lcd.print(cardID);

  String path = "/Attendance/" + cardID;
  if (Firebase.RTDB.setString(&fbdo, path + "/time", dateTime)) {
    Serial.println("Attendance Marked Successfully!");
    lcd.setCursor(0, 1);
    lcd.print("Marked OK");
  } else {
    Serial.print("Error: ");
    Serial.println(fbdo.errorReason());
    lcd.setCursor(0, 1);
    lcd.print("Upload failed!");
  }

  mfrc522.PICC_HaltA();
  delay(1500);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("System Ready!");
  lcd.setCursor(0, 1);
  lcd.print("Scan RFID Card...");
}

What This Code Does

  • Connects the NodeMCU to Wi-Fi
  • Reads the RFID card UID (with each byte padded, so 0A stays 0A and not just A)
  • Gets the real date and time from NTP (Pakistan time, UTC+5)
  • Sends the UID + date-time to Firebase at /Attendance/<UID>/time
  • Shows the card ID and "Marked OK" on the LCD — this sketch actually drives the LCD, which the old version claimed but never did

Each new tap from the same card updates that card's latest time. For a full history of every tap, use Firebase.RTDB.pushString() instead of setString() — see the FAQs.

Testing the System

  1. Test the LCD first. Upload the sketch. The LCD should show "Attendance System" then "System Ready! Scan RFID Card...". If it stays blank, check SDA → D2, SCL → D1, and try I2C address 0x3F if 0x27 shows nothing.
  2. Test Wi-Fi. The Serial Monitor should show "WiFi connected!" and an IP address. If it never connects, check the Wi-Fi name and password (both are case-sensitive) and use a 2.4 GHz network — the ESP8266 does not connect to 5 GHz Wi-Fi.
  3. Test a card tap. Tap a card on the reader. The Serial Monitor should show "Card Detected: ..." and "Attendance Marked Successfully!", and the LCD should show the card ID and "Marked OK".
  4. Check Firebase. Open your Realtime Database in the Firebase console — a record should appear under /Attendance/<card UID>/time with the real date and time.

Troubleshooting

  • LCD shows nothing: check SDA → D2, SCL → D1, and try I2C address 0x3F if 0x27 shows nothing.
  • Card not detected: check the RC522 wiring (SDA → D4, SCK → D5, MOSI → D7, MISO → D6, RST → D8) and that VCC is on 3.3V, not 5V. Hold the card flat against the reader, 1–2 cm away.
  • Wi-Fi never connects: check the Wi-Fi name and password, and use a 2.4 GHz network — the ESP8266 does not connect to 5 GHz Wi-Fi.
  • "Firebase sign-up failed": Anonymous sign-in is not enabled — go to Firebase console → Authentication → Sign-in method → enable Anonymous. Also check the API key and database URL are pasted correctly.
  • "Upload failed!": check the database URL (it must be the full https://...firebaseio.com address) and that the database is in test mode or its rules allow signed-in writes.
  • Wrong date/time in Firebase: the NTP servers could not be reached — check the Wi-Fi connection, and give the board a few seconds after connecting before the first tap.

Applications

  • School and college attendance — one reader at the classroom door
  • Student and final year projects — a complete RFID + Wi-Fi + cloud system
  • Small office attendance demo — a low-cost check-in system
  • Final year project base — add a web dashboard, student names per card, or daily reports on top

Where to Buy the Components

The NodeMCU board, jumper wires and breadboard are available at QKZEE Technologies, Shop 20, 1st Floor, Al-Khalil Center, Hall Road, Lahore, and online at qkzeetech.com with delivery all over Pakistan — see the links above. The RC522 RFID reader, RFID cards/tags, 16×2 LCD and 5V power source are available at the Hall Road shop on request.

Still Stuck?

If the card is not detected, or Firebase stays empty, message us — tell us what the Serial Monitor shows and which step you are on, and we will help you find the fault.

Chat on WhatsApp Watch on YouTube

FAQs

Can I use an Arduino Uno for this project?

No. The upload needs Wi-Fi, and the Uno has no Wi-Fi. Use the NodeMCU ESP8266 as shown in this guide.

Why does the old Firebase code not work any more?

The old code used the legacy FIREBASE_HOST / FIREBASE_AUTH (database secret) API. Firebase no longer lets new projects create database secrets, so that method does not work for a new project. This guide uses the current Firebase library with a Web API key and anonymous sign-in.

Can the RC522 run on 5V?

No. The RC522 is a 3.3V module — connect its VCC to the NodeMCU's 3.3V pin. Powering it from 5V can damage it.

How do I see the attendance records?

Open your project in the Firebase console → Realtime Database. Records appear under /Attendance/<card UID>/time with the real date and time of each card's latest tap.

Can I keep a full history of every tap instead of just the latest time?

Yes. Replace Firebase.RTDB.setString(&fbdo, path + "/time", dateTime) with Firebase.RTDB.pushString(&fbdo, path, dateTime) — each tap then creates a new entry under the card's path instead of overwriting the last one.

Does this work without the LCD?

Yes — the LCD is only for instant confirmation. The attendance still goes to Firebase without it. Just remove the LCD lines from the sketch (or leave the LCD code in and fit the display later).

Where can I buy the parts in Pakistan?

From QKZEE Technologies on Hall Road, Lahore, or online at qkzeetech.com with Cash on Delivery across Pakistan — see the component links above.

Conclusion

Building an ESP8266 smart classroom attendance system with an RC522 RFID reader and Firebase is a strong final year project: it combines RFID sensing, Wi-Fi, real date-time handling and a cloud database in one working system. Follow the wiring above, set up Firebase as shown, and you will have live attendance records in the cloud to show your teachers and judges.