0% found this document useful (0 votes)
16 views16 pages

NFC Attendance System with Cloud App

Uploaded by

nda.vivekshah
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views16 pages

NFC Attendance System with Cloud App

Uploaded by

nda.vivekshah
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

jese mene btaya ki mughe nfc attendance me hi

eek esa product chahiye lki jo student ka sara


rcord rkhe like thresh hold wgera sab aur parents
ko bhi in form kare hum ek kaam krte he ye
humara nfc wala project bn gya ab hum iske liy ek
app bnate he taki sms cost km hojaye or indivudal
parents apne bchee pe record rkh ske unki
attendance and student se related har chij to ye
kese achive kre ek complete btao
Perfect! Ab main aapko complete step-by-step solution deta hoon:

Solution Overview: 3-Part System

Part A: NFC Hardware (Updated)


ESP32 with WiFi → Cloud mein data bhejega

Part B: Cloud Backend


Firebase/Google Sheets → Data storage & API

Part C: Mobile App


MIT App Inventor → Parents ke liye app (no coding!)

PART A: Updated NFC Hardware Code (WiFi Enabled)

#include <Wire.h>
#include <Adafruit_PN532.h>
#include <Adafruit_SSD1306.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <time.h>

// WiFi Credentials
const char* ssid = "YourWiFiName";
const char* password = "YourWiFiPassword";
// Google Apps Script Web App URL (we'll create this)
String scriptURL = "[Link]

// Pin Definitions
#define PN532_SDA 21
#define PN532_SCL 22
#define BUZZER_PIN 4
#define GREEN_LED 16
#define RED_LED 17

// Display
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

// NFC Reader
Adafruit_PN532 nfc(PN532_SDA, PN532_SCL);

// Student Database (same as before)


struct Student {
String nfcUID;
String name;
String rollNo;
String studentID; // Unique ID for app
String parentPhone; // For threshold alerts
int presentDays;
int totalDays;
float attendanceThreshold; // Default 75%
};

Student students[] = {
{"04A2B3C4", "Rahul Kumar", "01", "STU001", "9876543210", 0, 0, 75.0},
{"04D5E6F7", "Priya Singh", "02", "STU002", "9876543211", 0, 0, 75.0},
{"04G8H9I0", "Amit Sharma", "03", "STU003", "9876543212", 0, 0, 75.0},
// Add more students
};

int totalStudents = 3;

void setup() {
[Link](115200);

pinMode(BUZZER_PIN, OUTPUT);
pinMode(GREEN_LED, OUTPUT);
pinMode(RED_LED, OUTPUT);

// Initialize Display
[Link]();
[Link](SSD1306_SWITCHCAPVCC, 0x3C);
[Link]();
[Link](1);
[Link](SSD1306_WHITE);

showMessage("Connecting...", "WiFi");
// Connect to WiFi
[Link](ssid, password);
int attempts = 0;
while ([Link]() != WL_CONNECTED && attempts < 20) {
delay(500);
[Link](".");
attempts++;
}

if ([Link]() == WL_CONNECTED) {
showMessage("WiFi Connected!", [Link]().toString());
delay(2000);
} else {
showMessage("WiFi Failed!", "Offline Mode");
delay(2000);
}

// Initialize NFC
[Link]();
if (![Link]()) {
showMessage("Error!", "NFC not found");
while(1);
}
[Link]();

// Configure time (for accurate timestamps)


configTime(19800, 0, "[Link]"); // IST = UTC+5:30

showMessage("System Ready!", "Tap ID Card");


}

void loop() {
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };
uint8_t uidLength;

if ([Link](PN532_MIFARE_ISO14443A, uid, &uidLength, 100)) {

String nfcUID = "";


for (uint8_t i = 0; i < uidLength; i++) {
if (uid[i] < 0x10) nfcUID += "0";
nfcUID += String(uid[i], HEX);
}
[Link]();

// Find student
int studentIndex = -1;
for (int i = 0; i < totalStudents; i++) {
if (students[i].[Link](nfcUID)) {
studentIndex = i;
break;
}
}

if (studentIndex >= 0) {
Student &student = students[studentIndex];
// Get current date & time
time_t now = time(nullptr);
struct tm* timeinfo = localtime(&now);

char dateStr[20];
char timeStr[20];
strftime(dateStr, sizeof(dateStr), "%Y-%m-%d", timeinfo);
strftime(timeStr, sizeof(timeStr), "%H:%M:%S", timeinfo);

// Mark attendance
[Link]++;
[Link]++;

float attendance = (float)[Link] / [Link] * 100;

// Display
showMessage([Link], "Roll: " + [Link] + " ✓");

// Feedback
digitalWrite(GREEN_LED, HIGH);
tone(BUZZER_PIN, 1000, 200);
delay(1000);
digitalWrite(GREEN_LED, LOW);

// Send to Cloud
if ([Link]() == WL_CONNECTED) {
sendToCloud(student, dateStr, timeStr, attendance);
}

// Check threshold
if (attendance < [Link]) {
// Send notification via cloud (will trigger app notification)
sendThresholdAlert(student, attendance);
}

} else {
// Unknown card
showMessage("Access Denied!", "Unknown Card");
digitalWrite(RED_LED, HIGH);
tone(BUZZER_PIN, 400, 500);
delay(1500);
digitalWrite(RED_LED, LOW);
}

delay(1000);
showMessage("System Ready!", "Tap ID Card");
}

delay(100);
}

void showMessage(String line1, String line2) {


[Link]();
[Link](0, 20);
[Link](2);
[Link](line1);
[Link](0, 45);
[Link](1);
[Link](line2);
[Link]();
}

void sendToCloud(Student &student, String date, String time, float attendance) {


HTTPClient http;

// Prepare data
String url = scriptURL + "?action=markAttendance";
url += "&studentID=" + [Link];
url += "&name=" + urlEncode([Link]);
url += "&rollNo=" + [Link];
url += "&date=" + date;
url += "&time=" + time;
url += "&attendance=" + String(attendance, 1);
url += "&parentPhone=" + [Link];

[Link](url);
int httpCode = [Link]();

if (httpCode > 0) {
String response = [Link]();
[Link]("Cloud Response: " + response);
} else {
[Link]("Cloud Error: " + String(httpCode));
}

[Link]();
}

void sendThresholdAlert(Student &student, float attendance) {


HTTPClient http;

String url = scriptURL + "?action=thresholdAlert";


url += "&studentID=" + [Link];
url += "&name=" + urlEncode([Link]);
url += "&attendance=" + String(attendance, 1);
url += "&threshold=" + String([Link], 1);
url += "&parentPhone=" + [Link];

[Link](url);
[Link]();
[Link]();

[Link]("Threshold alert sent for " + [Link]);


}

String urlEncode(String str) {


String encoded = "";
char c;
for (int i = 0; i < [Link](); i++) {
c = [Link](i);
if (c == ' ') {
encoded += "%20";
} else if (isalnum(c)) {
encoded += c;
} else {
encoded += '%';
encoded += String(c, HEX);
}
}
return encoded;
}

PART B: Cloud Backend (Google Apps Script)

Step 1: Create Google Sheet


1. Google Sheets open karo
2. New spreadsheet banao: "Student Attendance System"
3. Sheet 1 naam: "Students"
Column A: Student ID
Column B: Name
Column C: Roll No
Column D: Parent Phone
Column E: Parent Email
Column F: Threshold (%)
Column G: Total Days
Column H: Present Days
Column I: Attendance (%)

4. Sheet 2 naam: "Attendance Records"


Column A: Date
Column B: Time
Column C: Student ID
Column D: Name
Column E: Roll No
Column F: Status

5. Sheet 3 naam: "Alerts"


