Arduino Binary Clock




About: Software Developper by day, maker and learner by night/weekends ;)

I've finally made it, the binary clock the people around me heard me talked about for so long. I was trying to make this during the last christmas break, but time was lacking, I changed jobs 2 times in the last 6 months... so things were a bit hectic, but now everything is fine and I did it :)

I don't want to pretend like it's my idea. I took the design from this great instructables : My Arduino Binary Clock by Cello62and I gave it my touch.

I used a real time clock to keep exact time, I used just the Atmega328 instead of a full Arduino and made some small changes here and there, but the clock's design is all Cello62's.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: The Arduino Prototype

First I made the prototype with the Arduino, then I prototyped the circuit I would have in the final product, using the Atmega328 chip instead of the full Arduino to be sure that everything was working correctly.

Step 2: The Schematics

Here you can see how the push buttons, the leds and the real time clock are connected with the Arduino.

N.B. the resistance values are not correct.

Step 3: The Code

First let's setup the beginning to communicate with the real time clock and keep the time

#include <Wire.h>

//DS3232 I2C Address #define RTC_ADDRESS 0x68

//DS3232 Register Addresses #define RTC_SECONDS 0x00 #define RTC_MINUTES 0x01 #define RTC_HOURS 0x02

//Times keeping variables
byte seconds; //00-59 byte minutes; //00-59 byte hours; //00-23

Then we set constants to define the pins of the Arduino for the leds and push buttons

//Buttons pins
const int minutesButton = 14; const int hoursButton = 15;

//LED pins const int hoursPin10 = 0; const int hoursPin20 = 1;

const int hoursPin1 = 2; const int hoursPin2 = 3; const int hoursPin4 = 4; const int hoursPin8 = 5;

const int minutesPin10 = 6; const int minutesPin20 = 7; const int minutesPin40 = 8;

const int minutesPin1 = 9; const int minutesPin2 = 10; const int minutesPin4 = 11; const int minutesPin8 = 12;

Then we need to initialize everything in the setup function

