RFID Based Attendance System Using NodeMCU with PHP web app

RFID Based Attendance System Using NodeMCU with PHP Web App

IoT Projects

Overview

The RFID based attendance system is developed using PHP, CSS, and Javascript. An RFID Based Attendance System Using NodeMCU is a modern attendance system. Hence, is a very interesting project. It can be useful in different places like schools, Colleges, industry and private organizations to register the attendance of students, teachers, employees, etc. to tabulate monthly/daily working hours automatically. When the person with the correct RFID card swipes his/her RFID tag, His/Her arrival time will be stored in system Log. Usually, when the same person swipes his/her RFID tag again, the system will save it as his/her leaving time. 

RFID Based Attendance System Using NodeMCU with PHP web app
RFID Based Attendance System Using NodeMCU with PHP Web App

The RFID attendance system is developed with the IoT platform. We have used NodeMCU ESP8266 development board with MF-RC522 Module to send the card UID to the PHP Web app and store data into the website database. Basically, the admin plays an important role in the management of this system.

Also Read: IoT based RFID Attendance System Using ESP32, OLED Display, and RFID Module

Features:

-Secured Login System
-Admin Panel
-User Entry Log
-User Management System
-Multiple Device Management System
-Filter the Log Data by Date, Time-In, Time-Out, and Department
-Export those filtered data to Excel

Functionality Performed by users

Now, talking about the features of the RFID based attendance system using NodeMCU.The home page displays the admin login page. Unless You login to the system, you won’t be able to browse other available options. Hence the system is secured. Basically, the design of the RFID attendance system project is pretty simple. Hence the user won’t find any difficulties while enrolling his/her attendance. The user needs to swipe his/her card or a keychain to maintain attendance that includes the entry time as well. The major functions provided to admin are mentioned below:

RFID Based Attenance System Using NodeMCU
Admin Panel Login System
  • Admin Login/Logout System 
  • Forgot Password for admin
  • Edit and Update admin profile
RFID Based Attenance System Using NodeMCU Admin account reset
Reset Admin Account Password

Manage Users

RFID Based Attenance System Using NodeMCU Users
View and Manage Users
  • View users
  • Add New User
  • Edit and update the existing users
  • Remove Users
Manages Users for RFID Based Attenance System Using NodeMCU
User Management System

From the admin panel, the admin can enroll new users, update and remove users from the user management system. Further, the admin can view all the attendance records.

User Manager on RFID Based Attenance System Using NodeMCU
Enroll New Users/Update/Remove

Manage Device

RFID based Device Management System
Device Management System
  • Add new device
  • Update existing device
  • Delete device
  • Update New token to the device
  • Change the device mode (Enrollment mode: to register new users to the system, Attendance Mode: To record attendance of registered users)
Add New RFID Scanner Device
Add New RFID Scanner Device

Actually, from the devices section admin can add a new device, update the device, and remove the device. To add a new device you need to enter a device name and its department. Furthermore, you can also update the device token from the device UID Section.

View Users Log

View Users log on RFID Based Attenance System Using NodeMCU
View Users log on RFID Based Attenance System

From the user log menu, you can navigate to all the user’s logs data. You can view their arrival and Leaving time as well. Furthermore, It has more functions to filter your logs by user, date, arrival time, leaving time, and filter by different departments, etc. Hence, you can also export those data to excel. 

Filter Users Log on RFID Based Attenance
Filter Users Log to export

Hardware Components Required

  • NodeMcu ESP8266
  • RFID-RC522 Module
  • Jumper Wires
  • Micro USB Cable
  • Mini Breadboard (optional)

Software Required with Download Links

Technology Used in RFID attendance System Using NodeMCU

Here we are listing all the major required software components for this project to develop the user interface.

  1. Embedded C: All the hardware interface coding has been done in embedded C Language.
  2. PHP: All the Logics and web interface is written in PHP Language.
  3. MYSQL: For database, MYSQL Database is used.
  4. Apache 2: To run the web interface over the Apache 2 server.
  5. Javascript and CSS: To Style web Interface with animation and validate the form.

RFID Based Attendance System Network Topology

This is the simple network topology designed to run this project over a Local Area Network. The Project Device and Computer server are connected to the same network through WiFi. 

RFID Based Attendance System Network Topology
RFID Based Attendance System Network Topology

