Introduction: Full Binary Clock

Picture of Full Binary Clock

I was wandering the internet looking for a good arduino tutorial on how to build a binary clock with seconds, but I could not find one. So now I am  writing this for you to have a binary clock with seconds, minutes, and hours.

What I did:
-Because controlling 20 LEDs individually for this cube would be messy, I multiplexed.
-I used an ATtiny84 and a SN74HC164N to control the clock. This makes the clock cheaper and smaller.
-I built it all on two PCB boards and affixed a stand, power plug, and buttons.

Step 1: Parts List

Picture of Parts List

Somethings you have to have to make a binary clock, others are optional and I will try to give you ideas to use what you have.

Required Parts:
-20 LEDs, any color I used 5mm I wouldn't recommend 10 unless you have the space
-6  PN2222 transistor, or any that you have that are simmilar
-2  push buttons, any flavor of interface you want to try would work buttons are easy
-2  1K resistors, for the buttons
-10 resistors for LEDs, i used 470ohm you could use as low 100ohm but they would be very bright at night
-various wire for connections

  -I used ATtiny84 and SN74HC164, I choose it because it was small, cheep, and easy to use with this option you will use the shift register to control one side of the LED matrix 
  -ATmega, any of this series would work as long as you have a programmer and the space
  -Arduino Board, I don't recommend spending the money on this option and it also takes up a lot of space
  -ATtiny with only 6 I/O if you use two shift registers
  -The library is written for arduino and feels free to use anything else that you would re-code
 *Use a DIP socket for whichever controller you choose to use.
  -I used USB charger and cable to power it
  -any 5V power supply would work, just make sure it works with your controller
  -Some type of board is needed. I used two small boards, 4cm x 6cm and 3cm x 7cm. I have seen cardboard used for the LEDs but i do not recommend cardboard for the controller.
  -I used polymorph, it's cool stuff to have around
  -origami would work


Step 2: My Multiplexing

Picture of My Multiplexing

I use the SN74HC164 shift register and PN2222 transistor to shift on each column of the LED matrix to ground faster than the eye can see. When the correct column is grounded then the ATtiny then outputs HIGH to the LED that represents the time.

When a the transistor emitter is connected to ground the transistor will provide ground, from collector, if the base is connected to Vcc.

Step 3: Wiring

Picture of Wiring

Wiring will depend on your design choices but here are the connections you need to make.

1. Solder your LED matrix as in the diagram, note it is drawn from the back make sure the cathode and anodes are corrected to ground and Vcc, respectively
2. Connect the LEDs ground to the emitter of the transistor
3. Solder the push buttons and DIP sockets on the board 
4. Connect power and ground to all the right parts
5. Connect the 1K resistor to ground and the resistor, connect Vcc to the push button, and connect an input of the ATtiny to the push button
6. Solder the 470ohm resistors next to the DIP sockets, 6 go to the SN74HC164 and 4 the outputs of the ATtiny
7. Connect the 6 resistors to the base of each transistor, they need to be in order of A-F so they multiplexing works
8. Connect the 4 resistors to each anode layer
9. Connect 2 outputs of the ATtiny to the clock and data of the shift registor

Step 4: Build a Stand

Picture of Build a Stand

I used polymorph, this is not necessary. Use whatever material you want to support your clock.

Step 5: Programming the ATtiny84

Picture of Programming the ATtiny84

If you have an arduino you also have a free In System Programmer (ISP)

1. Connect the following:
    Vcc to  pin 1   on ATtiny
    Gnd to pin 14 on ATtiny
    D10 to pin 4   on ATtiny
    D11 to pin 7   on ATtiny
    D12 to pin 8   on ATtiny
    D13 to pin 9   on ATtiny
2. For the rest follow instructions here

(If that site is down then here is a different instructional on it with the file attached to this step.
Or here as a third backup )

The instructions are great and easy to use.

Step 6: The Code

Picture of The Code

The code is divided into functions to make changes easier.

Step by Step Walk Through:

This sets up all of the pin outs for the ATtiny

assigns pinMode to all pins
I had problems with configuring my binary clock to be the same as my watch so i added a configuration setting, pressing the hour button bypasses this option
shiftOut send the byte of data 0xff, B11111111 in binary, to the shift register this turns on all columns
digitalWrite then lights up one layer
then it waits for the hour button or the minute button; the hour button skips the adjustment process the minute starts the timmer
another layer lights up and begins counting
when you are done with 60 seconds press the HOUR BUTTON, it changed buttons 