void setup() {
//Set Button pins mode pinMode(minutesButton, INPUT); pinMode(hoursButton, INPUT); //Set LED pins mode pinMode(hoursPin10, OUTPUT); pinMode(hoursPin20, OUTPUT); pinMode(hoursPin1, OUTPUT); pinMode(hoursPin2, OUTPUT); pinMode(hoursPin4, OUTPUT); pinMode(hoursPin8, OUTPUT); pinMode(minutesPin10, OUTPUT); pinMode(minutesPin20, OUTPUT); pinMode(minutesPin40, OUTPUT); pinMode(minutesPin1, OUTPUT); pinMode(minutesPin2, OUTPUT); pinMode(minutesPin4, OUTPUT); pinMode(minutesPin8, OUTPUT); //Start the RTC communication Wire.begin(); //Initialize and set time seconds = 00; minutes = 00; hours = 00; }

And we will have a simple loop function calling different functions to do the work it needs to do. We will sleep for 500 ms because we don't need to loop as fast as we can, this also helps with setting the time when we press the push buttons so it doesn't change too fast.

void loop() {
checkInputs(); getTime(); displayLights(); delay(500); }

Here's how we check for push buttons inputs and react to them

//----- Input Function -----

void checkInputs() { if (digitalRead(minutesButton) == HIGH) { minutes++; seconds = 00; if (minutes == 60) { minutes = 00; } setTime(); } if (digitalRead(hoursButton) == HIGH) { hours++; seconds = 00; if (hours == 24) { hours = 00; } setTime(); } }

To access the real time clock, let's create a setTime and getTime function

//----- RTC Functions -----

void setTime() { Wire.beginTransmission(RTC_ADDRESS); Wire.write(0); Wire.write(decToBcd(seconds)); Wire.write(decToBcd(minutes)); Wire.write(decToBcd(hours)); Wire.endTransmission(); }

void getTime() { Wire.beginTransmission(RTC_ADDRESS); Wire.write(0x00); Wire.endTransmission(); Wire.requestFrom(RTC_ADDRESS, 3); seconds = bcdToDec(; minutes = bcdToDec(; hours = bcdToDec( & 0b00111111); }

You probably noticed some strange function calls in the code above... let's create those utility functions. They are useful to convert decimal numbers to a byte readable by the real time clock protocol and vice versa

//----- Utility functions ----

byte decToBcd(byte val) { return ( (val/10*16) + (val%10) ); }

byte bcdToDec(byte val) { return ( (val/16*10) + (val%16) ); }

Now let's turn on and turn off the appropriate leds depending on what time it is

//----- Display Function -----

void displayLights() { if (hours >= 20) { digitalWrite(hoursPin20, HIGH); digitalWrite(hoursPin10, LOW); } else if (hours >= 10) { digitalWrite(hoursPin20, LOW); digitalWrite(hoursPin10, HIGH); } else { digitalWrite(hoursPin20, LOW); digitalWrite(hoursPin10, LOW); } int hoursUnit = hours % 10; if (hoursUnit >= 8) { digitalWrite(hoursPin8, HIGH); digitalWrite(hoursPin4, LOW); digitalWrite(hoursPin2, LOW); } else if (hoursUnit >= 6) { digitalWrite(hoursPin8, LOW); digitalWrite(hoursPin4, HIGH); digitalWrite(hoursPin2, HIGH); } else if (hoursUnit >= 4) { digitalWrite(hoursPin8, LOW); digitalWrite(hoursPin4, HIGH); digitalWrite(hoursPin2, LOW); } else if (hoursUnit >= 2) { digitalWrite(hoursPin8, LOW); digitalWrite(hoursPin4, LOW); digitalWrite(hoursPin2, HIGH); } else { digitalWrite(hoursPin8, LOW); digitalWrite(hoursPin4, LOW); digitalWrite(hoursPin2, LOW); } if (hoursUnit % 2 == 1) { digitalWrite(hoursPin1, HIGH); } else { digitalWrite(hoursPin1, LOW); } if (minutes >= 40) { digitalWrite(minutesPin40, HIGH); digitalWrite(minutesPin20, LOW); if (minutes >= 50) { digitalWrite(minutesPin10, HIGH); } else { digitalWrite(minutesPin10, LOW); } }else if (minutes >= 20) { digitalWrite(minutesPin40, LOW); digitalWrite(minutesPin20, HIGH); if (minutes >= 30) { digitalWrite(minutesPin10, HIGH); } else { digitalWrite(minutesPin10, LOW); } } else if (minutes >= 10) { digitalWrite(minutesPin40, LOW); digitalWrite(minutesPin20, LOW); digitalWrite(minutesPin10, HIGH); } else { digitalWrite(minutesPin40, LOW); digitalWrite(minutesPin20, LOW); digitalWrite(minutesPin10, LOW); } int minutesUnit = minutes % 10; if (minutesUnit >= 8) { digitalWrite(minutesPin8, HIGH); digitalWrite(minutesPin4, LOW); digitalWrite(minutesPin2, LOW); } else if (minutesUnit >= 6) { digitalWrite(minutesPin8, LOW); digitalWrite(minutesPin4, HIGH); digitalWrite(minutesPin2, HIGH); } else if (minutesUnit >= 4) { digitalWrite(minutesPin8, LOW); digitalWrite(minutesPin4, HIGH); digitalWrite(minutesPin2, LOW); } else if (minutesUnit >= 2) { digitalWrite(minutesPin8, LOW); digitalWrite(minutesPin4, LOW); digitalWrite(minutesPin2, HIGH); } else { digitalWrite(minutesPin8, LOW); digitalWrite(minutesPin4, LOW); digitalWrite(minutesPin2, LOW); } if (minutesUnit % 2 == 1) { digitalWrite(minutesPin1, HIGH); } else { digitalWrite(minutesPin1, LOW); } }

And the clock can work :)

Step 4: Making the LED Board

Getting the tools ready.

Then you should print the file attached here to get a template of where to drill holes.
I used only 5mm LEDs.

I then got the glue gun out to make little "boxes" so the light from each LED doesn't travel to another hole.

Step 5: Installing the LEDs

I then installed the LEDs and put a resistor to every anode (-) pins.

And I connected them all together and to one of the wire of a flat ribbon wire.

Then I connected all the cathodes(+) to a wire part of a flat ribbon wire.

Step 6: Making the Box

I then took a box big enough to house the circuit board, the buttons and the 5V D/C input.

I drilled holes for the buttons and got the size right after with a file.

I installed the buttons and fixed them with hot glue and identified the buttons to set the time. The red one is just to cut the flow of the ground for all the LEDs to turn off the lights without stopping the clock.

Step 7: Making the Board

I then cut a board to the right size to install the circuit with the Atmega328 and all the wiring.

Step 8: Putting It Together - Part Un

Let's hook up everything together in the box and test it.

Step 9: Putting It Together - Part Deux

Then it's time to put everything in the frame, I reused a RIBBA frame that I had lying around (13cm x 18cm) (6" x 8") from IKEA...

I decided to fix the boards with screws in the frame and to hold the box to the back of the frame with hot glue.

Step 10: The Finished Product

Now it's time to see the final product, it's a nice piece of decoration.

To read the time you just need to add the values of each lights... for the tens and units of hours and the tens and units of minutes.

The first image would read (1, 2+4, 2, 1+2+4)... so 16h27

The last image would read (1, 1+2+4, 1+2, 1+2) so 17h33

The only thing I regret is not having more lights behind the Hours and Minutes at the top, because it doesn't light up properly... maybe one day I'll open it and make the modification.

Let me know what you think :)

Reuse Contest

Participated in the
Reuse Contest

Bedroom Contest

Participated in the
Bedroom Contest

Crafting 101

Participated in the
Crafting 101

2 People Made This Project!


  • Assistive Tech Contest

    Assistive Tech Contest
  • Reuse Contest

    Reuse Contest
  • Made with Math Contest

    Made with Math Contest

18 Discussions


2 years ago

Hi, nice work with clock. I'm using rtc ds3231, is there any change in code because of that (It has to be...)? I wired everything like on and nothing happens.. :/

3 replies

Reply 1 year ago

I just prototyped this project and used a DS3231 I had laying around. It worked perfectly with no changes to Clapoti's code necessary.


Reply 1 year ago

Glad it all worked well :)


