Introduction: Binary Marble Clock

Picture of Binary Marble Clock

This is a simple clock that shows the time (hours/minutes) in binary using leds hidden beneath glass marbles.

For an average person it looks just like a bunch of lights, but you will be able to tell the time by just a quick glance at this clock. It might take you a couple of days to get up to speed on the esoteric art of fast binary counting, but you'll be able to tell the time right away, just a bit slower in the beginning.

Here's a instructable of counting in binary Binary counting.

Step 1: What You Need

Picture of What You Need
  • One Atmel Tiny2313 microcontroller
  • One 0.1 uF capacitor
  • Eleven resistors - 120 ohm
  • Eleven high brightness leds. I used 6 white and 5 yellow
  • One 10 MHz crystal
  • Two 20 pF capacitors
  • One small pushbutton
  • Eleven glass marbles
  • A nice piece of wood to mount it all on

The picture below are missing the leds and resistors...

Step 2: Preparing the Base

Picture of Preparing the Base

I took a a piece of wood( 3x2 cm , 50 cm long) that I found in a closet and used that as a base for the clock.

I started by drilling eleven 5 mm holes straight through for the leds. On the top I then used a 12 mm drill and drilled down like 7 mm at each 5 mm hole to get an indentation for the marbles to be put into. On the bottom I used an even wider drill and drilled out a huge chunk of wood over each led hole and then I chiseled a trench between the holes so the cables can be put there.

In the middle between the hour- and minute-leds I drilled and chiseled out a huge crater to put the electronics into.

After sanding it a bit and painted it all with a dark brown color.

Step 3: Soldering the Leds & Resistors

Picture of Soldering the Leds & Resistors

The leds have one short lead (minus) and a long led (plus). Insert all leds turned in the same direction and then solder all the short leads together.

Solder the 120 ohm resistors on the long leads.

Solder a wire long enough to reach the middle of the clock to each resistor.

Step 4: The CPU & Crystal

Picture of The CPU & Crystal

I didn't bother to make a circuit board for this project, it's easier to just solder it all together in dead bug style. (Actually I would rather call this a squashed bug because the chip is not turned upside down, but it's flattened out/squashed... ;-)

Begin by flashing the software into the chip (ATtiny2313) and test it to make sure that it works.

Then flatten the chip by angling all the leads outwards.

Solder the crystal to pin 4 & 5 on the chip. I ran the leads of the crystal on the bottom of the chip to get them out of my way.

Solder the 20 Kohm resistor between pin 1 (reset) and pin 20 (plus).

Solder the two 20 pF capactitors to pin 4 & 5 and then solder them both to pin 10 (minus).

Solder the 100 nF capacitor between pin 10 (minus) and pin 20 (plus).

Step 5: The Button

Picture of The Button

Chisel out an indentation for the button in the wood and connect the button to the wire that are connected to all the leds. Then solder another wire long enough to reach the microcontroller to the other pin of the button

Step 6: Wires

Picture of Wires

Solder the wires coming from the leds and the button to the microcontroller.

The led first led (the led farthest down) is the Minute-1 led up to the led for Minute-32 that should be just beneath the microcontroller. Above the microcontroller is the Hour-1 led.

Don't forget the wire coming from the button, solder that to pin 11 on the microcontroller.

End with soldering the power wires to pin 20 (plus) and pin 10 (minus) on the CPU. And yes, there's one final wire to do - solder a wire between the pin 10 on the microcontroller to the long wire connecting all the leds (and the button).

Finish it off by using hotglue to hold down all the wires into the trenches in a neat and orderly fashion.

Step 7: Schematic

Picture of Schematic

The schematic is so simple and there's no circuit board so only made a handdrawn schematic.

Step 8: The Software

Picture of The Software

The software is written in C for the Atmel using GCC.

There are really nothing special about the software. Timer0 is used to generate interrupts every 1638.4 uS and the Bresenham algorithm is used to make sure that the clock ticks at average every second.

After power on the the clock displays a dot that flashed up & down to indicate that the time must be set.

By pressing the button the time advances as a slow rate for 15 seconds and then speeds up. If the button is just pressed momentarily (0.1-0.5 seconds) the time is decremented by one minute for easy adjustment.

Step 9: The Finished Clock

Picture of The Finished Clock

Glue the marbles by using a dab of hotglue and it's done!

Apply 5 volt to it and bask in its glory.... :-)


Chein (author)2011-03-06

This is cool! I'm gonna make one. Btw, just wondering where do you normally source for parts? Around KL/PJ or online?
P/S: Are you by any chance the same guy who came up with that QuaterK shield? Love that too :)

