Newbie Clock Project with ATTiny85 & DS1307

Hey guys! I thought I would ask the PROs before etching this out on double-sided PCB (see image at bottom).

It's a very basic design for a clock that's based on the ATTiny85 and takes advantage of the DS1307 for time-keeping. I'm not sure what my problem has been in the past where I have not been able to get such a simple thing running (the ATTiny85 and LCD have worked fine, but not the DS1307). I think it has to do with buying cheap DS1307s from eBay but finally I ordered some from a reputable website (at a price).

The DS1307 ($3.75) will arrive later in the week so I want to make sure my design will work before frying the poor thing. What I have done differently with the following PCB design is adding a ground plane for the first time and especially in-between the digital lines.

Can any of you PROs out there quickly review my design and tell if you see any mistakes?

Buying cheap saves money but can waste time and end up costing more in the long run (doesn't hurt to try though, right?) LOL


So I'm going to have the thing powered by a Micro-USB adapter and have a line running through the board supplying the 5V to the different components.

A ground-plane will ground the components to ground and be used to minimize noise in-between the I2C lines as I have had problems with it before (I'm pinpointing it to cheap chips).

My main worry considering that I know the LCD and ATTiny85 work properly when using I2C is having the DS1307 properly connected. I have read in other posts that I should have the crystal grounded (which I have done in this layout) and to add a .1uF capacitor to 5V on the DS1307 (I have yet to do so.)

I'm basically going to have a 20x4 LCD at around 45deg on the upper-portion (with it's potentiometer sticking up on the left) and a 6 button interface at 0deg on the bottom-portion covering the whole thing.

Thanks for your help! I wish to provide the PCB artwork and schematics to the public on my website if it turns out to be a success.

When you say the DS1307 did not work, what didn't work? no communications at all? wasn't keeping time correctly? There are a million things that could go wrong and with no code and no schematic it's kind of difficult to tell you if this would work. One thing I've learned about these DS1307 is that they are very picky as to which crystal you use. The datasheet states you should get one with 12.5pF capacitance which apparently is not so common (you may need to add additional caps) and it was becoming a pain. That's why switched over to using the DS3231 which has an internal heat compensated oscillator and is almost one to one code compatible withe the DS1307.


I would add a 10K pullup on the tiny's reset pin, and a 0.1uF cap close to the power pins of each chip.

I would also think about breaking out the tiny's spi pins to the standard 2x3 pin pcb header connector so you can reprogram the chip without removing it.

My main critisism would be the choice of the tiny85 in the first place. You have added the pcf8574 to give the tiny more i/o pins so that it can drive the lcd. It would have been simpler and cheaper to use an mcu with more pins so that the pcf chip wasn't needed. The tiny85 and pcf8574 have 24 pins between them. An atmega328 has 28 pins which is only 4 more, and there are tiny chips with 14 and 20 pins.

That said, well done! You have had to learn quite a few skills to get to this point.


update Sorry for my mouthy post, I was kind of under the influence of alcohol. /feeling bad for his behavior

I have problems with various DS1307s not responding but they were bought for dirt cheap and they are obviously not authentic. I have a separate little DS1307 board that works like a charm so I'm wondering what the problem is with these. I'm against a wall because my unauthentic Arduino Uno stopped working properly as it won't run I2C scan.

I went ahead and ordered an Authentic Arduino Uno but I won't blame myself for not doing so before because it is a pricey little board especially when you are a newbie and you know you would damage it no matter how well built it was. Now I think I have the discipline to handle it with care as I bought a little case for it too. I also ordered an authentic DS1307 and I am sure it will run as intended especially with the code I have backed up on my computer that previously worked well too.

These arrive tomorrow so I will put my heart into it. I also went ahead and modified the PCB to include capacitors (thanks for the suggestion) and will include a programming header too. Awsome ideas guys!

I doubt the crystals are the problem since they previously worked and according to my records they are 12.5pf. I want to program ATTiny85s as an educational experience to discover their limitations. From there I will advance to more complicated microcontrollers like the ATMEGA328 which I have plenty of lying around waiting to be discovered after I finish this project. I also have a pair of Cortex M0 DIPs lying around.

Thanks for the great ideas guys! I will post results in a day or two.

Here is a useful pinout diagram which shows the various attinys and mega328 and the 6-pin icsp header. There is also a 10-pin version of the header which may be more convenient depending on the programmer you are using.

As for switching the icsp header, you don't need to, if you can organise your attiny pins so that there is no danger of a short with other components. Looking at your circuit, I don't think you will need switches to isolate the icsp header, because the chips on the i2c bus should just ignore the icsp signals (they won't make any sense as i2c signals) and you may get some unpleasant but harmless noise from your speaker during programming.

That speaker, by the way... is it a piezo? if so, driving it with a transistor may not be of any benefit. If it is a magnetic coil speaker, you may need other components such as a cap to filter dc current.

Yes it is a piezo and I did not notice any improved performance either. I will go ahead and take the transistor out and implement the ICSP header. I use a 10-pin USBAsp to program with either way so that will definitely save me some time when programming it and should be something to be included in all of my future projects. Thanks for the heads-ups!

Here is my updated PCB, I will double-check the connections tomorrow as I did this before going to sleep. I'm hoping that the programming header traces can be kept at a minimal width in order to fit them aesthetically. Plus, it won't be a problem soldering under my new 40X stereo-microscope.

Couldn't of have done it without you guys!|500x366

simipleis the LED on the power line a 5 volt LED ? guess that saves a resistor.

I am not fond of a cap and a resistor so close as in the dead center of the board. no reason for them to almost touch.,

for small and simple boards, I use simple and cheap etch, get 10 boards for $20 or some such.

get lots of extra holes to allow for jumpers. and have all the traces from pins a bit long to allow for cutting them.

Looking at latest version of your layout, I think I see an error on the track from the tiny's ground line. Should part of that be on the other layer? It seems to cross/short with another track. I also think you should try to get all 10 pins on the icsp header. It will be difficult to solder them in straight unless you use strips of 5.

Want more suggestions? This one is only half thought-through...

This is an alarm clock. You don't want a bright backlight on the lcd lighting up your bedroom when you're trying to sleep. But during the day, you need the backlight as bright as possible to be able to read the display, unless you can find one of those that are naturally readable in daylight. You could use that unused attiny output, which I think is PWM capable, to drive the lcd backlight. You would also need an analog input for an ldr to sense the light level, but none are free except ADC0, which is also the reset pin. The pin can be changed from reset to adc by changing fuses, but I have no idea how you would re-program it without the reset function. There are a couple of pins free on the pcf chip... maybe those can be used in some way...

Yah I'm a fan of cheap components especially from like China. I got me some 20pcs of good ol' double-sided PCB that is the exact size of my board in the picture. I will do as you said and space out the resistor and capacitor. For the LED I think the resistor is necessary since the schematic for the DS1307 specifies a resistor to be present for the SQW output. Someone in a different thread recommended that trick to get a tick through the LED from the SQW.

I'm using one whole ICSP header socket so it won't be hard to solder, ... it will actually be more easy with those unused pins out of the way. As a newbie believe me or not the 20x4 LCD actually attracts me. Plus, I am doing the project to learn more about programming than soldering so I'm hoping I can simply just set it to time out after a minute and light up when I press a button. Thanks for pointing out the short, I will remedy it right away.

ANYWAYS, so I got my Authentic Arduino Uno in the mail but I ended up frying it. I'm not a perfect person but I know how to follow directions. It turns out that the authentic DS1307 that I also got works great but only when powered by the Arduino 5v and GND. Unfortunately as I was testing I accidentally shorted 5v with VIN so my Arduino warmly kissed me goodbye.

As I gave up resurrecting the Arduino Uno, and decided to take a nap... in my mind a little free wiggly leg attracted me back to my breadboard. Plus, luckily my unauthentic Arduino Uno from China still worked so I tested out powering the DS1307 from a pin set to output. Voila! It works in such a way.

Luckily for my project I have a free pin on the ATTiny85 (sexy lil' thing) that I am going to use to power the DS1307. Any other way the DS1307 won't work. Not with 3 different types of adapters, voltage regulators, or even a self-powered breadboard.

Crazy day' Do any of you know if the 5V pin on the Arduino Uno originates from the ATMEGA328 itself? Oh, and is VIN intended to power the Arduino but without the power jack connected? I can't think of any other use for it.

---------------- my new sig.-------------------- "Hey, I at least can say that I actually fried one of those things." ~Chamayo

The 5V pin on uno connects to a circuit that auto switches between output of the 5V regulator and 5V from usb, I think. The same line connects to the Vcc pins on the mega328, but the 5V does not come "from" the mega328. The only difference I can think of that might explain your ds1307 problem is that the voltage sources that make it work is slightly lower than those that don't work. Try connecting the ds1307 power via a diode (silicon=0.7V drop, germanuim=0.2V drop).

Yes, Vin can be used to power the uno using an external 5V supply, or supply external circuits from the uno's 5V supply from either the power jack via uno's regulator or usb power.

The problem ended up being unrelated as it turned out to be that TinyWireM.begin(); was missing in my code. It all works great now as the ATTiny85 is commanding my DS1307 successfully.

update how embarrassing that the problem ended up being a software anomaly, as I promise that the programming that worked A-Okay at first started little by little failing. It's great that I got so much help hardware-wise from you guys that led me to the same forum with the suggestion to check the bundled tiny_i2C sketch for a clock example. I don't regret doing what I did as I will toss the ol' for scrap parts and bring in the new even better than before'

Here is a picture of my progress (it's final weeks so I'm lucky to have gotten so far): |500x375

The clock works especially when backed up with a coin cell. The buttons as you can see that I removed off a remote control works great too. The display at the moment is reading out the default debug information when no button is pressed.

The only thing that doesn't work is the reset button in the back that you can't see but I'm guessing I should raise the resistor value.