Introduction: Arduino Binary Clock

Picture of Arduino Binary Clock

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.

Step 1: The Arduino Prototype

Picture of 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

Picture of 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(Wire.read()); minutes = bcdToDec(Wire.read()); hours = bcdToDec(Wire.read() & 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of Putting It Together - Part Un

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

Step 9: Putting It Together - Part Deux

Picture of 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... http://www.ikea.com/ca/en/catalog/products/00132524/

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

Picture of 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 :)

Comments

ssj_vegeta (author)2016-12-05

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

Clapoti (author)ssj_vegeta2016-12-05

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.

marcospardal made it! (author)2016-12-03

Thank you. This was my first experience to learn how to use and program Arduino.

Clapoti (author)marcospardal2016-12-04

Cool, I'm happy it inspired you :)

'DrackuinM (author)2016-11-15

QUE ARDUINO UTILIZO? FUNCIONARA PARA ARDUINO UNO? soy nuevo en esto

Clapoti (author)'DrackuinM2016-11-15

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.

ve3joc (author)2016-03-05

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.

Thanks

Clapoti (author)ve3joc2016-03-06

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

ve3joc (author)Clapoti2016-03-06

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

seamster (author)2015-05-26

Very nicely done!

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

Clapoti (author)seamster2015-05-26

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

seamster (author)Clapoti2015-05-26

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

Clapoti (author)seamster2015-05-26

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

MurtadaH (author)Clapoti2016-01-31

please i want pdf on my mail

thank you

smandal13 (author)2015-08-15

nice work

Clapoti (author)smandal132015-08-17

Thank you :)

Cello62 (author)2015-05-27

Great job! Thanks for sharing it

Clapoti (author)Cello622015-05-27

Thank you and thanks to your project for inspiring me to do it :)

About This Instructable

4,530views

70favorites

License:

Bio: Software Developper by day, maker and learner by night/weekends ;)
More by Clapoti:Quiz Game Show Buzzer Bluetooth EditionArduino Binary ClockWooden Puzzle Modular Electronics Prototyping Board
Add instructable to: