Picture of DS1307 Mental Health for Arduino Users
Few, yes very few things that I have encountered from playing with Arduino has given me as much grief as the DS1307 modules.  On the surface, these clock-calendar chips and associated break-out boards seem to be a great idea if you are dealing with sketches that must output reasonably accurate time/date over some long periods.  Most breakout boards even come with a backup battery to keep the DS1307 happy when the external power source is off.

But these little marvels come completely brain-dead!  Ignorant... like a battery powered watch, they are useless until set.  But Arduino users generally must load a sketch into their boards, connect the DS1307, and then run the sketch to program the time and date registers.  Which is OK except a month later when you go to check and find that the DS1307 has drifted a couple of minutes.  Well, maybe that is not a big deal for some, but I'm anal and I want my data loggers to have time more accurate than the inexpensive DS1307 modules will support.

I tried buying some quality crystals and replacing the stock crystal.  That actually worked and this is where the 20 seconds every 24 hours shifted to 4 seconds every 24 hours.  Not bad.  But sometimes I do not use the data logger for a few months.  Now, I have to load the Arduino sketch, set the time and date, and then reload my data logger sketch.  Pretty annoying and even though it was just a little thing, it really grated on my psyche.

So, I decided to write my own set routine where I could set the date once and set the time anytime or just "hack" the seconds if that was all that was necessary.  I did not want to deal with keyboards or terminals, so I rewrote a sketch I found for the ATtiny85 which can host an Infrared detector.  With this less-than-$2 circuit, I can now use a $1 universal controller from the "dollar store" and my UNO and Mega sketches do not have to poll for IR since the IR activity is handled separately and the normally unused hardware serial input is used to identify that the remote control has activated the Power Button and IR commands are awaiting.  If the user presses Power on the remote again, the UNO sketch simply returns to doing what it was doing.  The ONLY wasted instruction in the main sketch is just to check the serial buffer:

if (Serial.available() > 0)    // Something from IR is in the serial buffer
Most sketches can live with that!  The test sketch that follows compiles to 13,664 Bytes on an UNO with 32,256 Bytes of flash, or about 42%.  However, much of the code is "library" code and not specific to the DS1307, or to put it into prospective, 23% of the 42% is library code for serial and I2C.

Remove these adsRemove these ads by Signing Up
Most Excellent Instructable Ray !!
A truly Awesome insight into the lazy operation of these DS1307 RTC Modules !!

Im really annoyed at their ability to lose so much time per 24 hours too and am now collecting the parts needed for your great instructable !!!

May i kindly ask you what the frequency crystal is that you used to replace the stock crystal on these modules that eliminated the time-wastage from 20 seconds every 24 hours to about 4 seconds as i would also like to replace the crystal too but clueless as to what frequency crystal should be used !

The DS1307 datasheet says to use a specific 32.768 Khz Quartz Crystal - is this the one you used by any chance ?!?

many thanks in advance for this help !

kindest regards !
RayBurne (author)  offtherails20101 year ago
I had a few of these from another project in my parts bin:

These are 20 ppm and seem to be a a great replacement. I'm sure competitive devices can be sourced from numerous vendors.

Absolutely AWESOME Info - thanks so much !

so sorry about the delay in reply, 20 ppm is the info i never knew about to look for in the crystal specs, are there more accurate than that easily available if you know ?!?
RayBurne (author)  offtherails20101 year ago
NP... generally I have found that the "ppm" will have some impact on pricing... the lower the ppm the higher the quality and the higher the price. This is just a rule-of-thumb and does not always apply since volume manufacturing also plays a part. We hobbyists enjoy lower prices on parts that are used in general high volume electronics.
TheRafMan1 year ago
Neat set up and I like your approach. I am anal about accurate time also (why bother keeping track otherwise?). I ended up building one without a clock module using only a network shield attached to a small wireless access point that routinely checks the timeservers every 6 hours... I will post it soon once I feel it is ready, still testing it and it seems pretty stable so far...