A Simple USB-powered Binary Clock





Introduction: A Simple USB-powered Binary Clock

Yes, I know, there are already lots and lots of instructables about binary clocks.  I wanted to build one for a long time now so with the USB contest in mind, I gave it a go. So if you like this Instructable then please vote for it in the contest.

As the title suggests, the clock is powered via a usb cable. When you disconnect the clock or turn off the computer, it will keep going on its battery but it won´t show the time until you reconnect it or switch you PC on again.

For this project, I made my own PCB´s. I have only made 3 PCB´s yet and all in the last 14 days so I am really proud oft them. Any suggestions about those are very welcome!

A small video (the flickering of the LEDS in due to the camera).

Step 1: What Do You Need:

  • 20 x  LEDS: Any color you fancy
  • 2 x pushbuttons
  • 6 x 100Ohm resistors
  • 2 x 1.5K resistors
  • 2 x 4.7K resistors
  • an Atmega 8
  • a DS1307 real time clock IC
  • a crystal 32.768K
  • a USB connector
  • A 3V battery + holder ( I used a CR2032)
  • a 13pin male header (L-shaped)
  • Soldering Iron and solder
Please be careful when soldering. Children should always work under adult supervision!

Step 2: Schematics and PCB's

The clock consists of 2 boards: The main board and the display.

Main Board

The 2 most important things located on the main board are the microcontroller and the clock. Those 2 are connected to each other via an I2C link (don't forget the 4.7K pull-up resistors on the 2 wires).
The clock also needs a crystal (32.768K) on pins 1 and 2 and a battery on pins 3(+) and 4(-).

The 2 other resistors are 1.5K pull-up resistors for the buttons. They are connected to int0 and int1 on the atmega8 (pins 5 and 6).

The USB connector is only there to provide power, so we only need the VCC (pin 1) and GND (pin 4).


The display contains 20 leds, 6 resistors (100Ohm) and 2 buttons. I arranged the leds in 6 colums instead of 3 so that each digit of the decimal number is represented by its binary equivalent instead of the entiry number in a single binary value. I find it easier to read quickly and it gave me an extra challenge while programming.

The 2 buttons are used to set the time. One button for the hours and one for the minutes. Their pull-up resistors are located on the main board.

I added the schematics of the 2 PCB's here, as well as their layout. I also added 2 pdf-files with the layout for both PCB's, so that you can print them out on a transparent to make your own PCB's.

Step 3: Programming

I won't go to deeply into explaining the programming of the device itself, as everybody has his or her own way of programming and may use a prefered language. What I will do is explain the idea behind it and how it works in my case.

Start up:

When power is switched on the microcontroller reads the clock and makes sure that the clock is running by setting bit 7 of register 0 (oscilloscope enable bit) to 0. As the datasheet suggests, this is needed because the initial power-on state of the registers is not defined.

Main loop:

Once the program enters the main loop, it will read the clock again and convert the 3 decimal numbers (hours, minits, seconds) into 6 colums.

I used following calculation(see photo for the colums):

value / 10 (disgard the decimals) gives you colum 2
value - (colum2*10) gives you colum 1

value / 10 (disgard the decimals) gives you colum 4
value - (colum2*10) gives you colum 3

value / 10 (disgard the decimals) gives you colum 6
value - (colum2*10) gives you colum 5

When done, the colum values are passed on to port C according to the colum that is enables on port B. This multiplexing enables us to use less pins and keeps the current lower than 100mA.

After this the loop restarts

When a button is pressed, the corresponding interrupt is called and the hours or minits are increased by 1 accordingly. The clock is set immediately after increasing a value via a set subroutine.

I added a hexfile with the program.



    • Trash to Treasure

      Trash to Treasure
    • Paper Contest 2018

      Paper Contest 2018
    • Science of Cooking

      Science of Cooking

    We have a be nice policy.
    Please be positive and constructive.




    sir,this is . tmp file. i need . hxe file. please help me

    my gmail id = sohag.narsingdi@gmail.com. plese send me hex. format file

    dear sir, i make this clock, but the clock isn't works,even if the led don't glow. can you help me. first time when i power on the board the rtc get hot.Then i pull out the cmos battery-solved. i make a modification the circuit- connect the avcc and aref then i insert the battery and power up the problem solved with rtc,but the led don't glow.......

    Would you fix this ,sir

    sorry for poor English



    Congrats on your build, it looks nice! The clock needs USB and battery to work. Are all you ic's inserties in the correct direction? Overheating often means that polarities are switchen.

    Contact me if it isn't one of the above


    I checked the pcb several time whether the ic is in correct direction. The ic are perfectly placed.Also i checked the pcb track,its fine. I attach the photo of the board along with this. I made a connection modification--avcc and aref connect to the +5v to overcome the heating problem of the rtc(red wire).(mentioned above).

    Is the hex code is working???


    avcc is indeed better connected to +5V but it shouldn't solve an overheating rtc. If it does, it means that there in something else wrong in the powerlines of the circuit. The hex-file works perfectly, I reloaded it into my clock and it seems to work good. only thing I don't remeber is whether the internal osc of the atmega should be set to 1Mhz or 8Mhz.

    How can i change the internal osc to 1mhz or 8mhz?.....I connect the usb power to my clock the rtc get overheated now. When i remove the cmos battery it will solve the problem.While inserting the battery the rtc get overheated.

    did everything correctly,used blue leds,any idea why did my avr got hot,and didn't give any time


    Most of the times when an AVR gets hot, it's because 5v en GND are connected the wrong way round. Or because there is another short circuit somewhere.

    Solved.Thanks Stupid me,a jumper connected to vcc touched gnd,bad insulation