#include <Wire.h> // Include the Wire library for I2C communication
#include <RTClib.h> // Include the RTClib library for DS1307 RTC
RTC_DS1307 rtc; // Create an RTC_DS1307 object
void setup() {
Serial.begin(9600); // Start serial communication
// Initialize the DS1307 RTC
if (!rtc.begin()) {
Serial.println("Couldn't find RTC. Please check your connections or reset the module.");
while (1);
}
// Uncomment the following line if you want to set the initial date and time.
// rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
void loop() {
// Read the current date and time from the RTC
DateTime now = rtc.now();
// Print the date and time to the Serial Monitor
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
// Wait for a second before reading again
delay(1000);
}