IoT Based RFID Attendance System Using ESP32

IoT Based RFID Attendance System using ESP32

IoT Projects

In this project, I will tell you how to build a Portable IoT based RFID Attendance System using ESP32, 0.96” OLED Display & MF-RC522 Module. RFID Attendance Systems are commonly used to mark the presence of students or staff in schools and offices.

This project has a wide area in the modern era of schools, colleges, business organizations, offices where accurate attendance data is required. The RFID attendance system makes the process much easier and more reliable. But before getting started, let’s learn How RFID Attendance System works?

How IoT based RFID Attendance System Works?

The ESP32 Wi-Fi Module will collect the RFID CARD/keychain UID  from the multiple users and sends it over the internet to a website. The Enrollment of RFID CARD is done on the server using any MF-RC522 RFID Module that is available on the market. The verification of the Card/keychain will be done on the webserver, while Card UID is transmitted over the WiFi.

View Users log on RFID Based Attenance System

The website used in this project is developed using PHP, CSS, and Javascript, it has a database to record Card UID. By logging in to the web server, we can collect personal records of each attendee as well as all attendance records, including incoming and outgoing times. These data can also be downloaded and exported to an excel sheet.

Features of RFID Attendance Website

  • Safe Login System
  • Admin Panel
  • User Entry Log
  • User Management System
  • Multiple Device Management System
  • Filter log data by date, On-time, time-out, and department
  • Export those filtered data to Excel.

Note: Generally, administrators play an important role in the management of this system.

Functions Provided to users and Admin

Now, talking about the features of the RFID based Attendance system using ESP32. The home page displays the admin login page. Until you login to the system, you will not be able to browse other available options. So the system is safe. In general, the design of the RFID presence system project is quite simple. So the user does not find any difficulties in registering his/her Attendance. The user must swipe his/her card or keychain to enroll in attendance, including entry time. The main tasks assigned to the administrator are as follows:

You can watch the following video tutorial for detailed information, or you can read the article written here.

RFID Attendance Admin Panel Login System
  • Admin Login/Logout System 
  • Forgot Password for admin
  • Edit and Update admin profile
Reset Admin Account Password in RFID Attendance system

Manage Users

View and Manage Users using RFID Attendance system using ESP32
  • View users
  • Add New User
  • Edit and update the existing users
  • Remove Users
RFID Attendance User Management System using esp32

From the admin panel, administrators can add new users, update and remove users using the user management system. Additionally, the administrator can view all attendance records.

Enroll New Users Update and Remove using RFID and esp32

Manage Device

RFID Device Management System using esp32
  • 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

In fact, from device section administrators can add a new device, update, and remove too. To add a new device you need to enter the device name and its depart. Additionally, you can update the device token from the device UID section.

View user log

View Users log on RFID Based Attenance System

From the User Log menu, you can navigate to all user log data. You can also see their arrival and departure times. It also filters your logs to filter user, date, arrival time, timeout, and various sections. So you can export that data to Excel.

Filter Users Log to export to excel

Components Required

Following are the Hardware and Software components required for making IoT Based RFID Attendance System Using ESP32.

Hardware Components

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

Software Components

Technology Used in RFID attendance System with ESP32

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.

Network Topology: IoT Based RFID Attendance System using ESP32

This is a simple network topology designed to run this project through a local network. Project devices and computer servers are connected to the same network via Wi-Fi.

 IoT Based RFID Attendance System Using ESP32 Network Topology

Now its time to interface all the components together to build the project.

Interfacing RFID RC522 & 0.96″ OLED Display to ESP32 Module

Using the table and circuit diagram provided below you can easily assemble your circuit.