matseng (author)Chein2011-03-06

Sometime I go to Jalan Pasar in the Pudu area, but usually I just order from Farnell/Element14. They have free next day delivery so it's quite convenient.

Since I travel to Bangkok twice a month I get a lot of stuff from the shops in the Ban Mo area there. I get standard components in bulk from there like 1000 packs of 0.1uF decoupling caps.

For the 200 QuarterK kits I did a while ago I got almost everything from the Chinese merchants on The prices there is less than 50% than the already cheap Ban Mo-prices. But you have to wait for the shipping a bit longer and also use a shipping agent that will repack your stuff and send it to you since the merchants don't ship overseas and usually don't understand English.


hiromato (author)2009-12-12


Very nice instructable! I've built the clock, but I had no 10 MHz crystal so i used a 20 MHz one instead. I've been fiddling around with the code to compensate for this but have, so far, been unsuccessful. Without changes to the code one minute on the clock equals exactly 10 minutes in reality. What parameters should i change to make it run correctly?

aliasjanedoe (author)2009-10-08

Why do you have 5 hour lights instead of 4?  Are you doing military time, 24 hours rather than 12?

Very nice clock, BTW.  I want to do something similar as a watch, but I can't find the chip already programmed for a reasonable price, and I don't want to invest in the equipment to do it myself for a single project.

godofal (author)2009-09-13

I finished my clock, but it runs way to slow! i made the time 23:29 last night and then went to sleep. at about 09:45 the clock said it was just after midnight! what is wrong?

godofal (author)godofal2009-09-20

i got it working, i did the math, rewrote line 65 into
and now it works pretty exact, still got to find out how exact over a week, going to try that now :)

godofal (author)2009-09-13

u need to change ur handdrawn diagram,it says pin17 controls H16, but in the code it says pin16 controls H16, and its kinda odd to skip a led. also, how can i make the time improvement of the button go faster and the minus 1 minute go earlyer? its now bout 5 seconds for a minute (after that 15 second speed increase) and half a second for decrease of minute. i would like something that goes 1 minute increase every second after the speed increase, and 1 minute increase every 2 seconds before, and right after i push i should be able to release for a decrease of 1 minute. how do i alter the code? il upload some pictures in a slideshow when i get it all done, now its kind of messy with the wiring... also, i used a protoboard and a socket for the IC, seemed handyer to me.

godofal (author)2009-09-12

you need to change ur handdrawn diagram,it says pin17 controls H16, but in the code it says pin16 controls H16, and its kinda odd to skip a led. also, how can I make the time improvement of the button go faster and the minus 1 minute go earlier? its now bout 5 seconds for a minute (after that 15 second speed increase) and half a second for decrease of minute. i would like something that goes 1 minute increase every second after the speed increase, and 1 minute increase every 2 seconds before, and right after i push i should be able to release for a decrease of 1 minute. how do i alter the code? il upload some pictures in a slideshow when i get it all done, now its kind of messy with the wiring... also, i used a protoboard and a socket for the IC, seemed handyer to me.

arhodes18 (author)2009-09-01

is there anyway you could help me figure out how to do this out of an old alarm clock? it uses an mm5387AA "controller" i guess its called... this clock is pretty old, at least 15 years or so, so i figured it may be easier to use this controller...

cantthinkof bettername (author)2009-02-05

How do you tell minutes? I think I did the binary right.
Never mind, I saw more than 4 marbles on a different step. That is a very good idea, but I don't have time to make one now. Do people sell these? I can picture a computer teacher buying one, or me if they were not very expensive. I am going to favorite this.

you can buy them on i think, but i know you can buy wrist watch versions

Flip all of the binary numbers around. You read it from right to left.

Thanks! I guess my Dad taught me wrong. Oh well, I got the basic concept.

MrCruz (author)2009-06-27

A micro-controller? Bah. That's cheating my friend. There's no challenge in that ;) Although I have to admit that this is a good implementation...

cantthinkof bettername (author)2009-03-06

are there any screensavers that do this?

sotsirh194 (author)2009-02-08

Can you explain the time algorithm in more detail. I really don't understand it.

sotsirh194 (author)2009-02-05

How do you get the leds to change. Do you use a +1 to the port since it runs on binary already. like PORTD = minute
minute equals 0111010 which shows which pins are high

arhodes18 (author)2008-12-08

this is really cool, is there any way to get a pre-programmed chip, and what is the power supply on this?

awkrin (author)2008-05-23

and how are u going to connect the ic to the computer?