Reply 2 years ago

It should be the same I guess... but I can't be sure.
So many things can go wrong, bad wiring, error in the code... I honestly don't know what it could be.


3 years ago


1 reply

Reply 3 years ago

Yes I use an Arduino Uno... on the final product I use only the Atmega328 that the Arduino Uno use.

But you can use the full Arduino Uno if you want... but it's more expensive than just the chip.


3 years ago

Nice job for sure! Will your code work on a Arduino Mega? I have everything I need to build it except I have the Mega 2560 rather than the UNO.


2 replies

Reply 3 years ago

Well I've never used the Mega, but it should work the same way.


Reply 3 years ago

Thank you for the quick reply. I will give it a try and see how it goes.
Thanks again for sharing.


4 years ago on Introduction

Very nicely done!

*Step 4 . . . There's just something about seeing power tools in living rooms that makes me smile! Love it! :)

4 replies

Reply 4 years ago on Introduction

Thanks a lot :)
Yeah I'm living in a 2 bedroom apartment for now so I don't have a lot of space :)


Reply 4 years ago on Introduction

I've got a little more space nowadays, but I've definitely been there! Good stuff.

I hope we see lots of great projects from your workshop/living room! :)


Reply 4 years ago on Introduction

Thank you, I did some projects already, but definitely not as many as I wished... but I have some things in the works, I just need more hours in a day... or to win the lottery so I can quit my day time job ;)


Reply 3 years ago

please i want pdf on my mail

thank you