Now before getting started with this project, let’s learn What is RFID? with its specifications and Features.

RFID RC522 Module

What is RFID RC522 Module?

At first, let’s learn a little bit about RFID. RFID is the short form of Radio Frequency Identification. RFID modules use electromagnetic fields for transferring data between the card and the reader. Different RFID tags are attached to objects like Keychain, cards, etc. and whenever we place that object in front of the RFID reader, the reader reads that tags. The next benefit of RFID is that it doesn’t require to be in a straight line to get detected. Unlike a barcode, in RFID there’s no such restriction. So, here are some features of RFID RC522.

Interface RFID to PHP & MySQL Database with NodeMcu ESP8266
RFID MF-RC522 Module

Features:

– Module Name: MF522-ED
– Working current:13—26mA/ DC 3.3V
– Standby current:10-13mA/DC 3.3V
– Sleeping current:<80uA
– Peak current:<30mA
– Working frequency:13.56MHz
– Card reading distance :0~60mm(mifare1 card)
– Protocol:SPI
– Data communication speed:Maximum 10Mbit/s
– Card types supported:mifare1 S50、mifare1 S70、 Mifare UltraLight、mifare Pro、 Mifare Desfire
– Dimension:40mm×60mm
– Working temperature:-20—80 degree
– Storage temperature:-40—85 degree
– Humidity:relevant humidity 5%—95%
– Max SPI speed: 10Mbit/s

Specifications & Pin Details

The simple specifications of RC522 module from left to right first pins are as follows:

Pin Name Details
1. 3.3V +3.3V Power Supply
2. RST Reset
3. GND Ground Pin
4. IRO Not Connected
5. MISO Serial Communication
6. MOSI Serial Communication
7. SCK TX/RX with ESP8266
8. SDA TX/RX with ESP8266
Connect RFID to PHP & MySQL Database with NodeMcu ESP8266
NodeMcu ESP8266 Pinouts

Interfacing RFID RC522 with NodeMcu ESP8266 Module

NodeMCU ESP8266/ESP12E RFID MFRC522 / RC522

D2 <———-> SDA/SS

D5 <———-> SCK

D7 <———-> MOSI

D6 <———-> MISO

GND <———-> GND

D1 <———-> RST

3V/3V3 <———-> 3.3V

Connect RFID to PHP & MySQL Database with NodeMcu ESP8266
Interfacing RFID RC522 with NodeMcu ESP8266 Module

How to run a server?

Actually, we can Deploy this PHP Web App on Hosting Server as well. But, you will need Public IP from Your Broadband connections to send data to the hosting server.

However, we are using the XAMPP server. It can be used both in Windows and Linux. Basically, Ubuntu users can use LAMP it’s better than XAMPP. But, I am using Windows so I am going to use the XAMPP server. So you can download the XAMPP server from this link.

Deploying our PHP Web App

  • Start your Mysql and Apache from XAMPP Control Panel.
Xampp server for windows
  • Download the PHP web app and the Arduino IDE Program code.
  • Extract the file.
  • Copy the rfidattendance folder (Main Project folder).
  • Paste the folder in C:\>xampp/htdocs/ folder.

Now let’s connect the database to the RFID attendance system.

Database
  • Create a database name “rfidattendance” and then click on the import tab.
create rfidattendance database
  • Click on the browse file and then choose the “rfidattendance.sql” file located inside the rfidattendance folder.
select rfidattendance sql file
  • Click on Go.

After creating a database, open a browser and go to the URL “http://localhost/rfidattenddance/”. Now, the admin login panel will be displayed.

RFID Based Attenance System Using NodeMCU
Admin Panel Login System
  • Enter the admin email and password to enter the system.
  • The default admin credentials is: email= [email protected], and password= 123.

Setting Up Arduino IDE for NodeMCU ESP8266

We need to add the esp8266 board to our Arduino IDE. Open up your IDE then go to “File -> Preferences” or simply hit “Ctrl + comma”.

Connect NodeMcu ESP8266

Paste http://arduino.esp8266.com/stable/package_esp8266com_index.json in additional board manager URLs. 

Go to “Tools -> Board -> Boards Manager” search and install esp8266.

Connect RFID to NodeMcu ESP8266

Selecting Port and Board

Go to Tools -> Port and select the COM Port of your NodeMCU. If you are not sure what port your NodeMcu is plugged in, go to Device Manager -> Ports (COM & LPT).

