Hi, I'm using a DS1307 RTC to keep time in a solar tracker project I'm building. I'm using the RTClib.h and whenever I try to 'sync' the RTC with my device time, the serial monitor shows some random dates and times. I'm posting my code, in case that's where I'm going wrong.
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 rtc;
void setup () {
Serial.begin(9600);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (true);
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
rtc.adjust(DateTime((__DATE__), (__TIME__)));
}
}
void loop () {
DateTime now = rtc.now();
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(100);
}
I've attached what my serial monitor shows when I run the code. I've rechecked my connections and they seem fine. Any help and suggestions are appreciated.