#include <Wire.h>
#include <LiquidCrystal.h>
#include <RTClib.h> // RTC library for DS3231 or DS1307
// Initialize LCD and RTC
LiquidCrystal lcd(9, 10, 5, 4, 3, 2);
RTC_DS3231 rtc; // Use RTC_DS1307 if you're using the DS1307 module
void setup() {
lcd.begin(16, 2); // Initialize 16x2 LCD
if (!rtc.begin()) { // Check if RTC module is connected
lcd.print("RTC error");
while (1); // Stay here if no RTC is found
}
}
void loop() {
DateTime now = rtc.now(); // Get current time from RTC
// Display time (HH:MM:SS)
lcd.setCursor(0, 0);
lcd.print(now.hour());
lcd.print(":");
lcd.print(now.minute());
lcd.print(":");
lcd.print(now.second());
// Display date (DD/MM/YYYY)
lcd.setCursor(0, 1);
lcd.print(now.day());
lcd.print("/");
lcd.print(now.month());
lcd.print("/");
lcd.print(now.year());
delay(1000); // Update every second
}