#include <Wire.h> // Library for I2C communication
#include <RTClib.h> // Library for DS3231 RTC
#include <LiquidCrystal.h> // Library for LCD
// Initialize the RTC and LCD
RTC_DS3231 rtc;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Set LCD pin connections
void setup() {
// Start the LCD and set its size (16x2)
lcd.begin(16, 2);
// Start communication with the RTC module
if (!rtc.begin()) {
lcd.print("RTC not found!");
while (1);
}
// Optional: set the RTC to the current time
// Uncomment the following line and adjust date/time if needed
// rtc.adjust(DateTime(__DATE__, __TIME__));
}
void loop() {
// Get the current date and time
DateTime now = rtc.now();
// Display the date (DD/MM/YYYY) on the first row
lcd.setCursor(0, 0);
lcd.print(now.day(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.year(), DEC);
// Display the time (HH:MM:SS) on the second row
lcd.setCursor(0, 1);
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
// Delay for 1 second before updating
delay(1000);
}