Arduino 1307 clock
May 1, 2010 Leave a comment
The project I am currently working on requires as accurate time keeping as possible on the arduino. There are a few commercially available external clocks such as spark fun’s generic modual or the ChronoDot temperature compensating unit, however both cost more than $10 and are thus more than my project can afford.
This video here shows how to keep accurate time with just an arduino by compensating in code for the variance of your particular 16 Mhz crystal. The down side is that it is only accurate within about a minute per day. Boo 😦
My solution is to build my own 1307 module.
A Maximum ds1307 RTC – (Maximum can send you free samples, don’t abuse it)
A 32.768 crystal – Hint, you can find these on dead motherboards or most any electronics that keep time. Or buy one here.
A coin Battery – again, dead motherboards are a great place to get them, or buy this one.
Once you have the parts, it is a simple matter of wiring it according to the schematic. There are 3 output pins, SQW, SCL, and SDA. You only need the second two. If you have everything wired correctly, then your RTC should be silently ticking away. It will continue to do so for years as long as the battery stays connected.
The next step is to interface it with a micro controler such as the Arduino. People in the arduino community have been nice enough to create a library for the 1307 on the arduino. It includes the commands to read and write the current time to the chip. You can download it here. A full article with pinouts and code is available here. If you are wanting more, take a look at this blog here.