I am currently trying to interface an RTC with arduino. For this purpose,I am using Tiny RTC module purchased from Ebay
My connections are as follows-
Vcc-Vcc
GND-GND
SCL-A5
SDA-A4
I have downloaded the RTC library from adafruit website and am trying the example code.
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;
void setup () {
Serial.begin(9600);
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
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(1000);
}
Below is the Screenshot of the output I am getting using Serial monitor. I want to ask why does the output(date and time) come correct for the first time and after that becomes incorrect? I am really confused.