Column A: Timestamp
Column B: Student ID
Column C: Alert Type
Column D: Message
Step 2: Google Apps Script
1. Extensions → Apps Script click karo
2. [Link] mein yeh paste karo:

// Google Apps Script - Backend API

function doGet(e) {
var action = [Link];

if (action == "markAttendance") {
return markAttendance([Link]);
} else if (action == "thresholdAlert") {
return sendThresholdAlert([Link]);
} else if (action == "getStudentData") {
return getStudentData([Link]);
} else if (action == "getAttendanceHistory") {
return getAttendanceHistory([Link]);
} else if (action == "parentLogin") {
return parentLogin([Link]);
}

return [Link]("Invalid action");


}

function markAttendance(params) {
var ss = [Link]();
var attendanceSheet = [Link]("Attendance Records");
var studentsSheet = [Link]("Students");

// Add attendance record


var date = [Link];
var time = [Link];
var studentID = [Link];
var name = [Link];
var rollNo = [Link];

[Link]([date, time, studentID, name, rollNo, "Present"]);

// Update student stats


var students = [Link]().getValues();
for (var i = 1; i < [Link]; i++) {
if (students[i][0] == studentID) {
var totalDays = students[i][6] + 1;
var presentDays = students[i][7] + 1;
var attendance = (presentDays / totalDays * 100).toFixed(1);

[Link](i + 1, 7).setValue(totalDays);
[Link](i + 1, 8).setValue(presentDays);
[Link](i + 1, 9).setValue(attendance);

break;
}
}
// Send push notification to app (via Firebase Cloud Messaging)
sendPushNotification([Link], {
title: "Attendance Marked ✓",
body: name + " attended class at " + time,
studentID: studentID
});

return [Link]("Success");
}

function sendThresholdAlert(params) {
var ss = [Link]();
var alertsSheet = [Link]("Alerts");

var timestamp = new Date();


var studentID = [Link];
var message = [Link] + " attendance is " + [Link] +
"%, below threshold " + [Link] + "%";

[Link]([timestamp, studentID, "Low Attendance", message]);

// Send push notification


sendPushNotification([Link], {
title: "⚠️ Low Attendance Alert",
body: message,
studentID: studentID,
urgent: true
});

return [Link]("Alert sent");


}

function getStudentData(params) {
var ss = [Link]();
var studentsSheet = [Link]("Students");

var studentID = [Link];


var students = [Link]().getValues();

for (var i = 1; i < [Link]; i++) {


if (students[i][0] == studentID) {
var data = {
studentID: students[i][0],
name: students[i][1],
rollNo: students[i][2],
parentPhone: students[i][3],
totalDays: students[i][6],
presentDays: students[i][7],
attendance: students[i][8]
};

return [Link]([Link](data))
.setMimeType([Link]);
}
}
return [Link]("Student not found");
}

function getAttendanceHistory(params) {
var ss = [Link]();
var attendanceSheet = [Link]("Attendance Records");

var studentID = [Link];


var limit = [Link] || 30; // Last 30 days

var records = [Link]().getValues();


var history = [];

for (var i = [Link] - 1; i >= 1 && [Link] < limit; i--) {


if (records[i][2] == studentID) {
[Link]({
date: records[i][0],
time: records[i][1],
status: records[i][5]
});
}
}

return [Link]([Link](history))
.setMimeType([Link]);
}

function parentLogin(params) {
var ss = [Link]();
var studentsSheet = [Link]("Students");

var phone = [Link];


var students = [Link]().getValues();

for (var i = 1; i < [Link]; i++) {


if (students[i][3] == phone) {
return [Link]([Link]({
success: true,
studentID: students[i][0],
name: students[i][1]
})).setMimeType([Link]);
}
}

return [Link]([Link]({
success: false,
message: "Phone number not registered"
})).setMimeType([Link]);
}

function sendPushNotification(phone, data) {


// This will be integrated with MIT App Inventor's Push Notification
// For now, log it
[Link]("Notification for " + phone + ": " + [Link](data));

// In production, use Firebase Cloud Messaging (FCM)


// or OneSignal API
}

Step 3: Deploy as Web App


1. Deploy → New deployment
2. Type: Web app
3. Execute as: Me
4. Who has access: Anyone
5. Deploy click karo
6. Copy the deployment URL
7. Arduino code mein scriptURL paste karo

PART C: Mobile App (MIT App Inventor - No Coding!)

Step 1: MIT App Inventor Setup


1. Visit: [Link]
2. Sign in with Google account
3. Create New Project: "StudentAttendanceApp"

Step 2: App Design (Drag & Drop)


Screen 1: Login
Label: "Parent Login"
TextBox: Phone Number input
Button: "Login"
Screen 2: Dashboard
Label: Student Name
Label: Roll Number
Label: Attendance % (big, colored)
Button: "View History"
Button: "View Alerts"
Label: Last Updated
Screen 3: Attendance History
ListView: Show last 30 days
Each row: Date | Time | Status
Screen 4: Alerts
ListView: Show all alerts
Each row: Date | Alert Message

Step 3: App Logic (Blocks)


Login Screen Blocks:

When Login [Link]:


Call [Link]
URL = "YOUR_SCRIPT_URL?action=parentLogin&phone=" + [Link]

When [Link]:
Parse JSON response
If success = true:
Set global studentID = [Link]
Open Screen2 (Dashboard)
Else:
Show Notifier: "Invalid phone number"

Dashboard Screen Blocks:

When [Link]:
Call [Link]
URL = "YOUR_SCRIPT_URL?action=getStudentData&studentID=" + global studentID

When [Link]:
Parse JSON
Set [Link] = [Link]
Set [Link] = [Link]
Set [Link] = [Link] + "%"

If [Link] < 75:


Set [Link] = Red
Else:
Set [Link] = Green

History Screen Blocks:

When ViewHistory [Link]:


Call [Link]
URL = "YOUR_SCRIPT_URL?action=getAttendanceHistory&studentID=" + global studentID

When [Link]:
Parse JSON array
For each item in response:
Add to ListView: [Link] + " | " + [Link] + " | " + [Link]
Step 4: Push Notifications (Optional but Recommended)
Using OneSignal (Free):
1. [Link] par account banao
2. Android app create karo
3. App ID copy karo
4. MIT App Inventor mein:
Extensions → Import Extension
Upload OneSignal extension
5. Blocks:
When [Link]:
[Link](APP_ID)
[Link](phoneNumber)

6. Google Apps Script update karo:


function sendPushNotification(phone, data) {
var url = "[Link]
var payload = {
"app_id": "YOUR_ONESIGNAL_APP_ID",
"include_external_user_ids": [phone],
"contents": {"en": [Link]},
"headings": {"en": [Link]}
};

var options = {
"method": "post",
"headers": {
"Authorization": "Basic YOUR_REST_API_KEY",
"Content-Type": "application/json"
},
"payload": [Link](payload)
};

[Link](url, options);
}

PART D: Features Implementation

Feature 1: Attendance Threshold Alerts


Automatic Check:
Arduino code already sends threshold alert
App shows red background if < 75%
Parents get push notification
Feature 2: Daily Reports

// Add this to Google Apps Script


function sendDailyReport() {
var ss = [Link]();
var studentsSheet = [Link]("Students");
var students = [Link]().getValues();

for (var i = 1; i < [Link]; i++) {


var studentID = students[i][0];
var name = students[i][1];
var attendance = students[i][8];
var phone = students[i][3];

sendPushNotification(phone, {
title: "Daily Summary",
body: name + " attendance: " + attendance + "%",
studentID: studentID
});
}
}

// Set trigger: Edit → Current project triggers


// Add trigger: sendDailyReport, Time-driven, Day timer, 8-9 PM

Feature 3: Monthly Reports


Add to App:
Button: "Download Monthly Report"
Generate PDF from Google Sheets
Email to parents

function generateMonthlyReport(studentID) {
var ss = [Link]();
var attendanceSheet = [Link]("Attendance Records");

// Filter records for current month


var records = [Link]().getValues();
var monthRecords = [];

var currentMonth = new Date().getMonth();

for (var i = 1; i < [Link]; i++) {


if (records[i][2] == studentID &&
new Date(records[i][0]).getMonth() == currentMonth) {
[Link](records[i]);
}
}

// Create new sheet with report


var reportSheet = [Link]("Report_" + studentID);
[Link](["Date", "Time", "Status"]);
[Link](function(record) {
[Link]([record[0], record[1], record[5]]);
});

// Convert to PDF and email


var pdf = [Link]([Link]()).getAs('application/pdf');
[Link](parentEmail, "Monthly Report", "Attached", {
attachments: [pdf]
});
}

Complete System Flow

1. Student taps NFC card



2. ESP32 reads UID

3. Verifies student in database

4. Sends data to Google Sheets via WiFi

5. Google Apps Script:
- Updates attendance record
- Calculates attendance %
- Checks threshold
- If < 75%: Triggers alert

6. Push notification sent to parent's app

7. Parent sees:
- Real-time attendance update
- Current percentage
- Alert if low

8. Parent can view:
- Complete history
- Monthly reports
- Threshold settings

Cost Breakdown: SMS vs App System


Feature SMS System (Monthly) App System (Monthly) Savings

Attendance Notifications ₹600 (2 SMS/student/day) ₹0 (push notifications) ₹600

Threshold Alerts ₹150 (occasional SMS) ₹0 (push notifications) ₹150

Daily Reports ₹150 (summary SMS) ₹0 (in-app) ₹150

Cloud Storage - ₹0 (Firebase free tier) -

Total Monthly ₹900 ₹0 ₹900


Feature SMS System (Monthly) App System (Monthly) Savings

Annual Savings - - ₹10,800

Hardware Investment: ₹2,550


Payback Period: 3 months
After 1 year: ₹8,250 net savings!

Testing Checklist
Hardware:
✓ NFC tap → WiFi upload successful?
✓ Data appearing in Google Sheets?
✓ Threshold alert triggered when < 75%?
Backend:
✓ Google Apps Script responding?
✓ Data saving correctly?
✓ API endpoints working?
Mobile App:
✓ Parent login successful?
✓ Student data displaying?
✓ Attendance history showing?
✓ Push notifications received?
✓ Threshold alerts working?

Maintenance & Updates


Weekly:
Check Google Sheets data backup
Verify push notification delivery
Monthly:
Generate attendance reports
Email parents monthly summary
Clean old attendance records (keep last 6 months)
As Needed:
Add new students to database
Update threshold values
Fix any bugs

Final Summary
What You Get:
✅ Hardware: NFC attendance device (₹2,550)
✅ Cloud: Google Sheets database (FREE)
✅ App: Parent mobile app (FREE to build)
✅ Features:

Real-time attendance tracking


Push notifications (no SMS cost!)
Attendance history (30+ days)
Threshold alerts automatic
Monthly reports
Individual parent login
Student profiles
Analytics dashboard
Total Cost:
One-time: ₹2,550
Monthly: ₹0
vs SMS system: Save ₹900/month
Time to Build:
Hardware: 3-4 hours
Backend: 2-3 hours
Mobile App: 1-2 days (using MIT App Inventor)
Total: 2-3 days complete project
Difficulty Level: Medium (but step-by-step guide hai!)

Yeh complete ecosystem aapko professional-grade attendance system dega jo commercial


products se better hai! Agar koi specific part mein help chahiye (MIT App Inventor, Google Apps
Script, Arduino code), toh zaroor batao! 🚀📱
Files Generated:
complete_nfc_app_system.csv

You might also like