Help with RTC DS1307, does not store the time when power off

Hi I'm a newbee..
I'm using the RTC DS1307 for my final year project. The below codes are, to get the time. However when I restart the board it goes back to the time, when I uploaded the program. It does not even keep the time when it last disconnected. I need to have the correct timing whenever I restart or connect the power supply.
I need some urgent help on this... pleeeeeeeaseee.. :frowning:
Thank you so much in advance...

#include "RTClib.h"
DateTime now;
RTC_Millis rtc;

void setup () {
Serial.begin(9600);
rtc.begin(DateTime(DATE, TIME));

void loop(){
now = rtc.now(); // Get the current time

int h = now.hour(); // Get the hours right now and store them in an integer called h
int m = now.minute(); // Get the minutes right now and store them in an integer called m
int s = now.second(); // Get the seconds right now and store them in an integer called

}

I have coppied only the codes related to RTC module

Have you got a battery backup circuit on that chip?
You need one to keep the time live.

Thank you for the quick reply..
yes I do.. I have the RTC DS1307 breakout board with the battery backup

I have the RTC DS1307 breakout board with the battery backup

Which one there are lots, can you provide a link to it?

Thanks for the link.

In the setup function you have this:-

 rtc.begin(DateTime(__DATE__, __TIME__));

This sets the clock to the compile time of the code. Every time your code is run.

You just want it to be

RTC.begin();

And then it will keep the time that it has without resetting it.

thank you for the reply..
I have already tried that Im getting error saying
'no matching function for call to RTC_Millis::begin()'
What do you think about the breakout board. It's different compared to adafruit and sparkfun ones. I'm a bit worried about this.

I've tried using
RTC_DS1307 rtc;
rtc.begin()

This just displays 06.28 whenever I upload the programme..

What do you think about the breakout board. It's different compared to adafruit and sparkfun ones.

Basically the DS1307 is an I2C device so it should not matter who's library you use the basic chip it is talking to is the same.

Have you tried the examples that came with the library? I downloaded a new version today and the example code is different.
It shows a

 rtc.adjust(DateTime(__DATE__, __TIME__));

To adjust the time not as a parameter in the begin.

rtc.adjust(DateTime(DATE, TIME));

I used the above code as well.. But there is no change in it.. would you mind to share the link for the new version please..

I have downloaded many many libraries for the RTC do you think that would cause any problem.. I tried the other exa,ples.. one uses the internal clock, sive me outpit in the serial monitor.. But other two examples does not give me any output.. :frowning:

I realized that in all the examples they use RTC_DS1307 rtc;
where as I use RTC_Millis rtc;

Does this causing the problem? However it does not work with RTC_DS1307 rtc; =( =(

OMG!!!!!!!!
i just removed the connetions for the real time clock from the arduino.. and it works as the same.. which means i was not using the \RTC breakout board at all...
how do I check my RTC DS1307.. I'm very confused...
Please help me... =( =( =(

Well if it were me I would forget about libraries and just write to the device.
But then that's me. Get hold of the data sheet and just use the I2C commands to read and write to the registers.

I got the library from here:-

how do I check my RTC DS1307..

The best way is with an oscilloscope but I don't suppose you have one do you?
Get an I2C scanner and see what addresses it sees to check that you can see the chip.

There is 56 bytes of RAM in the chip so I would write to that and see if it reads back correctly.

Thank you so much for the help and ideas..
I have started writing to it..
hope it works.. :~