DIY: Binary Clock with Arduino

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

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…

imagem-binario.png

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:

button1.png

If you don’t understand what I am trying to explain, you can go to the arduino website here.

Images + Video

Binary Clock II

Binary Clock I

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.

/*
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, 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< =13;i++){
digitalWrite(i, LOW);}

} else {

//minutes units
if(munit == 1 || munit == 3 || munit == 5 || munit == 7 || munit == 9) { digitalWrite(1, HIGH);} else { digitalWrite(1,LOW);}
if(munit == 2 || munit == 3 || munit == 6 || munit == 7) {digitalWrite(2, HIGH);} else {digitalWrite(2,LOW);}
if(munit == 4 || munit == 5 || munit == 6 || munit == 7) {digitalWrite(3, HIGH);} else {digitalWrite(3,LOW);}
if(munit == 8 || munit == 9) {digitalWrite(4, HIGH);} else {digitalWrite(4,LOW);}

//minutes
if((minute >= 10 && minute < 20) || (minute >= 30 && minute < 40) || (minute >= 50 && minute < 60)) {digitalWrite(5, HIGH);} else {digitalWrite(5,LOW);}
if(minute >= 20 && minute < 40) {digitalWrite(6, HIGH);} else {digitalWrite(6,LOW);}
if(minute >= 40 && minute < 60) {digitalWrite(7, HIGH);} else {digitalWrite(7,LOW);}

//hour units
if(hunit == 1 || hunit == 3 || hunit == 5 || hunit == 7 || hunit == 9) {digitalWrite(8, HIGH);} else {digitalWrite(8,LOW);}
if(hunit == 2 || hunit == 3 || hunit == 6 || hunit == 7) {digitalWrite(9, HIGH);} else {digitalWrite(9,LOW);}
if(hunit == 4 || hunit == 5 || hunit == 6 || hunit == 7) {digitalWrite(10, HIGH);} else {digitalWrite(10,LOW);}
if(hunit == 8 || hunit == 9) {digitalWrite(11, HIGH);} else {digitalWrite(11,LOW);}

//hour
if(hour >= 10 && hour < 20) {digitalWrite(12, HIGH);} else {digitalWrite(12,LOW);}
if(hour >= 20 && hour < 24) {digitalWrite(13, HIGH);} else {digitalWrite(13,LOW);}

}

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

}

Binary Clock III

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

Share/Save/Bookmark

23 Replies

No one has
  1. 1 Scott Kirkwood

    Oi Daniel,

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

  2. 2 Ryan Barnes

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

  3. 3 Arquitetura Digital

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

  4. 4 DanielAndrade

    @Arquitetura Digital Obrigado =)

  5. 5 Angel Kiel

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

  6. 6 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 www.arduino.cc :)

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

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

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

  10. 10 DanielAndrade

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

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

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

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

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

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

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

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

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

  1. 1 YourITronics
  2. 2 DIY: Binary Clock with an Arduino
  3. 3 Binary Arduino clock « Sumber Ilmu Anda
  4. 4 Relógio Binário com Arduino at Gambiarra!
  5. 5 only hacks» Blog Archive » Arduino Binary Clock

Leave a Reply