I was going to start watching a movie, when me and my friend pedro decided to give up on the movie and build a binary clock. After sometime thinking on how to program it, we made it. It works beautifully, so I decided to show here how I’ve done. It may not be the easiest way to make it work, but that’s what we’ve done.
Parts:
– Arduino
– 13x Leds (You choose the color)
– 13x 220Ohms Resistors
– 3x 2.2KOhms Resistos
– 2x Push-Buttons
– 1x Normal Button
– Bread Board
– Wire
Well, this is a quite simple circuit, but can be tricky for some people, so I will try to explain how it work and how to assemble.
How it works
I think with this images you can understand how it will work. The leds which are on, you just need to sum the numbers, and it will give current time.
Assembling
To assemble the circuit, you will need to connect first the resistors and leds. To do it, just hook up leds + resistor from the pin 1 to 13. Remember that the bigger leg of the led is positive, and need to be connected to arduino output pin, and the other leg should be on the ground.
So that the code will work for the circuit, you should use the leds like this, LED 1 to PIN 1, LED 2 to PIN 2, and so on…
For connecting the buttons, I’ve used one digital input and two analog inputs. To set change the hour/minute, you will need to use two push-buttons. And they need to be connected to the analog input pin 0 and 5. And to turn leds ON/OFF I’ve used a normal button that is connected to digital input pin 0. To make it work, you need use one leg of the buttons on a 2.2K Ohm resistor connected to the 5V output together with the analog/digital input, and the other leg going to the ground, something like this:
If you don’t understand what I am trying to explain, you can go to the arduino website here.
Images + Video
Code
The clock code is based on the open-source-arduino-clock by Rob Faludi. I’ve made many changes, but the time counting the basically the same. So if you want to make another kind of clock, I suggest you to take a look on that website.
If the code below isn’t working, you can download it as .txt HERE.
Hope you liked, any question just ask! And if you make your own, send me pics =)
Oi Daniel,
That’s a fun little project.
I think I’ll try it out.
Very nice, I think I might give this a shot!
Muito bom o esquema cara, parabéns, seu site é excelente, não conhecia!
@Arquitetura Digital Obrigado =)
hi! im interested with the project.. but i dont know what’s ARDUINO is.. can u help me with it? thank u..
@Angel “Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It’s intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments. ”
take a look at http://www.arduino.cc 🙂
Good job!! Do you know what the power consumption is like? I’ve been thinking of doing something like this for a while to keep as a permanent clock run on batteries and it would be interesting to know how long they’d last.
Thanks!
@Andy, I’m not sure, someday when I’ve some spare time I’ll assemble it with battery and run some tests.
In case you do it, tell us how long it lasted.
Greetings
I was wondering what changes should be made to add 13 LEDs for the seconds (Apart from the 13 220 Ohm resistors).
See Ya
Shadow493
Why use all 13 LEDs for secons? didnt get your point 🙂
Sorry, my misake.
I mean, add 7 more LEDs, so it end like this
º º º
º ºº ºº
ºº ºº ºº
ºº ºº ºº
Hr Mn Sc
Hope I made myself clear this time.
See Ya
Shadow493
My previous ASCII art didn’t come out as I planned.
Look, I want a clock like the one here http://www.thinkgeek.com/homeoffice/lights/59e0/
BTW, sorry for the double post.
See Ya
Shadow493
Well, as arduino have only 14 Digital Outputs, you would need to multiplex the leds, http://en.wikipedia.org/wiki/Charlieplexing
http://blog.makezine.com/archive/2008/04/all_about_charlieplexing.html
Daniel
Thanks for posting the code and instructions.
I was wondering if you think it would be possible to add seven segment displays so that the time is displayed in normal numbers mode?
Do you think your code could be modified to do this?
Thanks
Actually you can use the Analog inputs as Digital outs. They are all GPIO. So I count 20 as long as they aren’t used for anything but the clock.
Just thinking about this a bit. So if you used three analog pins to set the clock. One for Hours, one for Minutes, and one to START the clock, which would also set the pins to become digital outs. Then use the AVR reset button if you need to change the time in the future. Sounds like it might work for a full hours/minutes/seconds BCD clock.
Hi Daniel,
Hope your still replying to these mails 🙂
Great concept here, I’ve been following it and am nearly done- except I need some help.
I can’t quite figure out where two of the resistors on the bottom half end, and from the images I can’t tellvery well since the wires are covering it. Is there any way I can get a better photo of where the last two resistors on binary row 2 end please or is there any way you can help mek understand?
Thanksfor any help.
hiya i’m trying to make ur binary clock but i am kinda stuck. i can’t cleary see what wire goes where. is it possible to take a few more photos or video of where the wires goes clearly or can u just tell me in text where each indiviual goes.
WOULD YOU DO IT WITH A REAL TIME CLOCK, LIKE DS1302 OR SIMILAR ?
WOULD YOU DO IT WITH THE LILYPAD ARDUINO ALSO ?
WOULD BE GREAT.
THANKS
Raul, yes, you can use a RTC with it!! If the LILYPAD have the same outputs/inputs as a atmel168, yes you can!
This is a great project! I used your tutorial to build one for my electronics fabrication class. Mine can be viewed at:
http://arduinofun.com/blog/2009/08/15/functional-artsy-arduino-binary-clock/
Very cool project!!!
I have built it and seem to have a problem. The hour and minutes are stuck in a counting routine. I am able to change the hour and minutes by the buttons but then it continues to count. I was wondering if you had any suggestions?
Thanks
I think I know what the problem is, it is in the code. But I am new to the arduino. The last statements are causing the clock to count, so when I delete them then it functions normally. Not sure how to get it working properly.
Hello Jay,
if you have copied the code from the green window, send the code through the compiler, so you will find a line with an space problem. Sorry can not recall the correct position, or took the code above (i hope it will work, never tried it).
If you correct it and adjusting the three buttons, the clock will work fine.
I have much fun with this projekt, looking now to attach the clock in a special case and have the ability to design it.
Special thanks to Daniel (the italian brain) for my first arduino project.
@Woodworm, yes, what you are saying may work! Thanks, I just didn’t get the italian part =P
Sorry Daniel Andrade,
for the italian, brazilian is correct eh ?!
I read afterward!
I trying now to combine the clock with a pir.
With a 6 volt pack of batterie it is working without any problem.
How long? A matter of the led and the usage to switch them on and off and of course the amount of ampere of the batterie.
Greetings from munich!
@Woodworm great to know that it’s working. Are using 6V with the Voltage Regulator? Is it working properly? Vielen Dank =)
Bom dia!
@Daniel Andrade No, I used four AAA batteries serial that means 6 Volt.
The minimum voltage for the arduino is 6 volt, so it would be better to use more voltage, for examble a 9 volt block-batterie.
the microcontroller runs on 5V. Arduino board have a 5V voltage regulator. The best thing is to use a 9V battery! You may get some problems with the 6V AAA batt, specially when they start to unload charge and the voltage will go under 5V. 🙂
Built it, but seem to have a problem. Both the hour and minute sets of leds count up to 24 then return to 0 and they count up in 1 second increments. They actually counted a lot faster but I changed the 2 delay times at the end to 1000. I’m pretty new with an arduino and am just started to ba able to see what the code is doing, but this one has me stumped a bit. Any help would be greatly appreciated. By the way, I tried both sets of code on the page (also fixed the preoblem with the space) but get the same result. Thanks, Ali
Hi,
I had the same problem… there is probably something wrong with the buttons for setting the clock (or you have not added them to the schematics).
Try to comment out the code blocks that read the analogue input and see if this solves the problem.
Hope that helps.
Hello,
i modified my source code and have a problem that lies nearby Alis!
My clock is a little bit to slow (around three minutes daily).
I searched in my source code and optimized it, but did not find any special.
Ali, the 2 delay times cant be the problem, the delay is for using the buttons (triggering to set the minutes or hours).
Has somebody in this forum experience in calibrating the oscillator? I guess that this could be the problem.
Next time i will try to involve a fictive seriell connection into the source code, to force the oscillator to be in time.
I would be pleased to read better ways to solve the problem!
Hello,
i tried different energy adapter and a block batterie with 9 voltage.
First adapter 4.5 V and 700 mA the clock worked to slow. With the 9 V block batterie nearly the same result.
With an 12 V and 1 ampere adapter, the clock seems to work well, during an observation time from three hours, also im my pir-mode.
@Woodworm, you have a good point there! I haven’t tried it with different power sources then USB. Also the problem on using batteries is that maybe when they start to uncharge, the software will not run the right way. Another way to fix this problem is using a RealTimeClock to “calculate” the time, THEN show it on the LED`s.
Hello,
i found a very good workaround here: http://www.instructables.com/id/SCAKJ38G145SWHO/
Hey guys,
I have built this sweet clock, but it runs a little fast. Has anyone nailed down a good way to keep the time accurate. It’s about 1 minute fast per day on my arduino.
Thanks!
hey,
the code should be:::THX
int second=0, minute=0, hour=0; //start the time on 00:00:00
int munit,hunit,valm=0,valh=0,ledstats,i;
void setup() { //set outputs and inputs
pinMode(1, OUTPUT);pinMode(2, OUTPUT);pinMode(3, OUTPUT);pinMode(4, OUTPUT);pinMode(5, OUTPUT);
pinMode(6, OUTPUT);pinMode(7, OUTPUT);pinMode(8, OUTPUT);pinMode(9, OUTPUT);pinMode(10, OUTPUT);
pinMode(11, OUTPUT);pinMode(12, OUTPUT);pinMode(13, OUTPUT);
pinMode(0, INPUT);
}
void loop() {
static unsigned long lastTick = 0; // set up a local variable to hold the last time we moved forward one second
// (static variables are initialized once and keep their values between function calls)
// move forward one second every 1000 milliseconds
if (millis() – lastTick >= 1000) {
lastTick = millis();
second ;
}
// move forward one minute every 60 seconds
if (second >= 60) {
minute ;
second = 0; // reset seconds to zero
}
// move forward one hour every 60 minutes
if (minute >=60) {
hour ;
minute = 0; // reset minutes to zero
}
if (hour >=24) {
hour=0;
minute = 0; // reset minutes to zero
}
munit = minute; //sets the variable munit and hunit for the unit digits
hunit = hour;
ledstats = digitalRead(0); // read input value, for setting leds off, but keeping count
if (ledstats == LOW) {
for(i=1;i= 10 && minute = 30 && minute = 50 && minute = 20 && minute = 40 && minute = 10 && hour = 20 && hour
HELP SOON ;
ok so i put in the (origional) code and it said an Error (here: for(i=1;i
Great project! Someone else asked about it already, but does anyone know if it’s possible to get an accurate time pulse with arduino? I’ve tested this out and my clock gets off about two minutes every day.
There seems to be a problem with the code, i line 55
Doesn’t work with atmega328
Should it???
Yep, it should!!
has anyone implemented this code with the chronodot real time clock?
i’m having trouble with the circuit – any help/suggestions would be great..
thanks,
kate
Great work! Tried it and it works great using your code!
However, I have a question:
How do I connect the two buttons (that are used to set the time) to the analog input pins? The schematic you provided is only for one button. I had the problem where each button was changing both minutes and hours (when I connected both buttons and analog pins to the same +5V pin).
Thanks in advance to anyone who helps! 🙂
This is excellent! Was wondering what the difference is between a pushbutton and a button? You use both here but how so I know which one it is – the arduino homepage doesn’t make it clear?
Thank you…
Hi, I re-buildt your clock and it works like a breeze … thanks for sharing schematics and code. 🙂
Hey ALEX, can you post the code?, i´m trying to complile but gives me several errors, you mention you rebuild the clock, what are the fixes u implemented?
Hi Cesar,
sure. I did not really change much yet, just fixed an unnecessary space in one line and commented out the parts of the code that handle the settings buttons (as I have not connected them yet and instead set the time directly in the code before uploading the program). I have posted this version of the code below. I hope it helps.
I have also experimented with changing the code to using the Time Library (http://www.arduino.cc/playground/Code/Time). If you are interested, I can send you this alternative program, too.
Best, Alex
/*
An open-source binary clock for Arduino.
Based on the code from by Rob Faludi (http://www.faludi.com)
Code under (cc) by Daniel Spillere Andrade, http://www.danielandrade.net
http://creativecommons.org/license/cc-gpl
*/
int second=0, minute=0, hour=0; //start the time on 00:00:00
int munit,hunit,valm=0,valh=0,ledstats,i;
void setup() { //set outputs and inputs
pinMode(1, OUTPUT);pinMode(2, OUTPUT);pinMode(3, OUTPUT);pinMode(4, OUTPUT);pinMode(5, OUTPUT);
pinMode(6, OUTPUT);pinMode(7, OUTPUT);pinMode(8, OUTPUT);pinMode(9, OUTPUT);pinMode(10, OUTPUT);
pinMode(11, OUTPUT);pinMode(12, OUTPUT);pinMode(13, OUTPUT);
pinMode(0, INPUT);
}
void loop() {
static unsigned long lastTick = 0; // set up a local variable to hold the last time we moved forward one second
// (static variables are initialized once and keep their values between function calls)
// move forward one second every 1000 milliseconds
if (millis() – lastTick >= 1000) {
lastTick = millis();
second++;
}
// move forward one minute every 60 seconds
if (second >= 60) {
minute++;
second = 0; // reset seconds to zero
}
// move forward one hour every 60 minutes
if (minute >=60) {
hour++;
minute = 0; // reset minutes to zero
}
if (hour >=24) {
hour=0;
minute = 0; // reset minutes to zero
}
munit = minute%10; //sets the variable munit and hunit for the unit digits
hunit = hour%10;
ledstats = digitalRead(0); // read input value, for setting leds off, but keeping count
if (ledstats == LOW) {
for(i=1;i= 10 && minute = 30 && minute = 50 && minute = 20 && minute = 40 && minute = 10 && hour = 20 && hour < 24) {digitalWrite(13, HIGH);} else {digitalWrite(13,LOW);}
}
// I commented this part of the code out because I have not added the buttons yet. Instead, I set the time directly in the code above by changing
// the values of the variables int second=0, minute=0, hour=0; before uploading the program.
// valm = analogRead(0); // add one minute when pressed
// if(valm<800) {
// minute++;
// second=0;
// delay(250);
// }
//
// valh = analogRead(5); // add one hour when pressed
// if(valh<800) {
// hour++;
// second=0;
// delay(250);
// }
}
Hey Cesar,
I tried to post the sourcecode here, but the comment is awaiting moderation since a couple of days. If you still need help, write me a mail to bogenfreund (AT) hotmail (DOT) com, and I will send you my version.
Best
Alex
BTW, this is a picture of my version of the binary clock: http://i.imgur.com/2K03J.jpg 🙂
Hey guys! @Bash, on the post I showed how to add one button, to add more then one, just use the same scheme but in a different INPUT pin.
@KeV Button and PushButton are the same thing 🙂
@Alex, you clock looks really good! 🙂 Thanks for sharing the information. I know the code is ugly, I’ve coded in 2008, should re-build it and re-make the code someday.
I won’t show that comment with the code because it will be too messy,
you can get the code from a txt file here:
http://www.danielandrade.net/wp-content/uploads/2008/07/arduno-binary-clock.txt
If you want to post a code, a good idea is use something like http://pastebin.com/
Keep on rocking!!
Daniel, thanks for clarifying. I don’t think the code is ugly, although it could be re-arranged for improving the readability. It also works quite well, so thanks again for sharing!
Also, thanks for the hint with pastebin. You can see the code I am using right now here: http://pastebin.com/sNGwr6uZ (I hope I got the thing with the license right).
As said, I have not yet implemented any buttons, but that could be added easily to the code using the adjustTime() function.
Best
Alex
Hi Daniel, i’ve just done your BCD clock, but i’ve a little problem. My hours and my minutes runs together, i dunno where i’m wrong. Minutes and hours runs together, and leds turn on/off after 250 millis (in fact if i change the delay time in the button section at the end of the code, leds run more or less fast) and they stop at 23:23, re-starting again at 00:00.
I dunno if the problem is the code or i’ve done a mistake assembling leds.
Thank you for your tutorial! and i hope that you can help me.
Hey, sounds like there is something wrong with your buttons then. The clock behaves as if the buttons are pressed all the time. Perhaps you have wired them differently (or wrong), so check that! Or try to comment out the button section, or try to exchange the >’s in the section for <'s.
Hope that helps!
Thanks a lot for this tutorial!
I used it as the basis for my binary clock, built inside an old clockwork:
http://www.robindelange.com/projects/aclockworkbinary
Hey, I used parts of your code to build a binary clock myself. Its composed of an LED matrix for showing the time (so I need only 8 digital output pins), and is soldered into a 3d printed case created in the game Minecraft.
The setup can be seen here: https://postapocalypticresearchinstitute.wordpress.com/
Thanks for sharing! 🙂
@Daniel, can you post the schematic diagram for this binary clock project? Thanks.
I did it! If you read carefully you will get how to assemble it. 🙂
i’d be grateful, if you posted how you connected the push buttons 🙂
i just built this, took me a while (because i soldered it) and at first i was having prolems, but then i found @Alex’s code and it is workig great now. a very fun and simple project would be really cool to implement into some sort of steampunk clock
Link is correct again.
I am an absolute newbie when it comes to electronics but I have always wanted to make a binary clock consisting of 13 80W light bulbs (HH:MM clock). Would the most practical way of doing this involve an Arduino controlling 13 relays that feed mains voltage (240V) to the bulbs?
Batteries?
It’s up to you to add batteries. 🙂
sorry!!
can you help me???
for your circuit
what code used???
I would guess he used the same code. 🙂
Thanks
Very enjoy to successful make the binary clock
But….
Is It possible to make a binary clock with arduino and display hours,minutes and seconds.*
I have found many project but nothing with Arduino.
Is there a way to make It ?
😉
SR
Daniel, can NTP be used to keep this clock on time? I plan to build this and use PoE to power the clock from the network switch, and hopefully set the time by NTP and resync via NTP every hour. Have you thought about using NTP instead of a RTC to set and keep time?
i have a problem pin 1 2 3 an 4 reset every time when i get to hour 24 so i can’t reach 59 minutes, how is it possible ? Are there some error in the code?
I connected everything as shown here, but clock is running to fast. All LEDs are changing every second. I’ve tried all LEDs just in a simple loop and they are all connected properly. Buttons are working correctly but just speeding up LEDs. I’m using Elegoo uno, but never had similar problems. I looked at code, and everything seem to be right. Any idea why it is behaving this way?
Hello Daniel’
I have just found your Binary Clock on the web and would love to build one (in fact I have already started) but being a total numpty at electronics I would need a bit more help.
Would it be possible for you to either send me or post some more detailed pictures on your website.
It’s not clear to me at the arduino end and switches, I have every thing ready to go and this is the only bit holding me up.
Great project bye the way, I plan to give it to my Son who is a computer programmer as a surprise for his office desk.
Any help would be greatly appreciated.
Cheers.
Colin
(UK)