DS1302 clock interfacing

Hi, I am trying to make a home automation system which will work as per set time. The time is been tracked via a RTC module DS1302 and the micro controller will be Arduino Uno R3. The time I get using the code I found on one of the Youtube video is starting from 1st Jan 1970 00:00:00 and I cannot set my own time so I figured out that it might be because of the battery the module needs so I replaced the CR2025 with CR2032 Lithium battery but still the issue remains that I cannot set the time on the RTC module. Please guide me on what could be wrong I am doing or if the code is not correct. Also, I would like to know that if I can set the time once and even if the arduino is turned off the clock saves the time and continues from wherever it stopped

clock_chck_final.ino (5.58 KB)

lOL.ino (1.13 KB)

Hiya funkymonk16,

I have a hard time understanding the DS1302. It's playground page says the library is a 'drop-in' replacement for DS1307.h, but the 1307 (and 3231) use I2C, while the 1302 does not (it uses a non-standard serial connection.) Have you tried using a 1307, or the newer 3231 chips? I am a huge fan of the 3231, because it's temperature compensated, uses i2c and does not need an external crystal.

I suspect however, that if your module will not keep a set time, even with a fresh battery (and have you tried the 'set clock' example included with the library?) then the module itself is defective. Perhaps the battery holder is not connected properly?

If you look at my YouTube video #5 it describes in some detail the DS1307 and the DS3231 (which is a much better product - more accurate and has a built in temp sensor too).

Both use I2C but if you're going to replace that weird DS1302 for something more standard (and reliable by the sounds of it), go for the DS2131 - the cost, from the Far East, is pretty much the same and you get a much better product.

One final caveat: don't replace a Li-Ion battery LIR3032 (if one is supplied) with a standard CR3032 as there is a charging circuit built into the RTC and the non-rechargeable CR3032 won't like that. You can get ones with and without the Li-Ion batteries but sometimes they don't ship them from China due to worries they will self-ignite whilst in the post!

A standard CR3032 will last an amazing amount of time as a backup anyway especially if the RTC is normally powered by the Arduino.

Url for the videos in my signature on this post - enjoy!

Ralph_S_Bacon:
One final caveat: don’t replace a Li-Ion battery LIR3032 (if one is supplied) with a standard CR3032 as there is a charging circuit built into the RTC and the non-rechargeable CR3032 won’t like that. You can get ones with and without the Li-Ion batteries but sometimes they don’t ship them from China due to worries they will self-ignite whilst in the post!

A standard CR3032 will last an amazing amount of time as a backup anyway especially if the RTC is normally powered by the Arduino.

“the RTC” he is referring to is the most common, the ZS-042. You can modify it to remove the charging circuit, or use one of several others that don’t have that horrible feature.