/*
author : Rajeev TR
date : 29/08/2024
https://github.com/HoNtErBoT
*/
#include <Wire.h>
#include <RTClib.h>
RTC_DS1307 rtc; // Create an RTC object
void setup() {
Serial.begin(9600); // Start serial communication
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (!rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// Set the RTC to a specific date & time (YYYY, MM, DD, HH, MM, SS)
rtc.adjust(DateTime(2024, 8, 29, 19, 17, 0)); // Set to August 29, 2024, 12:30:00 PM
}
}
void loop() {
DateTime now = rtc.now(); // Get the current date and time
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();
delay(1000); // Wait for 1 second before printing again
}