Arduino Binary Clock Example

I received an Arduino Mega ADK for Christmas. My plan for my first project is to create a very fancy model rocket launcher, but you have to start somewhere, so here’s a basic example that implements a binary clock.

First, the code:

To build the circuit, you will need one led and resistor for each digit in your display, plus a method of connecting them. Because this is a throwaway example to me, I used a breadboard and some jumper wires. Connect the resistor to a digital pin on the arduino, and the other side of the resistor to an led. Connect the cathodes of all the leds to gnd on the arduino. See the images for an example of one way to do this with jumpers and a breadboard.

To change this to a real clock that displays the time in binary coded decimal, you’d want 19 leds (20 for military 24h time), and so would need to use an arduino with at least 19 digital pins, or some sort of encoding such as a shift register. You’d probably want to make 3 sets of arrays, for hours, minutes, and seconds, and every time you counted 60 seconds you’d wrap the seconds and increment the minutes, doing the same for hours and minutes every 60 minutes. To improve the accuracy of your clock, you’d want to time how long your loop takes, and subtract that from the delay between cycles, or your clock will run slow. This project is left as an exercise for the reader.

If you have questions / comments about this, feel free to email me at jcaswell at secondstringsamurai dot com.

4-digit binary clock on breadboard

4-digit binary clock on breadboard

Leave a Reply