DIY: Binary Clock with Arduino

July 15, 2008

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 =)

Category: Arduino, Hardware, Howto


  • Pingback: YourITronics

  • Pingback: DIY: Binary Clock with an Arduino

  • http://forusers.com Scott Kirkwood

    Oi Daniel,

    That’s a fun little project.
    I think I’ll try it out.

  • http://www.thelowtech.com/ Ryan Barnes

    Very nice, I think I might give this a shot!

  • http://www.arquiteturadigital.com Arquitetura Digital

    Muito bom o esquema cara, parabéns, seu site é excelente, não conhecia!

  • Pingback: Binary Arduino clock « Sumber Ilmu Anda

  • http://www.danielandrade.net DanielAndrade

    @Arquitetura Digital Obrigado =)

  • Pingback: Relógio Binário com Arduino at Gambiarra!

  • Pingback: only hacks» Blog Archive » Arduino Binary Clock

  • Angel Kiel

    hi! im interested with the project.. but i dont know what’s ARDUINO is.. can u help me with it? thank u..

  • http://www.danielandrade.net DanielAndrade

    @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 :)

  • Andy C

    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!

  • http://www.danielandrade.net DanielAndrade

    @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

  • Clyde Arrowny

    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

  • http://www.danielandrade.net DanielAndrade

    Why use all 13 LEDs for secons? didnt get your point :)

  • Clyde Arrowny

    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

  • Clyde Arrowny

    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

  • http://www.danielandrade.net DanielAndrade

    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

  • http://www.gdesign.com.au Sid Guglielmino

    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

  • gary

    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.

  • gary

    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.

  • Syd

    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.

  • 238

    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.

  • Pingback: Alt Fn :: 1337 » Blog Archive » Arduino Project #3: True Binary Clock

  • Pingback: Alt Fn :: 1337 » Blog Archive » How To: Arduino True Binary Clock

  • RAUL RENDON

    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

  • http://www.danielandrade.net DanielAndrade

    Raul, yes, you can use a RTC with it!! If the LILYPAD have the same outputs/inputs as a atmel168, yes you can!

  • Pingback: Functional Artsy Arduino Binary Clock | ArduinoFun.com

  • http://www.arduinofun.com Shawn

    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/

  • jay

    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

  • jay

    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.

  • Woodworm

    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.

  • http://www.danielandrade.net DanielAndrade

    @Woodworm, yes, what you are saying may work! Thanks, I just didn’t get the italian part =P

  • Woodworm

    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!

  • http://www.danielandrade.net DanielAndrade

    @Woodworm great to know that it’s working. Are using 6V with the Voltage Regulator? Is it working properly? Vielen Dank =)

  • Woodworm

    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.

  • http://www.danielandrade.net DanielAndrade

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

  • Ali

    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

    • Alex

      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.

  • Woodworm

    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!

  • Woodworm

    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.

  • http://www.danielandrade.net DanielAndrade

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

  • Woodworm

    Hello,

    i found a very good workaround here: http://www.instructables.com/id/SCAKJ38G145SWHO/

  • MHead

    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!

  • NickNerd

    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

  • NickNerd

    HELP SOON ;
    ok so i put in the (origional) code and it said an Error (here: for(i=1;i

  • Pingback: Arduino-powered binary clock « Clock-a-Day

  • Pingback: Arduino Binary Clock | About:Y-aji

  • Pingback: Binary Arduino Watch | Adrian Lombard

  • http://www.tmatthew.net Tyler Brown

    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.

  • Robin

    There seems to be a problem with the code, i line 55

  • Pingback: DIY Actigraphy with Arduino « The Mad Edition

  • Hanno

    Doesn’t work with atmega328

    Should it???

  • http://www.danielandrade.net DanielAndrade

    Yep, it should!!

  • http://kateewatkins.com kate

    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

  • Pingback: Make Cool Stuff: Digi-Comp II

  • Bash

    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! :)

  • KeV

    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…

  • Pingback: Make Cool Stuff: Digi-Comp II - Free Plans, Hacks, Howto's and other DIY stuff - Free Plans Online

  • Alex

    Hi, I re-buildt your clock and it works like a breeze … thanks for sharing schematics and code. :)

    • Cesar

      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?

      • Alex

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

        }

      • Alex

        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

  • Alex

    BTW, this is a picture of my version of the binary clock: http://i.imgur.com/2K03J.jpg :)

  • http://www.danielandrade.net DanielAndrade

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

    • Alex

      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

  • Oxy

    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.

    • Alex

      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!

  • Pingback: Linkita.net - Reloj binario con Arduíno.

  • Pingback: Arduino Binary Clock – By Daniel Andrade | Deven Prasad

  • Pingback: link : tutorial for a d.i.y binary clock « markfrances.co.uk

  • http://www.robindelange.com Robin de Lange

    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

  • Alex

    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! :)

  • Pingback: DIY Minecraft Binary Clock « post-apocalyptic research institute

  • Pingback: Lars Jansen » Huge index of Arduino & Freeduino Knowledge

  • Pingback: Prosty zegar binarny na Arduino | YWD - blog

  • Pingback: Zegar binarny na Arduino | Arduino

  • Ryan King Locsin

    @Daniel, can you post the schematic diagram for this binary clock project? Thanks.

    • http://www.danielandrade.net DanielAndrade

      I did it! If you read carefully you will get how to assemble it. :)

  • ismail

    i’d be grateful, if you posted how you connected the push buttons :)

  • bayly

    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

  • Pingback: Arduino Powered Binary Clock - Arduino for ProjectsArduino for Projects

  • Pingback: DIY Binary Clock with Arduino -Arduino for Projects

  • Robin de Lange

    Link is correct again.

  • Jonny Ashton

    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?

  • Pingback: Binäruhr – Teil 1 | Pascal's Königreich

  • Ple mesco

    Batteries?

    • http://www.danielandrade.net/ Daniel Andrade

      It’s up to you to add batteries. :)