28
Let’s make an Arduino real time clock shield
arduino, arduino shield, CR2032, DS1307, education, freetronics, Practical Arduino, project, projects, protoshields, RTC, save money, tronixstuff Comments Off on Let’s make an Arduino real time clock shield
Hello fellow Arduidans
Today we are going to make a real time clock Arduino shield. If you have been following my tutorials, in weeks 7, 8 and onwards we have been making use of the Maxim DS1307 real time clock chip. Although it is a very interesting part to use, implementing it has not been so easy, therefore the reason for this shield. So let’s go!
First of all, we need create our circuit diagram. Thankfully the Maxim DS1307 data sheet [pdf] has this basics laid out on page one. From examining a DS1307 board used in the past, the pull-up resistors used were 10k ohm metal films, so I’m sticking with that value. The crystal to use is 32.768 kHz, and thankfully Maxim have written about that as well in their application notes [pdf], even specifying which model to use. Phew!
So here is the circuit diagram we will follow (click on it to enlarge):
Which gives us the following shopping list:
- One arduino protoshield pack. I like the yellow ones from Freetronics, however others may prefer this one
- X1 – 32.768 kHz crystal – Citizen America part CFS206. You should probably order a few of these, I broke my first one very quickly…
- IC1 – Maxim DS1307 real time clock IC
- 8-pin IC socket
- CR2032 3v battery
- CR2032 PCB mount socket
- R1~R3 – 10k ohm metal film resistors
- C1 – 0.1 uF ceramic capacitor
And here are our parts, ready for action:
The first thing to do is create the circuit on a solderless breadboard. It is much easier to troubleshoot possible issues before soldering the circuit together. Here is the messy test:
Messy or not, it worked. Instead of writing another sketch, the example 7.3 from arduino tutorial seven was used. Here is a copy: example 7.3.pdf.
The next step is to consider the component placement and wiring for the protoshield. Try not to rush this step, and triple-check your layout against the schematic. As my protoshield has a green and red LED as well, I have wired the square-wave output to the green LED. You can never have too many blinking lights…
At this point I celebrated the union of tea and a biscuit. After returning to the desk, I checked the layout once more, and planned the solder bridges. All set – it was time to solder up. If you have the battery in the holder for some reason, you should remove it now, as they do not like getting warm. Furthermore, that crystal is very fragile, so please solder it in quickly.
And here we are – all soldering done except for the header sockets. At this point I used the continuity function of the multimeter to check the solder joints and make sure nothing was wrong with the circuit.
Final checks passed, so on with the headers. To make this easier, I stick some header pins in the sockets, then place the whole lot in a solderless breadboard to keep it straight. Well, it works for me:
Just a side note – always make sure you have enough consumables, the right tools, etc., before you start a project. This is how much solder I had left afterwards…
Moving on … in with the battery and the DS1307 – we’re done!
It is now time for the moment of truth – to insert the USB cable and re-run the sketch… and it worked! The blinking LED was too bright for me, so I de-soldered the wire. If you are making a shield, congratulations to you if yours worked as well. If it did not, don’t be afraid to hit me up via email or our Google Group with your questions. Note that if you are using this shield, you cannot use analog pins 4 and 5 – they are being used as the I2C bus. Time to clear up the desk and wash my hands.
Now to put this shield to work. Last week we made an LCD module shield – so let’s pile up the shields and make a digital clock. We can re-use the sketch from arduino tutorial example 7.4, with the liquidcrystal() corrected to use the LCD shield pins. Here is the modified sketch: ds1307shielddemo.pdf.
And my post wouldn’t be complete without a video, so here are our new shields in action!
So there we have it. Another useful shield, and proof that the Arduino system makes learning easy and fun. High resolution photos are available on flickr. If you have any questions or comments, please leave them below, or consider joining our Google Group!
As always, thank you for reading and I look forward to your comments and so on. Please subscribe using one of the methods at the top-right of this web page to receive updates on new posts!