DS1307

Sir. I really don’t get it why it keep on resetting if I remove the supply. My RTC module has a back up 3.0v. I am using mega2560 and DS1307. Is it the program or the module? Here’s the code

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib

#include <Wire.h>
#include “RTClib.h”

RTC_DS1307 RTC;

void setup () {
Serial.begin(57600);
Wire.begin();
RTC.begin();
//RTC.adjust(DateTime(DATE, TIME));
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();

Serial.println();
delay(1000);
}

thank you! Happy New year

When you say “keep on resetting”, you mean the time gets reset?

Does the serial print indicate that it’s not running?- because if that’s the case it will be re-setting the time to the compile time.

Maybe your external battery is flat?

JimboZA:
When you say “keep on resetting”, you mean the time gets reset?

Does the serial print indicate that it’s not running?- because if that’s the case it will be re-setting the time to the compile time.

Maybe your external battery is flat?

Yes the time gets reset. In indicate the the RTC is running. The external battery are new. Is it possible that the problem is in the RTC though it gives real time when I upload it?

How do you know it's being reset, anyway?

JimboZA:
How do you know it's being reset, anyway?

It gives the time when it was uploaded. And sometimes it gives a wrong date and time.

I'm very confused now. List exactly the steps you've followed, and are following, and explain what happens each time.