lastSecond stores when the clock added a second, if it is over the testTime then it adds a second
testTime was configured or bypassed earlier the default is 1000
the if()s evaluate if the minute or hour need to be changed, I added an if() not used if you want your minute button to count down
all of the unit variables sUnit, mUnit, and hUnit are given the value of the ones place for seconds, minutes, and hours
the buttons are then asked if they are on
the function activate() is called, described next

this will turn on all of the LEDs for the current time
*a note about not using a shift register, use the one labeled that - I haven't tested so i hope it works for you
when the clock is LOW data can be written to it and will be shifted when clock is pulled HIGH
doing this while allowing for the layer to be activated
there is a delay so your eyes will see the LED
then all of the layers are turned off before the next layer is loaded
rinse and repeat...

one, two, four, and eight correspond to the value of the LED, in binary, will be turned high or low...
its a lot of numbers that will blink in the way know to be a clock

turns on the layer corresponding to the time value



NickM135 (author)2016-09-24

Hi i would like to ask you a couple of questions, do the switches need a power supply? I have 2 terminal switches can I use them or do I need 4 and what would they and the usb come under in circuit Wizard program. Also could this device be powered from a battery? If so how? Many thanks for your time. Or anyone who helps me

AffanA7 (author)2016-09-08

How can I use an RTC module with this?

NickM135 (author)2016-06-14

Hi could you put a schematic diagram of how to wire up an Arduino in place of the Attiny84? As really struggling to program the Attiny84 and happy to use an uno for this project. Thank you so much regards Nick

NickM135 (author)2016-06-14

Hi could you put a schematic diagram of how to wire up an Arduino in place of the Attiny84? As really struggling to program the Attiny84 and happy to use an uno for this project. Thank you so much regards Nick

NickM135 (author)2016-06-14

hi i am unsure of how to wire up the buttons i have 2 momentary switches i understand that the 4 pins are connected in 2's what does BL BR TL TR mean? also my buttons have no indication of which way round they go please help im new to electronics many thank Nick

KyleH26 (author)2016-03-11

just spent the last 5 hours building this! and.... i messed something up the minute and seconds blink together and the hours do not light up at all.....

sbbrain (author)KyleH262016-03-12

You can try to light up the array without the code. Attach 5V to a resistor and try to light up each of LEDs one at a time. This will tell you if it is a hardware or software. If the hardware is wrong rewire. If the code is wrong just double check it for errors.

Prem_Sagar (author)2016-02-04

How do you set the time? and is it possible to run it on a coin battery ?

sbbrain (author)Prem_Sagar2016-02-05

You set it from the two buttons on the front.

The coin button is 3.3V while I ran my clock at 5V. I think the ATtiny can run at a lower voltage but it involves changing the clock speed.

mike.thorn.777 (author)2015-02-23

so i got the programming to take i want to make sure that the pin 13 from the Atiny84 connects to pin 1 & 2 on the second chip and does TL and BL of each button connect together

mike.thorn.777 (author)2015-02-23

so i got the programming to take i want to make sure that the pin 13 from the Atiny84 connects to pin 1 & 2 on the second chip and does TL and BL of each button connect together

mike.thorn.777 (author)2015-02-16

how do you know if the programming took on the Atiny84 chip

sbbrain (author)mike.thorn.7772015-02-16

The first thing I always do with a new chip is run a blink program to test the programmer and microcontroller. Than if you see a blinking light it works.
One problem I had with the attiny a lot was the arduino being programmed and not the attiny. Sometimes the code would be on the arduino and I'd have to reinstall the isp file.
Hope that helps, if not I'd need more details on your situation.

Leonelf (author)2014-09-16

But that's not binary, it's BCD (Binary Coded Decimal)! Anyways, cool project!

MalcolmV8 (author)2013-11-30

Looking at your schematic I don't see how you could turn on LED4 and LED8 without LED7 inadvertently powering on as well. It shares the power of LED4 and the ground of LED8 and will turn on too. What am I missing? That's just one example. Thanks.

folivito (author)MalcolmV82013-12-01

I have built a few clocks. First time with Arduino. I used the 5v off the board to power clock and the Arduino board shuts off. Must be a short in the clock PCB? Any Ideas?

sbbrain (author)folivito2013-12-01

Does the power light slowly turn off? Could be bad resistor, transistor, or LED. So test each of them individuality.
If plugged into the computer does it tell you the arduino is unplugged as soon as it is plugged in? Probably a short. Check with Ohm meter.

folivito (author)sbbrain2013-12-05