selecting esp8266 board and COM Port

Now select NodeMcu 1.0 (ESP-12E Module) by clicking Tools -> Board. Scroll down until you find it.

Install the MFRC522 library to your Arduino Libraries folder – Download RFID Library

Program/Sketch Code

//*******************************libraries********************************
//RFID-----------------------------
#include <SPI.h>
#include <MFRC522.h>
//NodeMCU--------------------------
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
//************************************************************************
#define SS_PIN  D2  //D2
#define RST_PIN D1  //D1
//************************************************************************
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
//************************************************************************
/* Set these to your desired credentials. */
const char *ssid = "Alsan Air WiFi 4";
const char *password = "[email protected]";
const char* device_token  = "2c4f3c61aa79d533";
//************************************************************************
String URL = "http://192.168.1.8/rfidattendance/getdata.php"; //computer IP or the server domain
String getData, Link;
String OldCardID = "";
unsigned long previousMillis = 0;
//************************************************************************
void setup() {
  delay(1000);
  Serial.begin(115200);
  SPI.begin();  // Init SPI bus
  mfrc522.PCD_Init(); // Init MFRC522 card
  //---------------------------------------------
  connectToWiFi();
}
//************************************************************************
void loop() {
  //check if there's a connection to Wi-Fi or not
  if(!WiFi.isConnected()){
    connectToWiFi();    //Retry to connect to Wi-Fi
  }
  //---------------------------------------------
  if (millis() - previousMillis >= 15000) {
    previousMillis = millis();
    OldCardID="";
  }
  delay(50);
  //---------------------------------------------
  //look for new card
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return;//got to start of loop if there is no card present
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;//if read card serial(0) returns 1, the uid struct contians the ID of the read card.
  }
  String CardID ="";
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    CardID += mfrc522.uid.uidByte[i];
  }
  //---------------------------------------------
  if( CardID == OldCardID ){
    return;
  }
  else{
    OldCardID = CardID;
  }
  //---------------------------------------------
//  Serial.println(CardID);
  SendCardID(CardID);
  delay(1000);
}
//************send the Card UID to the website*************
void SendCardID( String Card_uid ){
  Serial.println("Sending the Card ID");
  if(WiFi.isConnected()){
    HTTPClient http;    //Declare object of class HTTPClient
    //GET Data
    getData = "?card_uid=" + String(Card_uid) + "&device_token=" + String(device_token); // Add the Card ID to the GET array in order to send it
    //GET methode
    Link = URL + getData;
    http.begin(Link); //initiate HTTP request   //Specify content-type header
    
    int httpCode = http.GET();   //Send the request
    String payload = http.getString();    //Get the response payload

//    Serial.println(Link);   //Print HTTP return code
    Serial.println(httpCode);   //Print HTTP return code
    Serial.println(Card_uid);     //Print Card ID
    Serial.println(payload);    //Print request response payload

    if (httpCode == 200) {
      if (payload.substring(0, 5) == "login") {
        String user_name = payload.substring(5);
    //  Serial.println(user_name);

      }
      else if (payload.substring(0, 6) == "logout") {
        String user_name = payload.substring(6);
    //  Serial.println(user_name);
        
      }
      else if (payload == "succesful") {

      }
      else if (payload == "available") {

      }
      delay(100);
      http.end();  //Close connection
    }
  }
}
//********************connect to the WiFi******************
void connectToWiFi(){
    WiFi.mode(WIFI_OFF);        //Prevents reconnection issue (taking too long to connect)
    delay(1000);
    WiFi.mode(WIFI_STA);
    Serial.print("Connecting to ");
    Serial.println(ssid);
    WiFi.begin(ssid, password);
    
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }
    Serial.println("");
    Serial.println("Connected");
  
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());  //IP address assigned to your ESP
    
    delay(1000);
}
//=======================================================================

Program Code Explanation

Include RFID Library

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

Include NodeMCU ESP8266 Library files.

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

Define RFID MF-RC522 Module Pin.

#define SS_PIN  D2  //D2
#define RST_PIN D1  //D1

Create MFRC522 instance.

MFRC522 mfrc522(SS_PIN, RST_PIN);

Set your desired WiFi credentials.

const char *ssid = "Alsan Air WiFi 4";
const char *password = "[email protected]";

Copy the Device token from devices section and paste it over here.

const char* device_token  = "2c4f3c61aa79d533";

Place your computer IP or the server domain.

String URL = "http://192.168.1.8/rfidattendance/getdata.php";

Init SPI bus and MFRC522 card

SPI.begin(); 
mfrc522.PCD_Init();

check if there’s a connection to Wi-Fi or not.

if(!WiFi.isConnected())
  

Retry to connect to Wi-Fi

 connectToWiFi();

look for new card

if ( ! mfrc522.PICC_IsNewCardPresent()) {

go to start of loop if there is no card present

if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return;

Select one of the cards. If read card serial(0) returns 1, the UID struct contains the ID of the read card.

if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;

Send the Card UID to the website.

void SendCardID( String Card_uid ){
  Serial.println("Sending the Card ID");
  if(WiFi.isConnected()){
    HTTPClient http;    //Declare object of class HTTPClient
    //GET Data
    getData = "?card_uid=" + String(Card_uid) + "&device_token=" + String(device_token); // Add the Card ID to the GET array in order to send it
    //GET methode
    Link = URL + getData;
    http.begin(Link); //initiate HTTP request   //Specify content-type header
    
    int httpCode = http.GET();   //Send the request
    String payload = http.getString();    //Get the response payload

//    Serial.println(Link);   //Print HTTP return code
    Serial.println(httpCode);   //Print HTTP return code
    Serial.println(Card_uid);     //Print Card ID
    Serial.println(payload);    //Print request response payload

    if (httpCode == 200) {
      if (payload.substring(0, 5) == "login") {
        String user_name = payload.substring(5);
    //  Serial.println(user_name);

      }
      else if (payload.substring(0, 6) == "logout") {
        String user_name = payload.substring(6);
    //  Serial.println(user_name);
        
      }
      else if (payload == "succesful") {

      }
      else if (payload == "available") {

      }
      delay(100);
      http.end();  //Close connection
    }
  }
}

connect to the WiFi

void connectToWiFi(){
    WiFi.mode(WIFI_OFF);        //Prevents reconnection issue (taking too long to connect)
    delay(1000);
    WiFi.mode(WIFI_STA);
    Serial.print("Connecting to ");
    Serial.println(ssid);
    WiFi.begin(ssid, password);
    
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }
    Serial.println("");
    Serial.println("Connected");
  
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());  //IP address assigned to your ESP
    
    delay(1000);
}

Video Tutorial of RFID Based Attendance System


Thank You so much Electronics Tech Channel for this awesome Project. Please help him to grow his channel. Your one subscribe can motivate him to create more projects like this on future.

Conclusion

Finally, we have completed the RFID based Attendance system using NodeMCU with a Website and Database. We hope you found this project useful! Drop a comment below if you have any doubts or queries. We’ll do our best to answer your questions

Alsan Parajuli

I am a WordPress enthusiast, a hardworking and highly positive person. I always believes in practicality rather than theoretical knowledge. With my curiosity and fast learning skills, I managed to learn everything on my own. I love coding, editing, writing and rummaging around Internet. I am passionate about IoT Projects, Digital marketing, website designing, and reviewing. Moreover, I had been contributing to WordPress Biratnagar as an active member since 2018.

https://theiotprojects.com/

61 thoughts on “RFID Based Attendance System Using NodeMCU with PHP Web App

  1. Hi I ran everything as described in the guide but, when I pass the rfid card in front of the reader the code is not transmitted to the ‘getdata.php’ script I tried multiple strings in ‘string url’ but without success (wireshark sees the transmission and the answer ), I have no more ideas, thanks

    1. RFID is SPI module sometimes loose connection to the NodeMCU cause the Problem. Next Thing Make sure you have updated your IPV4 address in the code. Try Running Some RFID example code in Arduino IDE. To make sure your RFID don’t have any hardware issue.

      1. Hi Alsan, I tried with another rfid reader connected to a wemos D1 R1 but I get the same result on screen I don’t see any card code, but with wireshark I see that as soon as I pass the card on the reader there is a transmission to the ip of the machine server, I think ipv4 is right, I tried both with http://192.168.1.60/getdata.php and with ddns address and port but nothing happens, should I read the card code in serial mode or not? thanks for assistance

          1. hi Alsan, I have disabled the windows firewall but I don’t get any results, I have also installed rfidattendance on debian buster (lampp) but also the graphical interface does not receive the card_uid, sorry if I steal your time.

          2. I have tested it with NodeMCU V3 and ESP32 board. It’s working fine. It would be great if I can help you out. Due to lockdown my all testing equipment are left at hostel room. If I had one i would test it and figure out the actual issue.

  2. hi Alsan, I have disabled the windows firewall but I don’t get any results, I have also installed rfidattendance on debian buster (lampp) but also the graphical interface does not receive the card_uid, sorry if I steal your time.

    1. hi Alsan, I solved it, it was a simple problem: I just had to adapt the Sda / ss and Rst pins in the arduino sketc, now everything works perfectly even if I don’t know how to change the Admin password since it is encrypted in the db, thanks and sorry for the time I made you lose, congratulations for the work

  3. hi great Alsan, one last thing, rfid attendance is now operational 😉 ​​but I would like to change the admin password to make it stronger but I don’t know how to do it, plus if I press on ‘recover password’ or ‘reset password’ it gives me an error because the link of the button leads to reset_pass.php that does not exist, how can I solve it if possible? thanks and good day

  4. Hi Alsan
    When i go to serial monitor to check if is running doesn´t appear nothing and when i press RST this appear “⸮⸮⸮⸮/⸮⸮⸮⸮⸮⸮” why is this happening?

  5. Hello Alsan.
    Couldn’t find reset_pass.php file. How to add new admin?. I tried to insert new admin in SQL but the password always wrong. Thanks

  6. Hi, thank you for your project. I found and error (in my case) wherein the user_logs are not saving in mysql,
    and found that line 6 $t = date(“H:i:sa”); is at am/pm, changed it to $t = date(“H:i:s”); and the project worked fine.

  7. wow! I really like this project now working with my project hope will be successfully completed thanks for this awesome IoT project

  8. Hi there I have some error message during uploading to my NodeMCU board : Invalid library found in C:\Program Files (x86)\Arduino\libraries\examples: no headers files (.h) found in C:\Program Files (x86)\Arduino\libraries\examples
    Invalid library found in C:\Program Files (x86)\Arduino\libraries\doc: no headers files (.h) found in C:\Program Files (x86)\Arduino\libraries\doc

    Please help Thank you

  9. Francesco, I have the same problem just like you so can you please send me the part of the code which you edited…?

  10. Hello Alsan, in the part of arduino code, at the moment that I read the target, show me the rfid number but appears a message: Not found!, and didnt sent to the database.

  11. Hello Alsan, let me know how to get the device token? I know this is a stupid question because i have just learned arduino for a month.

  12. Alsan ti ringrazio comunque la password da mySQL non si imposta. Magari se hai il file reset_pass.php posso dare un okkiata io per la funzione. Il software è bellissimo sensa l’impostazione della password perde il suo valore. Fammi sapere grazie.

  13. Alsan forse sblagli crittografata non è MD5 ed è impossibile sostituirla. Controlla fai le prove in piu’ ti lascio un link
    dove puoi cittografare on-line.

    http://www.md5online.it/index.lm?key_decript=%242y%2410%2489uX3LBy4mlU%2FDcBveQ1l.32nSianDP%2FE1MfUh.Z.6B4Z0ql3y7PK

    123 non corrisponde a questa Pass MD5 $2y$10$89uX3LBy4mlU/DcBveQ1l.32nSianDP/E1MfUh.Z.6B4Z0ql3y7PK

    123 corrisponde a 202cb962ac59075b964b07152d234b70 in MD5

    Puoi chiarirmi la mente grazie.

  14. hello Alsan ,Thank you for such good project,
    I am having error while login,
    the login and password i try to enter/change , but i didnt get any solution.
    it is keep showing data base error. Kindly share any video or anything for the solution, Thank you

  15. HI ALSAN, WHEN I WANT TO ADD DEVICE APPEARS ERROR = “FATAL ERROR: CALL TO UNDEFINED FUNCTION RANDOM_BYTE” AT DEVICE_CONFIG.PHP. PLEASE EXPLANATION. THANK YOU

  16. Hiya,

    Thanks for this great project, It is working fine for me (I am at development stage to setup up a rfid attendance logging system for my school).

    Now, I got my hand on a stock of 125Khz rfid cards,and RDM6300 modules, as my coding skills are not that strong, can you show me the right direction to adapt your code?

    Thanks!

Leave a Reply