Real time Clock with a ATMega328 and a DS3231

One of the first Arduino projects that I started off playing around with was a clock. The project went through various iterations, and served as a learning experience for me. The first few sets of code I ran did not use a RTC (real time clock). At first I didn’t notice, or was not too concerned about the accuracy, but as the project grew more complex, and my code, probably not too efficient, I began to notice that the timing was extremely off. So with the first few instances of the project scrapped, I decided that I need to go the RTC route.

I purchased a few RTC modules, and got them working on the breadboard. I had two modules, one based on the DS1308 and the other on the DS3231, using them on the breadboard is identical. I had etched a few circuit boards thus far, and I was accustomed to using DIP components. So for this project where I’d etch a board, I decided to use the DS1308, as it comes in a DIP-8 package, and I did not want to have to use a separate module in my project. I decided to also go with a DS18b20 one wire temperature sensor and a 16×2 LCD.


I fired up Kicad and set about designing a single sided PCB. Without routing any jumpers across the surface of the PCB, and the fair amount of components the design was not necessarily a breeze, but not extremely complicated either.

2017-05-14-15-51-11 2017-05-14-15-51-25

The etching process turned out pretty well. At this point I was always etching two identical boards at a time, in case one should not turn out. I don’t think this ever was the case, usually both boards were viable, and it left me with a few unused extras. Previously I had been using USB type B connectors, because they are large, easy to work with, and most importantly though hole female connectors. Because of the success with the seven segment display in using a surface mount mini-usb connector, I decided to do the same for this project. (located on the back side)

The project turned out pretty well, with mainly one exception, the RTC I used (ds1308) did not seem to keep the best time. I attribute this possibly to the 32KHz crystal that I used. I’m not sure how they pair the crystals to the chips, or how the modules based on this chip perform better than what I noticed, but it’d perhaps stray a minute a month, which is pretty considerable, and much more than I was hoping for. But all in all, I was happy to get this project off of the breadboard to free it up for other things.




I know the code is in part based on someone else’s code, however I cannot recall where I found it, so I am unable to give credit.

Leave a Reply

Your email address will not be published. Required fields are marked *