Hi sbbrain
I tested all the resistors and found R1 and R2 bad. I replaced them and now the Arduino does not shut down when I plug in the clock board. I tested all the LEDs and found them all ok. I have 5v at all the switch pins. No voltage at the LEDs or transistors. on the ATtiny I have 5v on pins 1,4,10,11 on the 74HC I have 5v on pin 9, 4v on pin 14 and 2.2v on pin 8
I used ExpressPCB to make the PCB. From your schmatic i connected all GNDs to chassis ground and all the Vcc to 5v power from the Arduino board. On your schematic at pin 9 Vcc on 74HC there is a circle. Not sure what that means. I have 5v on all the switch pins

Thanks for the help

folivito (author)folivito2013-12-03

Hi sbbrain
Hey thanks for the reply. The 'L' and 'ON' LEDs are on but when I plug the clock circuit in they waver and turn off and remain off until I disconnect the clock. I will check each resistor. I will check the clock circuit with an Ohm meter.
I downloaded your code to the ATtiny with no problems. I will let you know the outcome.

sbbrain (author)MalcolmV82013-12-01

Multiplexing. The idea is to only allow one column to be grounded at a time.
So there are 6 columns and only one of them turns on at a time while the 4 anodes layers are turned on or off. Make Sense?

MalcolmV8 (author)sbbrain2013-12-02

So the LEDs are actually turning on and off at a high refresh rate that the eye cannot see? So anode row 2 turns on and the corresponding grounding transistor turns on, then anode row 3 turns on and the corresponding transistor and this goes back and forth many times a second creating the illusion that the corresponding lights are on? Interesting. When I've seen multiplexing in the past it was more simplistic was using shift registers to light LEDs but each output went high and turned on a specific led without a refresh rate. So what is the recommended refresh rate for multiplexing?

sbbrain (author)MalcolmV82013-12-02

Not quite every LED at separate times, say column two is grounded and it is 17 hours LED 4, 5, and 6 should be turned on in order to read 7 in binary. So very fast, at 17:26:30, the LEDs will be turned on in the first column and a 1 will be displayed. It will be left on for short enough time to not see flickering while long enough for it to be bright enough. Then column two, three, four and so on each displaying their number.

MalcolmV8 (author)sbbrain2013-12-02

Got it. Thanks. Looking at the supplied Arduino code with this Binary clock it would appear to cycle through the rows and columns at the speed of the Arduino's clock. I'm not seeing any delays in the code except for when a user presses the buttons and of course the increment of the seconds every 1000 milli seconds. The activate() function is called to refresh the display on every irritation of the man loop.

folivito (author)2013-12-03

The Full Binary Clock is so cool. I can't wait to have it up and running.

ma901ccmb (author)2012-11-25

hi there, i wanted to make this clock and i wonder if you could provide a Fritzing breadboard schematic for this. i'm new to these kind of stuff and i'm still learning using my first arduino kit, which consist of the arduino uno. i read in the comments that someone has already asked for an improved schematic, but, considering i'm new to this, i'm finding it difficult to understand it. i would gratefully appreciate it. thank you.

r2p2 (author)2012-10-31

Would it be possible to get a schematic for the circuit? I would really like to make one of these.

sbbrain (author)r2p22012-10-31

Check out the new and improved Step 3.
Hope that gives you all you need.

r2p2 (author)sbbrain2012-11-01

Thank you very much for the schematic, I will be starting on this today. One quick question, is the button you're using a dpst switching between normally power and ground through a resistor one one side?
Thanks again

sbbrain (author)r2p22012-11-01

Opps I forgot to label the resistors on the buttons, they should be 10k ohm.
But this is how a button looks in the real world.
It's wired just like mine.

randyohoh (author)2012-08-11

excelent! oh for a schematoc!

Libahunt (author)2012-08-09

You say "10 resistors for LEDs, i used 470ohm you could use as low 100ohm but they would be very bright at night". But I understand that actually only 4 of them are in series with the LEDs and influence their brightness and should be chosen according to the desired brightness. The other 6 resitors are connected to transistor base and should ensure that the transistors go to saturation mode. I don't know how this is calculated or if the resistor value is important at all. So 470R worked fine there? And am I correct at all or not?

sbbrain (author)Libahunt2012-08-09

I used all the same resistors and it worked fine for me. As I unsderstsnd it if you are using the same value resistors it will work. I have also see common emitter configurations that use 1k resistors between data and the base pin. So I don't believe the resistor used for the transistor is inport ant with this number of LEDs.
That said, I also used transistors on a 4x4x4 LED cube and didnt feel like using resistors between the data and the base and it works fine.
Hope that helps.

amandaghassaei (author)2012-08-08

great use of ATtiny!

About This Instructable




More by sbbrain:Plex BotPrintrbot Upgrades25x8 LED Hat, for parties and other useful things
Add instructable to: