DIY: Binary Clock with Arduino

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

leds1.png

Binary Example

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…

Binary Example

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:

Button

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.

Binary Clock III

Hope you liked, any question just ask! And if you make your own, send me pics =)

96 Comments Add yours
  1. Pingback: YourITronics
  2. @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 🙂

  3. 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!

  4. 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

  5. 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

  6. 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

  7. 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.

  8. 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.

  9. 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.

  10. 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.

  11. 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

  12. 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

  13. 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.

  14. 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.

  15. 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!

  16. 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.

  17. 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. 🙂

  18. 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

    1. 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.

  19. 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!

  20. 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.

  21. @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.

  22. 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!

  23. 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

  24. 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.

  25. 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

  26. 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! 🙂

  27. 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…

    1. 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?

      1. 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);
        // }

        }

      2. 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

  28. 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!!

    1. 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

  29. 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.

    1. 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!

  30. 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

  31. 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?

  32. 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

  33. 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?

Leave a Reply

Your email address will not be published. Required fields are marked *