Xellers (author)awkrin2008-09-30

You program it once through a usb programmer, and then you soldier everything together. Once you've decided to do this, you wo'nt be getting your chip back... Unless of course you soldier everything to a socket and then put the chip into that. It would also lower the chances of damage to the chip during soldiering. And easier way to do this without a Microcontroller is to use a 555 timer set to pulse once a second hooked up to some 7490 chips that divide the pulses and do the same thing as this. Then, if you only use one chip with 4 outputs, you can hook it up to a 4 line to 10 line demultiplexer such as the 7442 IC to drive a single digit nixie clock. That's what I did... And no MCU...

ckiick (author)2008-05-27

Accuracy? How accurate is the clock? Arduino code to keep real time usually drifts by several seconds an hour. Does yours do better? PS: I like the use of Bresenham for the ticker.

fpetir (author)2008-05-23

My clock not work, go only with pressed button. What is wrong? Please help!

mwalton (author)2008-05-14

I'm so close to being done, but each time I try to upload the source code to the chip I get errors talking about undefined variables and multiple definitions. Can someone please help, I was able to figure out how to use a atmega168 AVR and I bought a Arduino Diecimila so I could hook it up to my computer. But no luck and I even tried the ghetto programming enviro but I can't get that to work either can someone please help me.....

jeff-o (author)2008-05-11

Hi Mats, I've got the 20MHz version of the ATtiny2313. I assume I have to change all of the "10000000" references to 20000000, right? Do I have to touch the 1638.4 uS timer0 interrupt or will that take care of itself if the program know what speed it's running at?

beatle (author)2008-04-19

WOW! This instructable is just great! Thank you for doing it. I was scaning the Internet for some good DIY binary clock, and your's was the best! One question though, i can not find a 20pF cap any where, not even doble the amount of 10pF ones to conect in paralel, can i use a bit diffenet value, or it is critical? Thanks. And once more- a great instructable!

beatle (author)beatle2008-04-21

I managed to found 22pF caps, hope that it will be close enoght. Built the thing,it started flashing,but i had just set the time, i discowered, taht the clock is not ticking! Whay it is so, can anyone tell me? What could cause it? i would really apriciate any help, i have run aout of ideas, tried reprograming the uC, changing uC, checkin for shorts..

pullinsb (author)2008-02-21

I absolutely enjoyed this instructable! I am trying to replicate this right now. I am curious as to how hard would it be to add a seconds counter to this schematic? I've seen a binary clock made out of an old harddrive, and it had seconds on it. I think the seconds are a really fun part while watching a binary clock. Great job

matseng (author)pullinsb2008-02-22

Thank you. Seconds would probably really enhance the looks of the clock. Unfortunately there are not enough ports on the Tiny2313 to do that using direct drive. But by adding three transistors and multiplex the hours, minutes and seconds it'd be a piece of cake. By adding three transistors, six leds and removing five resistors and adding a few lines of code. If you're interested I can draw you a new schematic and update the software...

mwalton (author)matseng2008-04-19

I would be really interested in this I have an AT Mega just waiting for something to be done with it. I'm going to make this clock but having seconds would be amazing

pullinsb (author)matseng2008-02-22

I tell you what, if you send me the schematic and updated code, I'll build it and send you a pretty picture. Seconds would just be awesome.

rachedi (author)2008-03-06

Thanks for the project, quite informative. However, please forgive the ignorance, how do pass the C code you provided to the chip?

zootboy (author)rachedi2008-04-18

You need a programmer. This instructable has a nice description of a DAPA cable, which uses a parallel port. You can also make a DASA or ponyser cable, all of which can be found with a little googling or here. These are all in the class of bitbang programmers. If you want more professional porgrammers, you can consider a USBtinyISP, made by Adafruit Industries

zootboy (author)zootboy2008-04-18

OOPS! I forgot the most important thing! You need WinAVR to compile and burn the code. It includes programmer's notepad and avrdude to do all this. LINK.

(This is for the windows platform. I am not sure if they have done a mac or linux port yet.)

Charles IV (author)2008-03-26

Wow I've always wanted a binary clock but I couldn't find them anywhere except for the internet. So now I can just make one Instead.

sotsirh194 (author)2008-03-20

is there any way i could do this with a basic stamp or pic microcontroller

sergmag (author)2008-03-07


bluebasil (author)2008-02-17

I like this a LOT. Shame I don't have the resources to program the chip.

matseng (author)2008-02-15

