The RFID Attendance System is designed to log attendance using an RFID reader, monitor the time with an RTC module, send messages via a SIM800L module, provide alerts with a buzzer, and display messages on an LCD. It also uses two LEDs to indicate access status. The system is controlled by an Arduino Uno R3 microcontroller.
/*
* RFID Attendance System using Arduino Uno R3
* This system uses an RFID reader to log attendance, an RTC to check the time,
* a SIM800L module to send messages to parents, a buzzer for alerts, an LCD
* display for messages, and two LEDs to indicate access status.
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <MFRC522.h>
#include <DS3231.h>
#include <SoftwareSerial.h>
// Pin definitions
#define RST_PIN 9
#define SS_PIN 10
#define GREEN_LED_PIN 4
#define RED_LED_PIN 5
#define BUZZER_PIN 7
#define RELAY_PIN 6
#define SIM800_TX 3
#define SIM800_RX 2
// Initialize components
LiquidCrystal_I2C lcd(0x27, 16, 2);
MFRC522 rfid(SS_PIN, RST_PIN);
DS3231 rtc(SDA, SCL);
SoftwareSerial sim800(SIM800_TX, SIM800_RX);
void setup() {
// Initialize serial communication
Serial.begin(9600);
sim800.begin(9600);
// Initialize LCD
lcd.begin();
lcd.backlight();
// Initialize RFID
SPI.begin();
rfid.PCD_Init();
// Initialize RTC
rtc.begin();
// Initialize pins
pinMode(GREEN_LED_PIN, OUTPUT);
pinMode(RED_LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(RELAY_PIN, OUTPUT);
// Welcome message
lcd.setCursor(0, 0);
lcd.print("RFID Attendance");
lcd.setCursor(0, 1);
lcd.print("System");
delay(2000);
lcd.clear();
}
void loop() {
// Check for RFID card
if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) {
return;
}
// Get current time
DateTime now = rtc.now();
// Check if student is on time
if (isOnTime(now)) {
grantAccess();
} else {
denyAccess();
}
// Halt PICC
rfid.PICC_HaltA();
}
bool isOnTime(DateTime now) {
// Define the allowed time range (e.g., 8:00 AM to 9:00 AM)
DateTime start(2023, 1, 1, 8, 0, 0);
DateTime end(2023, 1, 1, 9, 0, 0);
return now >= start && now <= end;
}
void grantAccess() {
// Turn on green LED
digitalWrite(GREEN_LED_PIN, HIGH);
digitalWrite(RED_LED_PIN, LOW);
// Activate relay
digitalWrite(RELAY_PIN, HIGH);
// Display message
lcd.setCursor(0, 0);
lcd.print("Access Granted");
// Send SMS
sendSMS("Access Granted");
// Deactivate relay after delay
delay(5000);
digitalWrite(RELAY_PIN, LOW);
lcd.clear();
}
void denyAccess() {
// Turn on red LED
digitalWrite(RED_LED_PIN, HIGH);
digitalWrite(GREEN_LED_PIN, LOW);
// Activate buzzer
digitalWrite(BUZZER_PIN, HIGH);
delay(1000);
digitalWrite(BUZZER_PIN, LOW);
// Display message
lcd.setCursor(0, 0);
lcd.print("Access Denied");
// Send SMS
sendSMS("Access Denied");
delay(5000);
lcd.clear();
}
void sendSMS(String message) {
sim800.print("AT+CMGF=1\r");
delay(100);
sim800.print("AT+CMGS=\"+1234567890\"\r");
delay(100);
sim800.print(message);
delay(100);
sim800.write(26);
delay(1000);
}
This code is responsible for controlling the RFID Attendance System. It initializes the components, checks for RFID cards, determines if the scanned card is within the allowed time range, and grants or denies access accordingly. It also sends SMS messages and controls the LEDs and buzzer for visual and audible feedback.