Research on IoT based Attendace System
This IoT based research project is designed to create an RFID-based attendance system using an ESP32 microcontroller and an MFRC522 RFID reader. The system reads RFID card UIDs, compares them with predefined UIDs to identify users, and displays the results on a LiquidCrystal_I2C LCD screen. If the scanned card UID matches the predefined UID, a "Welcome" message is shown; IoT Projects Arduino otherwise, an "Access Denied" message is displayed. This project demonstrates the use of RFID technology for access control and attendance management.IoT Projects .
Introduction
An
attendance system is a technology solution designed to track and manage the
presence of individuals in various settings, such as schools, workplaces, and
events. These systems can range from traditional methods, like paper registers,
to advanced digital solutions that utilize biometric data, RFID cards, or
mobile applications.
Component Use
Attendance
systems utilize various components to efficiently track and manage presence in organizations.
Key elements include user identification methods such as biometric scanners and
RFID cards, which provide secure check-in options. Data collection devices like
attendance terminals and web interfaces gather attendance information, while software
applications manage and analyze this data. Networking equipment ensures
real-time communication between devices, and reporting tools generate insights
and metrics for decision-making. Integration capabilities with other systems
further streamline operations, making attendance systems essential for
enhancing accuracy and efficiency in both educational and corporate
environment.
Components Required
• ESP32 Microcontroller
• MFRC522 RFID Reader
• LiquidCrystal_I2C Display
• Jumper Wires
• Power Bank (for power supply)
Image of Component Used
PHP
CODE
<?php
$servername
= "localhost"; // Your
database host
$username
= "root"; // Database
username
$password
= ""; // Database
password
$dbname =
"attendance_db"; // Database name
// Create
a connection to the database using MySQLi
$conn =
new mysqli($servername, $username, $password, $dbname);
// Check
the connection
if
($conn->connect_error) {
die("Connection failed: " .
$conn->connect_error);
}
// Check
if 'uid' is received from the GET request
if
(isset($_GET['uid'])) {
$uid = trim($_GET['uid']); // Trim any whitespace from the UID
// Determine uname based on the value of
uid
if ($uid === "33:ba:9a:f5") {
$uname = "misty";
} else {
$uname = "unknown user";
}
// Use a prepared statement to prevent SQL
injection
$stmt = $conn->prepare("INSERT INTO
attendance_records (uid, uname, timestamp) VALUES (?, ?, NOW())");
if ($stmt) {
$stmt->bind_param("ss",
$uid, $uname); // Bind the UID and uname
parameters as strings
// Execute the query and check if
successful
if ($stmt->execute()) {
echo "New record created
successfully";
} else {
echo "Error: " .
$stmt->error;
}
// Close the prepared statement
$stmt->close();
} else {
echo "Error preparing statement:
" . $conn->error;
}
} else {
echo "UID not received.";
}
// Close
the connection
$conn->close();
?>
Arduino
code
#include
<Wire.h> // Library
for I2C communication
#include
<LiquidCrystal_I2C.h> // Library
for LCD display via I2C
#include
<SPI.h> // Library
for SPI communication
#include
<MFRC522.h> // Library
for RFID reader
#include
<WiFi.h> // Library
for Wi-Fi
#define
SS_PIN 27 // Pin for Slave
Select (SS) of RFID reader
#define
RST_PIN 5 // Pin for Reset
(RST) of RFID reader
MFRC522
rfid(SS_PIN, RST_PIN); // Create an MFRC522 object with SS and RST pins
LiquidCrystal_I2C
lcd(0x27, 16, 2); // Create an LCD object with I2C address 0x27 and 16x2
display
// Your Wi-Fi credentials
const
char* ssid = "OnePlus";
const
char* password = "thakuri1";
// Your server IP address (not localhost) and port
const
char* serverHost = " 192.168.38.51"; // Replace with your server's IP
address
const int
serverPort = 80; // Port
number for the server
const
byte predefined[] = {0x33, 0xBA, 0x9A, 0xF5}; // Example UID, adjust to your
actual UID
void
setup() {
Serial.begin(115200); // Initialize serial communication at
115200 baud rate
SPI.begin(); // Initialize SPI communication
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the LCD
// Connect to Wi-Fi
connectToWiFi();
// Display initial welcome message on LCD
lcd.setCursor(2, 0);
lcd.print("Attendance");
delay(1000); // Wait for 1 second
lcd.setCursor(1, 1);
lcd.print("System");
delay(2000); // Wait for 2 seconds
lcd.clear(); // Clear the LCD display
lcd.setCursor(0, 0);
lcd.print("Please");
lcd.setCursor(0, 1);
lcd.print("Scan card");
rfid.PCD_Init(); // Initialize the RFID reader
Serial.println("Scan RFID card");
}
void
loop() {
// Check if a new RFID card is present
if (!rfid.PICC_IsNewCardPresent()) {
return; // Exit if no new card is detected
}
// Try to read the UID from the detected card
if (!rfid.PICC_ReadCardSerial()) {
return; // Exit if reading the UID fails
}
lcd.clear();
lcd.clear();
Serial.print("Card UID: ");
byte scannedUID[rfid.uid.size]; // Array to
store the scanned UID bytes
// Read the UID bytes from the RFID card
for (byte i = 0; i < rfid.uid.size; i++) {
scannedUID[i] = rfid.uid.uidByte[i]; //
Store each byte of UID
Serial.print(rfid.uid.uidByte[i], HEX); //
Print each byte in hexadecimal format
Serial.print(" ");
}
Serial.println();
// Compare the scanned UID with the predefined UID
bool match = (rfid.uid.size ==
sizeof(predefined)); // Check if the size of UID matches
if (match) {
for (byte i = 0; i < rfid.uid.size; i++)
{
if (scannedUID[i] != predefined[i]) { //
Compare each byte
match = false; // Set flag to false if
any byte does not match
break; // Exit the loop if mismatch is
found
}
}
}
// Display welcome message on LCD
lcd.setCursor(0, 0);
if (match) {
lcd.print("Misty Sharma");
lcd.setCursor(0, 1);
lcd.print("Present");
Serial.println("Present");
} else {
lcd.print("Access Denied");
Serial.println("Access Denied");
}
Serial.print("Card UID: ");
String uidString = "";
// Read the UID bytes from the RFID card
for (byte i = 0; i < rfid.uid.size; i++) {
uidString += String(rfid.uid.uidByte[i],
HEX);
if (i < rfid.uid.size - 1) uidString +=
":";
Serial.print(rfid.uid.uidByte[i], HEX);
Serial.print(" ");
}
Serial.println();
// Send UID to server
sendDataToServer(uidString);
delay(2000); // Display result for 2 seconds
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Please");
lcd.setCursor(0, 1);
lcd.print("Scan card");
rfid.PICC_HaltA();
rfid.PCD_StopCrypto1(); // Stop encryption on
the RFID reader
}
void
connectToWiFi() {
Serial.print("Connecting to
WiFi...");
WiFi.begin(ssid, password);
// Wait until the connection is established
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("\nConnected to WiFi");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
void sendDataToServer(String uid) {
WiFiClient client;
String url = "/new_attendance.php?uid="
+ uid; // Only the path, not full URL
Serial.print("Connecting to ");
Serial.print(serverHost);
Serial.print(":");
Serial.println(serverPort);
// Try to connect to the server
if (client.connect(serverHost, serverPort)) {
Serial.println("Connected to
server");
// Send the HTTP GET request
client.print(String("GET ") + url
+ " HTTP/1.1\r\n" +
"Host: " +
serverHost + "\r\n" +
"Connection:
close\r\n\r\n");
// Wait for the response and print it
while (client.connected() &&
!client.available()) {
delay(10); // Wait for the response
}
while (client.available()) {
String line = client.readStringUntil('\r');
Serial.print(line);
}
} else {
Serial.println("Failed to connect to
server");
}
client.stop(); // Close the connection
}
Conclusion
In conclusion, attendance systems play a vital role in
enhancing the efficiency and accuracy of tracking presence across various
environments. By leveraging advanced technologies such as biometric
identification, RFID, and mobile applications, these systems streamline the
attendance process, reduce administrative burdens, and provide valuable data
insights. The integration of reporting tools and networking capabilities
further enhances their functionality, allowing organizations to make informed
decisions based on attendance patterns. As the demand for automation and
data-driven management continues to grow, implementing a robust attendance
system is essential for optimizing human resource management and fostering
accountability in both educational and corporate settings.
Team Member Name
· Aarushi Basyal
· Bishnu Mahato
· Sujan Rana Magar
· Manoj Malla
· Bibek Bansi Thakuri
· Sudikshya Temilsina
· Prayas Gurung