#include <Adafruit_Fingerprint.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_GFX.h>
#include <SD.h>
#include <Wire.h>
#define FINGERPRINT_RX 16 // Connect fingerprint sensor RX to pin 16
#define FINGERPRINT_TX 17 // Connect fingerprint sensor TX to pin 17
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial2);
// Define pins for IR sensors
#define IR_SENSOR_1 2
#define IR_SENSOR_2 3
// Define pins for buzzer and relay
#define BUZZER_PIN 4
#define RELAY_PIN 5
// Define pins for SD card
#define SD_CS_PIN 10
// Define pins for touchscreen display
#define TFT_CLK 13
#define TFT_RST 9
#define TFT_DC 8
#define TFT_CS 7
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST, TFT_CLK);
File attendanceFile;
int peopleCount = 0;
void setup() {
Serial.begin(9600);
Serial2.begin(57600);
pinMode(IR_SENSOR_1, INPUT);
pinMode(IR_SENSOR_2, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(RELAY_PIN, OUTPUT);
if (!SD.begin(SD_CS_PIN)) {
Serial.println("SD Card initialization failed.");
while (1);
}
finger.begin(57600);
// Initialize display
tft.begin();
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.setCursor(10, 10);
tft.println("Biometric Attendance System");
tft.setCursor(10, 40);
tft.println("Place Finger or Enter");
}
void loop() {
// Check for people entering/exiting using IR sensors
if (digitalRead(IR_SENSOR_1) == HIGH || digitalRead(IR_SENSOR_2) == HIGH) {
peopleCount++;
updateDisplay();
delay(1000); // Delay to avoid multiple counts
}
// Check for fingerprint authentication
if (finger.verifyPassword()) {
int fingerprintID = getFingerprintID();
if (fingerprintID != -1) {
grantAccess();
delay(3000); // Delay to allow the person to enter
peopleCount--;
updateDisplay();
}
}
}
int getFingerprintID() {
// Fingerprint authentication logic
// ...
}
void grantAccess() {
digitalWrite(BUZZER_PIN, HIGH);
digitalWrite(RELAY_PIN, HIGH);
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(10, 10);
tft.println("Access Granted");
delay(2000);
digitalWrite(BUZZER_PIN, LOW);
digitalWrite(RELAY_PIN, LOW);
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(10, 10);
tft.println("Place Finger or Enter");
}
void updateDisplay() {
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(10, 10);
tft.print("People Inside: ");
tft.println(peopleCount);
// Update other information on the display as needed
}