Introduction: Arduino + LEDs = Binary Clock
This project was taken directly from the book "30 Arduino Projects for the Evil Genius" by Simon Monk. It is described in detail starting on page 159.
Basically the steps I did are:
1. After deciding on the size of 12 by 15 inches, I built a box from scrap wood and then stained it a dark color.
2. I then bought a piece of plastic and cut it to a size which will just fit into the groove I routed out from the top of the box.
3. Then I made a circle basically centered around the middle of the box but slightly skewed to the top of the box. I would make a square box next time as the measurements would be easier.
4. Then I carefully drilled holes for the 16 LEDS that will be used to display the time.
5. Each of the positive sides of the LEDs has to be joined to the Lilypad pins . I used pins 1- 4 for the hours, 5-10 for the minutes and 11-13 plus A0 -A3 for the seconds . The negative sides are all joined to a common ground. I deviated from the book in the manner of how I got a common ground. Each LED has a 100 ohm resistor attached to it.
I have an old bike that I am determined to reuse in as many ways as possible. So I took one of the front gears and attached it to the plastic and then ran a copper wire around the back of the gear. This allowed for a common ground wire and made for a somewhat cleaner look(fewer wires to see).
6. I then copied the following code as it is in the article and loaded to the Lilypad. I did make a couple of changes to the original so the code I actually used is below:
#include <Time.h>
int hourLEDs [] = { 1, 2,3,4}; // least significant bit first
int minuteLEDs [] = { 10,9,8,7,6,5};
int secondLEDs [] = { 16,15,14,13,12,11 };
int loopLEDs[] = {16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1};
int switchPin = 17;
void setup()
{
for (int i = 0; i< 4; i++)
{
pinMode(hourLEDs[i], OUTPUT);
}
for (int i = 0; i< 6; i++)
{
pinMode(minuteLEDs[i], OUTPUT);
}
for (int i = 0; i<6; i++)
{
pinMode(secondLEDs[i], OUTPUT);
}
setTime(0);
}
void loop()
{
if (digitalRead(switchPin))
{
adjustTime(1);
}
else if (minute() == 0 && second() == 0)
{spin(hour());
}
updateDisplay();
delay(1);
}
void updateDisplay()
{
time_t t = now();
setOutput(hourLEDs, 4, hourFormat12(t));
setOutput(minuteLEDs,6, minute(t));
setOutput(secondLEDs,6, second(t));
}
void setOutput(int *ledArray, int numLEDs, int value)
{
for (int i= 0; i < numLEDs; i++)
{
digitalWrite(ledArray[i],
bitRead(value, i));
}
}
void spin(int count)
{
for (int i = 0; i < count; i++)
{
for (int j = 0; j<16; j++)
{
digitalWrite(loopLEDs[j], HIGH);
delay(50);
digitalWrite(loopLEDs[j],LOW);
}
}
}
7. It was necessary for me to get the Time library and install it. The process is described in the article.
8. Once installed and plugged in the clock works in this manner.
-To adjust the time you place a magnet near the reed switch and it will speed thru the time until you get the correct time ..
- As time passes, the seconds LEDs change and of course the minutes and hours.
- To read the time , one must add the LEDs that are on eg if Hours LEDs 8 and 2 are lite , Minutes 32 and 8 are on, and seconds 16 and 1 are on This would be 10 (8 +2), 40 (32 +8) , 17(16+1) or 10:40:17.
- Also at the change of the hour the LEDs will chase in a complete circle a number of times. If it is 4:00 t, then they chase 4 times, 11:00 then they chase 11 times.
Here is a video of it working:

Participated in the
Microcontroller Contest

Participated in the
LED Contest
14 Comments
8 years ago on Introduction
Could a real time clock be added for more accurate time keeping ?
10 years ago on Introduction
Hi, I really like the look of this so thought is would be a good first project for me to try out. I'm really stuck and wonder if anyone can help advise. I copied the code as provided here but am having problems. Initially the LEDs flashed too quickly but I fixed this by changing the delay from 1 to 1000 - the other problem I can't get over is getting the LEDs to flash "Seconds" correctly. Effectively after the first initialisation, when it counts 1, 2, 5, the Units LED stays on constantly. The most significant LED never comes on (32) and the rest count as though the "2's" LED was the seconds counter, i.e. at 1 second intervals it counts up 1,3,5,7,9 through to 31 on the first run through then 29 on the second run. I've got an Ardiuno Lilypad with ATmega328, I'm using the Arduino loader version 1.0.3. The Time.h library I downloaded from the Arduino web site and it appears to be in the right place - I can "Import" the Time library successfully. I've also tried this on two different computers - WinXP and Windows 7 in case I made a mess of the Time library install at some point. Before I involve my Son in this I'd like to get the basics working - hence the question. Hope someone can point me in the right direction. Thanks in advance.
Reply 10 years ago on Introduction
Hello,
I hope you have made some progress. It is not obvious to me what might be wrong but I have found odd electrical problems will occur when not every component is grounded properly. Also changing the delay from 1 to 1000 is a huge change so I doubt that needs to be done.
It also is critical that the pins be wired exactly as the code would have them eg seconds must be pins 11,12,13,14,15,16.
Sorry to be kind of general but I am not that much of an expert either with a lot of trial and error being my method.
12 years ago on Introduction
Nice implementation of my project! Well done.
If you liked this project from my book '30 Arduino Projects for the Evil Genius', then have a look at '15 Dangerously Mad Projects for the Evil Genius'.
Simon Monk :)
Reply 12 years ago on Introduction
Thanks. There are several other in your book that I will do at some time.
Perhaps you could comment on something though: I find that the clock runs a bit slow. It requires resetting almost daily for 10 minutes or so. No big deal but I wonder if there is a place in the code I could make some small change to get slightly better results.?
Reply 12 years ago on Introduction
Yes, sorry I did know about it running slow - I was hoping it was just my board.
I spent some time trying to figure out why, but there is nothing obvious. I suspect it may be in the time library, I guess thats why people use a real-time chip instead of the software solution.
Probably the easiest way to add an adjustment is to set the time forward the necessary number of seconds every time it gets to the hour. It looks like 'adjustTime' can take a negative number of seconds, so just call this in loop, right after you do the spinning thing.
void loop()
{
if (digitalRead(switchPin))
{
adjustTime(1);
}
else if (minute() == 0 && second() == 0)
{
spin(hour());
adjustTime(-10);
}
updateDisplay();
delay(1);
}
Give it a go, and please let me know the results.
Si.
12 years ago on Introduction
The links for the book this project came from is:
http://www.arduinoevilgenius.com
This is the one for my new book.
http://www.dangerouslymad.com
Reply 12 years ago on Introduction
I will check out the links. Thanks
12 years ago on Introduction
Very cool idea!
Reply 12 years ago on Introduction
Thanks
12 years ago on Introduction
Five Stars for this wild, weird and very COOL Clock!!!!
Reply 12 years ago on Introduction
Thanks
12 years ago on Introduction
Great clock! I like it very much.
Reply 12 years ago on Introduction
Thanks.