Little Bin -- The Binary Clock

All my possessions for a moment of time. Queen Elizabeth I

Feb 10, 2019

This project was started in July 2016. I finally "finished" it today.

Little Bin
July 31, 2016 to Feb 10, 2019

This is my clock, Little Bin. It has been in the works for 30+ years. I finally started building it about a week ago. Nothing really fancy about it, but I think it is interesting and maybe you will too.

The first interesting thing about this clock is the display: it's binary. The hours is one group of binary digits and the minutes is another group. Over the years I have seen quite a few clocks either sold as kits or presented as projects in magazines and on the web, that claimed to be binary. However, almost every single one was actually binary coded decimal (BCD) rather than true binary. BCD uses groups of four binary digits to represent a single decimal digit. So, the display was actually a decimal number, but used binary coding to represent each decimal digit. To me, that is cheating. I had to make mine use true binary coding. The six green LEDs on the right are for the minutes (0 to 59 or 000000b to 111100b) and the five green LEDs on the left are for the hours (0 to 23 or 00000b to 10111b). The single red LED in the middle acts much like the colon used on decimal digit clock displays.

The second interesting fact about this clock is that it maintains excellent accuracy by being synchronized to the power line frequency. In many parts of the world, including here in the US where I live, the power line frequency is very well regulated. The Wikipedia article on Utility Frequency has some very good and interesting information about that. In the early days of electric power generation, the frequency wasn't well regulated. However, Laurens Hammond invented the electric clock that ran a motor synchronized to power frequency. For it to be accurate the power frequency had to be accurate. As an incentive for generator operators to closely monitor and control their frequency, he gave away several hundred of his clocks to the operators. Their clocks would be as accurate as their generator frequency. Today, the large grids and government regulations demand that the frequency be accurate. More on this later.

In the modern world, with so many generating facilities tied together in a "grid," the frequency must be closely monitored. Regulations in much of the world demand that the frequency be kept within certain bounds. In general, the frequency may vary somewhat in the short term, but long term (days, weeks, etc.) it is regulated to be very accurate. Typically, especially in the US, periodic corrections are made during the day so that from midnight to midnight there are 5,184,000 cycles (24 hours X 60 minutes X 60 seconds X 60 cycles). So, although the clock might not be exactly accurate at any time during the day, from day to day it will be extremely accurate. As long as the power stays on. Of course, the frequency doesn't vary much during the day; it may be off by something like 2 Hz (58 to 62 cycles per second) at any time which would make it be off by 1 second after 30 seconds. Periods like that are normally kept quite short and it is unlikely you would ever notice it. And it will correct itself soon enough.


The hardware is mostly a fairly standard Arduino build. You can reference the schematic below for the discussion of the hardware.

There is a nano, twelve LEDs, and three pushbuttons. The LEDs are multiplexed in two banks of six. The first six normally show the minutes (0 to 59). The second bank consists of five LEDs for the hours and one multi-purpose LED used much like the colon on typical digital clocks. It flashes each second. It is also used to indicate various modes. The colon LED is red and the rest are green. Six resistors limit current to the LEDs and two transistors (pn3904) are used as "digit" drivers to handle the current of six LEDs.

The three pushbuttons, named "MODE," "UP," and "DOWN" are used to change modes and to set the time. The button to the left and centered vertically between the others is the MODE button. Of the two on the right, the upper one is UP and the lower one is DOWN. The pullup resistors inside the AVR chip are used to hold the pin high until the button is pressed. I used panel mount momentary switches from Tayda electronics that cost about 22 cents each.

Power is provided by an 8.5V AC wall wart. I picked up a bunch of those at a hamfest some years ago for cheap, along with some various other power supplies. Apparently the seller worked for a telecom company and all these wall warts and power supplies were used with various phone equipment. Anyway, the 8.5V AC works well with 5V regulators and AC was important for this application. The power is brought in to a barrel jack (conn1) and fed into the rectifier circuit. For power, I used a standard, small bridge rectifier good for about 1 amp. On the schematic it is shown as D1 to D4, but it is actually a single package. That converts the AC to pulsating DC which is then filtered by three 1000uF electrolytic caps (C1 to C3). The venerable and cheap LM7805 then regulates that to 5V for the rest of the circuit.