I think that this might need a wee bit more experience than two weeks to pull off successfully unless a kit with all parts and a pre-programmed chip is made available. I suggest that you fiddle around with some other projects for a few months to gain some more experience soldering and stuff like that. Then please come back and I'll try to fill in the blanks for you.

callmeshane (author)2008-02-14

CLOX - instruments of the devil.... It's funny tho that when you get yunga people, raised on digial clox, how they have to LEARN how to read analogue clox. Binary? Good stuff... perpetual mind expansion is important.

nacroman (author)2008-02-14

Nice instructable ive been looking for a good write up like this. My only question is if i had a different valued crystal like a 1MHz or so how would i modify the programming code to make the clock run properly off that so its not all off-kilter as I have plenty 1MHz crystals handy.

matseng (author)nacroman2008-02-14
Oh... A 1 MHz crystal. I haven't seen those in years...

I think that the easiest way to tweak the code for that would be like this:

On the top of the code change the F_CPU define to:
#define F_CPU 1000000UL

Then change the entire ISR code to this:
//// This Interupt Serivce Routine gets called every 16.384 mS by timer 0//ISR (SIG_OVERFLOW0) { static int32_t	ticks = 0;static int8_t	ms100ticks = 0;	// Standard Bresenhams time-keeping algorithm	ticks-=16384;	if (ticks<0) {		ticks+=10000000;				// Increment time by 10 seconds		second+=10;		if (second>=60) {			second=0;			minute++;			if (minute>=60) {				minute=0;				hour++;				if (hour>=24) {					hour=0;				}			}		}	}	// If this ISR been executed 6 times (approx 100mS)	// then increment the 100mS-counter	ms100ticks++;	if (ms100ticks>6) {		ms100ticks=0;		ms100++;	}}

I think that should fix it.

Since your crystals are 10 times slower than the one I used then we just update the seconds by ten instead of one. The seconds doesn't get displayed on the clock anyway it doesn't matter that we step it.

The counter that keeps track of the 100mS timings (used by determining the length of the button presses) was previously incremented 61 times at fast interrupt rate of 1.6384 mS (61*1.6384 is approx 100 mS). Now the interrupt rate is slower, (16.386 mS) so we only need to count 6 of them to get out 100mS. There's no need for any absolute precision here since it's only used for the button.
clamoring (author)2008-02-12

Great instructable and fantastic pics! I especially like your "squished bug" soldering job!

matseng (author)clamoring2008-02-13

Thank you. It's rather easy to get decent pictures with a Nikon D300 and some nice glass. But I really need to get my act together and finalize my homemade light tent to get a better lightning on the pictures.

5Volt (author)2008-02-11

To push further minimalism you could turn on quickly one LED at a time (multiplex) and thus use one single resistor shared by all LEDs on their common cathodes. The source code is well commented also. +1 Ciao

matseng (author)5Volt2008-02-11

Thanks. Yes, I was thinking about that but the leds I got at hand was rather old and not that bright and the multiplexing would reduce the brightness even further. But with good leds the muxed single resistor version would probably work just fine. To really minimize the hardware I could have used a 8 pin microcontroller like PIC 12F629/675 and chalieplexed the 11 leds. 2 pins power, 4 for the leds, 1 for the button and 1 spare. The problem with that would be that I had to rely on the internal oscillator and that may case the clock to drift up to 10 minutes a day....

GaRy GNUb (author)2008-02-10

awesome piece. please tell us how many amps this thing needs (i have loads of old wall warts that i'd like to use, but they vary in current rating). thanks!!

matseng (author)GaRy GNUb2008-02-10

With all leds on I measured a power consumption of 102 mA. The wart can be of any amperage as longs as it's larger than 100 mA

Just make sure that your wart is DC output and is of a maximum of 6 volts.

If unsure use the 5 volt regulator I wrote about further down in the comments to fix the power from your wart.

homba (author)2008-02-09

Does anyone have a good, cheap online source for the atmel microcontrollers? I've been wanting to get into these - I'm getting a little sick of my basic stamp kit.

unspecified (author)homba2008-02-09

I like sparkfun - they have a lot of atmel chips and accys at decent prices. I also can't recommend the ghetto dev kit highly enough - worked great for me!

homba (author)unspecified2008-02-09

I read through the ghetto kit a couple of days ago and it looks so cheap and easy to build. I've also been looking at this as well as it looks so clean and professional ... decisions, decisions ...

About This Instructable




Bio: Swedish expat living now living in Malaysia after spending some years working in Dubai.
More by matseng:The Motorized Led Bolas Of DoomBinary Marble ClockSpooky Led Lamp
Add instructable to: