

This circuit is designed to manage an RFID-based access control system. It includes an Arduino Nano microcontroller, an RFID reader, an LCD display, a real-time clock (RTC) module, a piezo buzzer, a relay, and a step-down voltage regulator. The system reads RFID tags, logs the time of access, and displays the information on an LCD. It also controls a relay to manage power to an external device and uses a buzzer for audio feedback.
Arduino Nano
RFID-RC522
LCD Display 16x4 I2C
rtc MODULE
Piezo Buzzer
12v Relay
STEP DOWN XY 3606
12v5ah Battery
#include <Wire.h>
#include <RTClib.h>
#include <LiquidCrystal_I2C.h>
// Initialize the LCD display with I2C address 0x27 and size 16x2
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Initialize the RTC module
RTC_DS3231 rtc;
// Variables to store login and logout times
DateTime loggedIn;
DateTime loggedOut;
// Variable to store the period (AM/PM)
String period = "AM";
// Pin definitions
const byte BUZZER_PIN = 5;
const byte BUTTON_PIN = 3;
const byte RELAY_PIN = 6; // Relay connected to D6
// Variables to track button state
byte lastState = LOW;  // Previous state of the button
int currentState;      // Current state of the button
void setup() {
  // Start the I2C communication
  Wire.begin();
  
  // Set pin modes
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, LOW); // Ensure relay is off initially
  
  // Initialize serial communication at 9600 bits per second
  Serial.begin(9600);
  
  // Initialize the LCD display
  lcd.init();
  lcd.backlight();
  
  // Initialize the RTC module
  if (!rtc.begin()) {
    Serial.print("Couldn't find RTC");
    Serial.flush();
    while (1);
  }
  
  // Check if the RTC lost power and set the time if necessary
  if (rtc.lostPower()) {
    Serial.println("RTC lost power, let's set the time!");
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }
  
  // Display the login time on the LCD
  lcd.clear();
  lcd.print("Logged In:");
  loggedIn = rtc.now();
  displayTime(loggedIn);
}
void loop() {
  // Read the state of the button
  currentState = digitalRead(BUTTON_PIN);
  // Check for button press (transition from HIGH to LOW)
  if (lastState == HIGH && currentState == LOW) {
    // Sound the buzzer
    tone(BUZZER_PIN, 2000); // Send a 2kHz sound signal
    delay(500);             // for 0.5 seconds
    noTone(BUZZER_PIN);     // Stop the tone
    // Display the logout time on the LCD
    lcd.clear();
    lcd.print("Logged Out:");
    loggedOut = rtc.now();
    displayTime(loggedOut);
    delay(3000);
    lcd.clear();
    // Calculate and display the elapsed time
    long elapsedSeconds = loggedOut.unixtime() - loggedIn.unixtime();
    int elapsedHours = elapsedSeconds / 3600;
    int elapsedMinutes = (elapsedSeconds % 3600) / 60;
    int elapsedSecondsRemaining = elapsedSeconds % 60;
    lcd.print("Elapsed time:");
    lcd.setCursor(0, 1);
    lcd.print(elapsedHours);
    lcd.print("h ");
    lcd.print(elapsedMinutes);
    lcd.print("m ");
    lcd.print(elapsedSecondsRemaining);
    lcd.print("s");
    delay(5000);
    lcd.clear();
    // Turn on the relay