I am having a problem in displaying a correct number of year.Previously i had tried run and it showed correct date and but now it suddenly cant display correct year. I had tried to set the date and time.when i changed my computer time into 2014 it displayed 2004 then i tried again changed the year into 2025 it displayed correctly.However things getting more weird is when i changed the year into 2036 it displayed 2026. Both of the pictures i shown are using same programming.Kindly Please help me.Dunno what to do anymore.
Both your sketches produce the correct time and year with my ds1307, Arduino Uno, and IDE 1.6.0.
The set time sketch actually never reads from the RTC to confirm what has been written.
Please run the following sketch after you set the RTC, and see if you can confirm that the year register 0x06 shows 00010101. which is BCD for 15. I would guess that its likely to show 00000101 (5), and for some reason the upper half byte is not being written properly. If that is the case, remove the comments from the line writeNVRAM(0x06, B00010101); and see if you can write it directly.
If indeed it is correct in the register and the read sketch and time library continue to show 2005 we can debug that instead of the RTC.
i have tried out your coding.it is true that it only display 00000101 for 0x06. Then i tried used the nvram write onto it however it still display the same.It seems like can't overwrite. Between i am using 1.0.6 IDE, arduino Mega. Could it be arduino version problem?
In my opinion you have a defective RTC chip, and is not related to Arduino or software.
I had tried to set the date and time.when i changed my computer time into 2014 it displayed 2004 then i tried again changed the year into 2025 it displayed correctly.However things getting more weird is when i changed the year into 2036 it displayed 2026.
It appears there is a defective bit4 (i.e. the 1x10year bit always reads 0), rather than the entire half byte.
This defect can certainly be compensated for in software in an individual sketch by adding 10 to tm.year. You could also modifying the time library #define tmYearToCalendar(Y) for the missing ten years.
Is this ds1307 a raw chip, or a module? There are many defective pirate clone chips marked with ds1307 but they are not legitimate. Many others have had different troubles with defective ds1307 chips or modules. See this post in this thread on how to identify a chip masquerading as a real ds1307. DS1307 Real Time Clock CH bit problem - #13 by CrossRoads - Project Guidance - Arduino Forum
I also have good luck with ZS-042. It has one flaw. It is wired to trickle charge the battery. It's really not the best thing for a CR2032. So I have removed the charge diode on all my boards. My all time favourite is the Cronos. It brings out more pins and allows more flexibility. I also recommend the Christensen library.
Thanks cattledog. i also suspected my ds1307 got some problem. I am using logging shield V1.0 deek robot which is a module. i bought it from aliexpress. can u please teach me how to add another 10 year to tm.year in my sketch?