Binary Clock with Arduino Micro and RTC DS1307

Binary Clock

I’ve build a Binary Clock to learn a bit more about Arduino Programming and to make myself keep the binary system in check.

Instead of using input buttons for setting the time, I’m going to use a real time clock (RTC) – the DS1307. I’m not going to explain how to assemble it (the one I bought came in pieces to assemble) and how to set the time the first time. You can find out more with the excellent Adafruit tutorial by Tyler Cooper.

Needed Parts

  • 17x LEDs
    • 6 yellow (seconds)
    • 5 (hours) + 6 (minutes)
  • 17x 120 Ohm resistors
  • 1x Arduino Micro
  • 1x DS1307 RTC breakout
  • 1x Adafruit PowerBoost 500 Basic (Optional)
  • 1x Lipo Battery (Optional)

The following picture shows how the connections are going to be made. We’re going to use all the digital PINs and all of the analog PINs of the Arduino Micro.

BinaryClock_bb

DS1307 RTC

To connect the DS1307, we’re going to use the I2C protocol. More about I2C in the Sparkfun learning system.

DS1307 has 5 PINs, but we’re just going to use 4.

  • GND and VCC are self explanatory.
  • SCL is the I2C clock PIN
  • SDA is the I2C data PIN

In the Arduino Micro, the SDA and SCL pins are PINs 2 and 3 (respectively), which we’re going to use.

More info about the Arduino Micro

You can learn more about the DS1307 RTC in the Adafruit website.

Assembly and wiring

I had laying around a acrylic cube from an early project –  Build an LED ambient light with Arduino and a Light/Lux/Luminosity Sensor – and decided to used it for a binary clock.

First, using a small wooden box i create the holes for the LEDs. Although the hours will just take 5 LEDs, I’ve decided to drill six holes nonetheless.

Box1

The LEDs inserted in the holes

LEDs

This next image is the other side of the box, with the LEDs and the resistors soldered to the cathode (the short leg)

LEDs with resistors

The next image are the LEDs already soldered together by the resistors.

 

6

This next image shows (according to the code) how to wire which LED to which PIN in the Arduino Micro

Wiring

Connecting the wires to the LEDs (anodes – Long leg) which will connect to the Arduino Micro

Wiring

The connections all made

8

Another shot of the connections

7

The following image shows the clock running with the Lipo battery and the Adafruit Powerboost 500 Basic

Clock with Lipo Battery

 

 

The acrylic cube

The Cube

Code

The code is based in the elegant and excellent  solution provided by Simon Monk on his book “30 Arduino Projects for the Evil Genius“.

My only changes are just using the RTC library and using 24 hours, instead of just 12.

The RTC library, to use with the DS1307, is needed. You can get it from the Adafruit RTClib Github account.

Uncompress it and move it to your Arduino libraries folder.

Code explaining

The code is fair simple to understand:

Three arrays are created – hours, minutes and seconds – each containing the PIN numbers for each LED corresponding to each “part” of time you want.

A simple solution (Thank you Simon) to translate the digit (be it hour, second or minute) into binary is using the bitread function.

Using the bitread function, we get a binary representation of the decimal number we want.

Example: 23

Using bitread (with 6 digits), we get 111010, which is 23 in reverse – 010111, therefor the PINs used in the minutes and seconds arrays are reversed – least significant bits first

When wiring, you wire the LEDs in order, but in the code they’re reversed because of the way bitread returns the result.

This next image is the Binary clock already running

9

Here’s some videos that show the Binary Clock working

 

Hope you had fun !

Happy programming !

5 Replies to “Binary Clock with Arduino Micro and RTC DS1307

  1. Hi,
    nice binary clock especially because it shows also seconds
    I want to rebuilt it but if i don’t have an arduino micro, I want to built it with an AT Mega328 in standalone. (without the arduino board)
    How I have to adapt your sketch and the wirings?

    Greetings,
    André

  2. Hi,

    thanks for your your answer. You are right. The most doubt i have is with the SDA,SCL pins for the I2C bus.
    The AT Mega 328 has special pins (27,28) for this bus and on the micro board you use D2,D3. For me this are normal digital pins aren’t they who in this example are used for I2C ?
    Well I will try in respect of the equivalent pins of the AT Mega and see what’s happen.
    Best Regards,
    A.

  3. Thanks for posting this project. I used a Nano for the project. I used A4 and A5 for the SDA and SCL and pins 2 and 3 for the seconds. Lines 13 and 15 were changed to reflect these changes. Everything is the same.

    int secondLEDs[] = {3, 2, A3, A2, A1, A0};

    int loopLEDs[] = {3, 2, A3, A2, A1, A0, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 1};

Leave a Reply to Andre Cancel reply

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