#include <Wire.h>
#include <RTClib.h>
#include <LiquidCrystal.h>
// Connect the DS1307 SDA and SCL pins to the corresponding pins on your Arduino (A4 for SDA, A5 for SCL)
RTC_DS1307 rtc;
// Define LCD pin connections
const int rs = 7;
const int en = 6;
const int d4 = 5;
const int d5 = 4;
const int d6 = 3;
const int d7 = 2;
// Create an LCD object
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
Serial.begin(9600);
// Initialize the LCD
lcd.begin(20, 4);
// Check if the RTC is connected and working
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (!rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// Uncomment the line below to set the RTC to the date & time this sketch was compiled
// rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
// Print a welcome message
lcd.print("Hello, Arduino!");
delay(2000);
lcd.clear();
}
void loop() {
// Get the current time from the RTC
DateTime now = rtc.now();
// Print date and time on the LCD
lcd.setCursor(0, 0);
lcd.print("Date: ");
lcd.print(now.year(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.day(), DEC);
lcd.setCursor(0, 1);
lcd.print("Time: ");
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
delay(1000); // Update every second
lcd.clear();
}