The more intersting part of the rectifier circuit consists of D5, R1, R2, R3, and Q1. Diode D5 passes only the positive half of the AC sine wave, giving 60 (or 50) pulses per second in the shape of half a sine wave. Each pulse is around 8.3 mS with a gap of 8.3 mS between them. This pulse is used to interrupt the processor on the Arduino for timekeeping. But, we can't use the pulses as they are. First, the peak voltage of the pulse will be around 12V. Our 5V logic circuits wouldn't like that. Second, the "rise time" of the pulse is very slow: around 4 mS. It is a bad idea to feed such a slow-rising pulse directly to an interrupt (or most other pins). Logic circuits don't really like slow-rising pulses, and noise on the signal can cause it to appear as many transitions between low and high. That is especially bad on an interrupt pin, and will cause severe problems for timekeeping.

So, to make the pulses more suitable we use a bit of signal conditioning. It is fed to transistor Q1, a 2n3904. The output(collector) of Q1 is powered by 5V and fed through R3, a 10K resistor. That limits the output to 0 to 5V, which the Arduino will like much better. The input goes to a voltage divider consisting of R1 and R2, which limit the current to the base. R2 also helps make the pulse a little more "square." When the input pulse goes high, the output goes low, so the pulses are inverted going to the AVR. That's fine. We don't care which half of the AC wave we use, so seeing it inverted is nothing more than seeing the opposite half. Take a look at the collector circuit. The 10K resistor means that a maximum of 5V/10K=0.5mA can flow through it. That would put the collector, and the interrupt input, at 0V. A bipolar (NPN or PNP) transistor is a current amplifying device. The 2N3904 amplifies the base current by about 100. A base current of 0.5mA/100=5uA will bring the output fully low to 0V. The voltage divider of R1 and R2 makes the input voltage appear as half the voltage applied through R1 and R2 in parallel (Thevenin's theorem.) So, at the peak of the pulse (12V) it will appear as about 6V through a 5K resistor. When the input pulse reaches about 0.05 V it will cause an input (base) current of about 5 uA, which fully turns off the output. The sine wave will reach 0.05 V very quickly and the pulses going to the AVR will be nice and square, and limited to 0 to 5V, just like we want.

Main Schematic of Little Bin
Schematic of display LEDs

The schematic also shows a speaker. This is actually a small piezo buzzer, but I didn't feel like creating a new schematic symbol. It is fed by an output pin to create a "tick" sound at each second.

Years ago Radio Shack had some fairly nice and sturdy steel project cases on clearance. I bought all I could find. They were only about $2 each. I still have about eight of them unused. They are a little bit more than eight by six by three inches. I used one of those and spray painted it flat black. I drilled 5mm holes for all the LEDs and holes for the switches. I also put in a hole for the power jack, but that may need to change. Since this is a hacker toy, I put an access hole to fit a USB cable in to plug into the Arduino USB port. I can hack on it without having to open the case.


The code is not complete yet. Right now, the biggest flaw is that I can't set the time. I am working on it as time permits and hope to have it "complete" very soon. My fixation with time may be due to the fact I have none! In any case, I am posting what I have. It's pretty bad right now. Cleaning it up is part of the ongoing development.

Basically, it has a main program that initializes everything then waits for a MODE key press. If the mode key is pressed, it switches modes based on a simple state machine. The interrupt ISR is also part of the main program. There is a Buttons module that is responsible for reading the buttons, and a Time module that keeps time (and sets it when done), plus a Display module that is responsible for displaying whatever needs to be shown for the current mode. At each interrupt (60 or 50 times per second) the time update routine is called.

As well as the time setting code, there are a few more features I plan to add. An alarm is one. But that will have to wait. We shall see just what the future holds.

Update Feb 10, 2019

The above was written when I first started working on this in 2016. Today I decided to finish it. So I sat down and wrote some code.

I can now set the time and date. The year goes from 1 to 99, so it isn't year 2000 compliant ( or year 2100, or 2200.) It keeps track of leap years. You can press the "mode" button to see seconds or date (month and day.)

I'm pretty happy with it so far, but still some changes to make. I still want to add an alarm. A few things could make setting time and date easier. It is kind of hard to tell what you are setting unless you keep track of where you are. If you hold the "mode" button in for more than a second the clock goes to setting mode when you release it. It sets in order: year, month, day, hour, minute, second. The "up" and "down" buttons change each setting, wrapping around last to first or vice versa. A short press on the "mode" button switches to the next setting, or back to time display after seconds. A long press on the "mode" button goes immediately back to time display.

I will post some updated pictures and video soon, as well as the code. That's all for now.

Small Time Electronics

Your Source for Custom Electronics, Projects, and Information

© 2019 William R Cooke