ESP32 RFID MFRC522 / RC522
GPIO 4SDA/SS
GPIO 18SCK
GPIO 17MOSI
GPIO 16MISO
GNDGND
GPIO 5RST
Vcc/3.3v3.3V
ESP320.96″OLED Display
GPIO 22SCL
GPIO 21SDA
GNDGND
Vcc3.3V/Vin for 5V
Assemble Circuit using this table
Circuit Diagram of IoT based RFID Attendance System using ESP32 and OLED Display
Circuit Diagram: IoT based RFID Attendance System using ESP32 and OLED Display

How to run a server for this project?

In fact, we can use this PHP web application on hosting servers as well. However, you need a public IP from your broadband connection to send data to the hosting server.

Anyway, we are using the XAMPP server. It can be used on both Windows and Linux. Generally, Ubuntu users can use LAMP which is better than XAMPP. But, I am using Windows so I am going to use the XAMPP server. So you can download XAMPP server from this link

Deploying RFID Attendance Web App

  • Start your Mysql and Apache from XAMPP Control Panel.
Start PHP MYSQL and Apache2 Webserver on xampp
  • 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.

Create RFID Attendance Database
  • Create a database name “rfidattendance” and then click on the import tab.
Ceating database with name rfidattendance
  • Click on the browse file and then choose the “rfidattendance.sql” file located inside the rfidattendance folder.
Import rfidattendance sql database
  • 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 Attendance Admin Panel Login System
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 ESP32

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

Installing ESP32 on Arduino IDE Board Manager

Paste https://dl.espressif.com/dl/package_esp32_index.json in additional board manager URLs. 

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

Installing ESP32 on Arduino IDE Board Manager

Selecting Port and Board

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

Selecting ESP32 COM Port (1)

Now select Your ESP32 Board by clicking Tools -> Board. Scroll down until you find it.

Library Files for IoT Based RFID Attendance System

You have to install the following library files to your Arduino IDE Libraries folder:

Program/Sketch Code

The source code for the Portable IoT Based RFID Attendance System using ESP32 is here. In this source code, you need to do some modifications like your WiFi Network credentials, Device token from the website, and PC IP Address.

Include ESP32, RFID, Adafruit GFX, and Adafruit SSD1306 Library header files.

#include <WiFi.h>
#include <HTTPClient.h>
#include <time.h>
//RFID-----------------------------
#include <SPI.h>
#include <MFRC522.h>
//OLED-----------------------------
#include <Wire.h>
#include <Adafruit_GFX.h> 
#include <Adafruit_SSD1306.h>

Defining Pin of all the components that are interfaced to ESP32 board.

#define SS_PIN  4 // SCK-GPIO 18, MOSI-GPIO 17, MISO-GPIO 16, Vcc-3.3v, GND -GND,
#define RST_PIN 5
// Declaration for SSD1306 display connected using software I2C pins are(22 SCL, 21 SDA)
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET     0 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

Create MFRC522 instance.

MFRC522 mfrc522(SS_PIN, RST_PIN); 

Set these to your desired credentials. Your WiFi SSID Name, Password, and Device Token.

const char *ssid = "SSID";
const char *password = "Password";
const char* device_token  = "Device Token";

Replace “x” your timezone.

int timezone = x * 3600;  
int time_dst = 0;

Your computer IP or the server domain.

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

Initiate 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);
}

Print the IP address assigned to your ESP32

Serial.print("IP address: ");
    Serial.println(WiFi.localIP());

Final Code: IoT Based RFID Attendance System using ESP32

Also Read:

/* -----------------------------------------------------------------------------
  - Project: RFID attendance system using ESP32
  - Author:  https://www.youtube.com/ElectronicsTechHaIs
  - Date:  6/03/2020
   -----------------------------------------------------------------------------
  This code was created by Electronics Tech channel for 
  the RFID attendance project with ESP32.
   ---------------------------------------------------------------------------*/
//*******************************libraries********************************
//ESP32----------------------------
#include <WiFi.h>
#include <HTTPClient.h>
#include <time.h>
//RFID-----------------------------
#include <SPI.h>
#include <MFRC522.h>
//OLED-----------------------------
#include <Wire.h>
#include <Adafruit_GFX.h>          //https://github.com/adafruit/Adafruit-GFX-Library
#include <Adafruit_SSD1306.h>      //https://github.com/adafruit/Adafruit_SSD1306
//************************************************************************
#define SS_PIN  4 // SCK-GPIO 18, MOSI-GPIO 17, MISO-GPIO 16, Vcc-3.3v, GND -GND,
#define RST_PIN 5
// Declaration for SSD1306 display connected using software I2C pins are(22 SCL, 21 SDA)
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET     0 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
//************************************************************************
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
//************************************************************************
/* Set these to your desired credentials. */
const char *ssid = "SSID";
const char *password = "Password";
const char* device_token  = "Device Token";
//************************************************************************
int timezone = x * 3600;   //Replace "x" your timezone.
int time_dst = 0;
String getData, Link;
String OldCardID = "";
unsigned long previousMillis1 = 0;
unsigned long previousMillis2 = 0;
String URL = "http://YourComputerIP/rfidattendance/getdata.php"; //computer IP or the server domain
//*************************Biometric Icons*********************************
#define Wifi_start_width 54
#define Wifi_start_height 49
const uint8_t PROGMEM Wifi_start_bits[] = {
  0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x1f,0xf0,0x00,0x00,0x00
,0x00,0x03,0xff,0xff,0x80,0x00,0x00
,0x00,0x1f,0xf0,0x1f,0xf0,0x00,0x00
,0x00,0x7e,0x00,0x00,0xfc,0x00,0x00
,0x01,0xf0,0x00,0x00,0x1f,0x00,0x00
,0x03,0xc0,0x00,0x00,0x07,0xc0,0x00
,0x0f,0x00,0x00,0x00,0x01,0xe0,0x00
,0x1c,0x00,0x00,0x00,0x00,0x70,0x00
,0x38,0x00,0x07,0xc0,0x00,0x38,0x00
,0x70,0x00,0xff,0xfe,0x00,0x1e,0x00
,0xe0,0x03,0xfc,0x7f,0xc0,0x0e,0x00
,0x00,0x1f,0x80,0x03,0xf0,0x00,0x00
,0x00,0x3c,0x00,0x00,0x78,0x00,0x00
,0x00,0xf0,0x00,0x00,0x1c,0x00,0x00
,0x01,0xe0,0x00,0x00,0x0c,0x00,0x00
,0x03,0x80,0x00,0x00,0x00,0x00,0x00
,0x03,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x3f,0xf8,0x07,0x1e,0x00
,0x00,0x00,0xff,0xfe,0x1f,0xbf,0x80
,0x00,0x03,0xe0,0x04,0x7f,0xff,0xc0
,0x00,0x07,0x80,0x00,0xff,0xff,0xe0
,0x00,0x0e,0x00,0x00,0xff,0xff,0xe0
,0x00,0x0c,0x00,0x00,0x7f,0xff,0xc0
,0x00,0x00,0x00,0x00,0xfe,0x07,0xe0
,0x00,0x00,0x00,0x03,0xf8,0x03,0xf8
,0x00,0x00,0x07,0xe7,0xf9,0xf1,0xfc
,0x00,0x00,0x1f,0xe7,0xf1,0xf9,0xfc
,0x00,0x00,0x1f,0xe7,0xf3,0xf9,0xfc
,0x00,0x00,0x3f,0xe7,0xf3,0xf9,0xfc
,0x00,0x00,0x3f,0xe7,0xf1,0xf1,0xfc
,0x00,0x00,0x3f,0xe3,0xf8,0xe3,0xfc
,0x00,0x00,0x3f,0xf3,0xfc,0x07,0xf8
,0x00,0x00,0x1f,0xf0,0x7f,0x0f,0xc0
,0x00,0x00,0x0f,0xe0,0x7f,0xff,0xe0
,0x00,0x00,0x07,0xc0,0xff,0xff,0xe0
,0x00,0x00,0x00,0x00,0x7f,0xff,0xe0
,0x00,0x00,0x00,0x00,0x3f,0xff,0x80
,0x00,0x00,0x00,0x00,0x1f,0xbf,0x00
,0x00,0x00,0x00,0x00,0x03,0x18,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
#define Wifi_connected_width 63
#define Wifi_connected_height 49
const uint8_t PROGMEM Wifi_connected_bits[] = {
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x03,0xff,0xff,0x80,0x00,0x00
,0x00,0x00,0x3f,0xff,0xff,0xf8,0x00,0x00
,0x00,0x01,0xff,0xff,0xff,0xff,0x00,0x00
,0x00,0x0f,0xff,0xff,0xff,0xff,0xe0,0x00
,0x00,0x3f,0xff,0xc0,0x07,0xff,0xf8,0x00
,0x00,0xff,0xf8,0x00,0x00,0x3f,0xfe,0x00
,0x03,0xff,0x80,0x00,0x00,0x03,0xff,0x80
,0x07,0xfe,0x00,0x00,0x00,0x00,0xff,0xc0
,0x1f,0xf8,0x00,0x00,0x00,0x00,0x3f,0xf0
,0x3f,0xe0,0x01,0xff,0xff,0x00,0x0f,0xf8
,0x7f,0x80,0x0f,0xff,0xff,0xe0,0x03,0xfc
,0xff,0x00,0x7f,0xff,0xff,0xfc,0x01,0xfe
,0xfc,0x01,0xff,0xff,0xff,0xff,0x00,0x7e
,0x78,0x07,0xff,0xc0,0x07,0xff,0xc0,0x3c
,0x00,0x0f,0xfc,0x00,0x00,0x7f,0xe0,0x00
,0x00,0x1f,0xf0,0x00,0x00,0x1f,0xf0,0x00
,0x00,0x3f,0xc0,0x00,0x00,0x07,0xf8,0x00
,0x00,0x7f,0x00,0x01,0x00,0x01,0xfc,0x00
,0x00,0x7e,0x00,0x7f,0xfc,0x00,0xfc,0x00
,0x00,0x3c,0x03,0xff,0xff,0x80,0x78,0x00
,0x00,0x00,0x07,0xff,0xff,0xc0,0x00,0x00
,0x00,0x00,0x1f,0xff,0xff,0xf0,0x00,0x00
,0x00,0x00,0x3f,0xf0,0x1f,0xf8,0x00,0x00
,0x00,0x00,0x3f,0x80,0x03,0xf8,0x00,0x00
,0x00,0x00,0x3f,0x00,0x01,0xf8,0x00,0x00
,0x00,0x00,0x1c,0x00,0x00,0x70,0x00,0x00
,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x0f,0xe0,0x00,0x00,0x00
,0x00,0x00,0x00,0x1f,0xf0,0x00,0x00,0x00
,0x00,0x00,0x00,0x3f,0xf8,0x00,0x00,0x00
,0x00,0x00,0x00,0x3f,0xf8,0x00,0x00,0x00
,0x00,0x00,0x00,0x3f,0xf8,0x00,0x00,0x00
,0x00,0x00,0x00,0x3f,0xf8,0x00,0x00,0x00
,0x00,0x00,0x00,0x1f,0xf0,0x00,0x00,0x00
,0x00,0x00,0x00,0x0f,0xe0,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
//************************************************************************
void setup() {
  delay(1000);
  Serial.begin(115200);
  SPI.begin();  // Init SPI bus
  mfrc522.PCD_Init(); // Init MFRC522 card
  //-----------initiate OLED display-------------
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }
  // you can delet these three lines if you don't want to get the Adfruit logo appear
  display.display();
  delay(2000); // Pause for 2 seconds
  display.clearDisplay();
  //---------------------------------------------
  connectToWiFi();
  //---------------------------------------------
  configTime(timezone, time_dst, "pool.ntp.org","time.nist.gov");
}
//************************************************************************
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() - previousMillis1 >= 1000) {
    previousMillis1 = millis();
    display.clearDisplay();
    
    time_t now = time(nullptr);
    struct tm* p_tm = localtime(&now);
    display.setTextSize(1);             // Normal 2:2 pixel scale
    display.setTextColor(WHITE);        // Draw white text
    display.setCursor(10,0);
    Serial.println(p_tm);
    display.setTextSize(4);             // Normal 2:2 pixel scale
    display.setTextColor(WHITE);        // Draw white text
    display.setCursor(0,21);
    if ((p_tm->tm_hour)<10) {display.print("0");display.print(p_tm->tm_hour);}
    else display.print(p_tm->tm_hour);
    display.print(":");
    if ((p_tm->tm_min)<10) {display.print("0");display.println(p_tm->tm_min);}
    else display.println(p_tm->tm_min);
    display.display();
  }
  //---------------------------------------------
  if (millis() - previousMillis2 >= 15000) {
    previousMillis2 = 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);
  display.clearDisplay();
}
//************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);
        
        display.clearDisplay();
        display.setTextSize(2);             // Normal 2:2 pixel scale
        display.setTextColor(WHITE);        // Draw white text
        display.setCursor(15,0);             // Start at top-left corner
        display.print(F("Welcome"));
        display.setCursor(0,20);
        display.print(user_name);
        display.display();
      }
      else if (payload.substring(0, 6) == "logout") {
        String user_name = payload.substring(6);
    //  Serial.println(user_name);
        
        display.clearDisplay();
        display.setTextSize(2);             // Normal 2:2 pixel scale
        display.setTextColor(WHITE);        // Draw white text
        display.setCursor(10,0);             // Start at top-left corner
        display.print(F("Good Bye"));
        display.setCursor(0,20);
        display.print(user_name);
        display.display();
      }
      else if (payload == "succesful") {
        display.clearDisplay();
        display.setTextSize(2);             // Normal 2:2 pixel scale
        display.setTextColor(WHITE);        // Draw white text
        display.setCursor(5,0);             // Start at top-left corner
        display.print(F("New Card"));
        display.display();
      }
      else if (payload == "available") {
        display.clearDisplay();
        display.setTextSize(2);             // Normal 2:2 pixel scale
        display.setTextColor(WHITE);        // Draw white text
        display.setCursor(5,0);             // Start at top-left corner
        display.print(F("Free Card"));
        display.display();
      }
      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);

    display.clearDisplay();
    display.setTextSize(1);             // Normal 1:1 pixel scale
    display.setTextColor(WHITE);        // Draw white text
    display.setCursor(0, 0);             // Start at top-left corner
    display.print(F("Connecting to \n"));
    display.setCursor(0, 50);   
    display.setTextSize(2);          
    display.print(ssid);
    display.drawBitmap( 73, 10, Wifi_start_bits, Wifi_start_width, Wifi_start_height, WHITE);
    display.display();
    
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }
    Serial.println("");
    Serial.println("Connected");
    
    display.clearDisplay();
    display.setTextSize(2);             // Normal 1:1 pixel scale
    display.setTextColor(WHITE);        // Draw white text
    display.setCursor(8, 0);             // Start at top-left corner
    display.print(F("Connected \n"));
    display.drawBitmap( 33, 15, Wifi_connected_bits, Wifi_connected_width, Wifi_connected_height, WHITE);
    display.display();
    
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());  //IP address assigned to your ESP
    
    delay(1000);
}
//=======================================================================

Thank You so much Electronics Tech Channel for this awesome Project.

Conclusion

Finally, we have completed the IoT Based RFID Attendance System Using ESP32 with a Website and Database. I hope you found this project useful! Drop a comment below if you have any doubts or queries. l will try my best to answer your questions.

Also Read:

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/

3 thoughts on “IoT Based RFID Attendance System using ESP32

Leave a Reply