Introduction: Odd Binary Clock

Hello all,

This project will show you an unpublished Binary Clock using LED display of 7 segments (see VIDEO) and controlled by an Arduino.

The idea is very simple, just converting binary data of hours, minutes and seconds into "A to G" segments of display.

I've never seen before this concept and the results are very interesting and may also can be developed in many other ways in future.

In this post I will introduce you two versions:

1) Using my LED Display Module.

2) Using Display 4 digits x 7 segments (TM1637 - Catalex)

Let's see them !!

Step 1: Material List

Components:

  • 01 x LED display Catalex TM1637 (07 Segments x 04 Digits)
  • 01 x Arduino UNO R3
  • Some wires

Optional:

  • 01 x Multiple LED Display Module
  • 01 x FYQ-5642AX(Common Anode LED Display 07 Seg x 04 Dig)

Step 2: Development & Arduino Programm

1) Version with LED Display Module (optional components used during development)

To speed up the development I have used the optional material listed before on an assembly with Display Module with FYQ-5642AX LED display.

I like the size of this display because it is easier to be viewed.

With the LED Module I have created is easier to assemble this version of prototype.

Without it I need to put on a breadboard many other components like shift register 74HC595 and many resistors and wires to connect everything.

Note: You can see the Video of this configuration working with a pattern (mask) over the display with the numbers to facilitate the reading until you are more trainned and confortable to read the display without it.

  • Arduino programming (Display Module Version)

/* Binary Clock with Multiple LED Display Module - V1.0
LED Display - 4 Digits x 7 Segments by LAGSILVA - 10.June.2016 */

int clockPin = 8; // Pin 8 of Arduino connected in the pin 11 of 74HC595 (Clock) int latchPin = 9; // Pin 9 of Arduino connected in the pin 12 of 74HC595 (Latch) int dataPin = 10; // Pin 10 of Arduino connected in the pin 14 of 74HC595 (Data)

int PWMPin = 11; // Pin 11 of Arduino connecte do pin PWM to control the Brightness of Display

int hh, mm, ss; unsigned long ti;

// A // ------ // | | // F | | B // | G | // ------ // | | // E | | C // | D | // ------

// 0 // ------ // | | // 16 | | 1 // | 32 | // ------ // | | // 8 | | 2 // | 4 | // ------

void setup() {

pinMode(latchPin, OUTPUT); // Define the 3 digital pins (Latch-Clock-Data) as output pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); pinMode(PWMPin, OUTPUT);

hh = 16; //Initial setup of hours mm = 17; //Initial setup of minutes

}

void loop() {

for (ss = 0; ss <= 59; ss++) {

ti = millis(); // Initial time for the Timer of Hour/Time

while ((millis() - ti) < 1000) {

//analogWrite(PWMPin, 10); //Ajusta o brilho do display via entrada PWM (0 a 255 = 100% a 0% de brilho)

// Plot Hours (hh) digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, LSBFIRST, ~B10000000); //Set DISPLAY 1 shiftOut(dataPin, clockPin, LSBFIRST, 0); if (hh == 0) { shiftOut(dataPin, clockPin, MSBFIRST, 1); } else { shiftOut(dataPin, clockPin, MSBFIRST, hh << 1); } digitalWrite(latchPin, HIGH);

// Plot Minutes (mm) digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, LSBFIRST, ~B01000000); //Set DISPLAY 2 shiftOut(dataPin, clockPin, LSBFIRST, 0); if (mm == 0) { shiftOut(dataPin, clockPin, MSBFIRST, 1); } else { shiftOut(dataPin, clockPin, MSBFIRST, mm << 1); } digitalWrite(latchPin, HIGH);

// Plot Seconds (ss) digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, LSBFIRST, ~B00100000); //Set DISPLAY 3 shiftOut(dataPin, clockPin, LSBFIRST, 0); if (ss == 0) { shiftOut(dataPin, clockPin, MSBFIRST, 1); } else { shiftOut(dataPin, clockPin, MSBFIRST, ss << 1); } digitalWrite(latchPin, HIGH);

}

}

mm = mm + 1; if (mm > 59) { mm = 0; hh = hh + 1; if (hh > 23) { hh = 0; } }

}

Note: The printed mask is attached on this step is for FYQ-5642A LED display. Just print it, cut the paper and put it over the display.

2) Version with Catalex LED display (TM1637)

In this version I used a serial display Catalex with no mask.

Note: The schematics are also available in this step.

  • Arduino programming (TM1637 - Catalex Display)

/* Digital Clock
Binary Clock with 7 Segments Display - TM1637 (4 Digits x 7 Segments) by LAGSILVA - V1.0 - 10.Jun.2016 */

#include

// Module connection pins (Digital Pins) #define CLK 8 //Arduino Conection on Pin #8 = CLK of Display Module #define DIO 9 //Arduino Conection on Pin #9 = DIO of Display Module

// // A // ---- // F | | B // - G- // E | | C // ---- // D /

/ // 0 // ---- // 16 | | 1 // -32- // 8 | | 2 // ---- // 4 //

uint8_t data[] = {

0, // data[0] for Hours 0, // data[1] for Minutes 0, // data[2] for Seconds

};

int hh, mm, ss; unsigned long ti;

TM1637Display display(CLK, DIO);

void setup() {

display.setBrightness (0x0a);//(0x0f) is the max brightness;

hh = 10; //Initial setup of Hours mm = 55; //Initial setup of Minutes

}

void loop() {

for (ss = 0; ss <= 59; ss++) {

// Plot Hours (hh) for (int k1 = 0; k1 <= 7; k1++) { if (bitRead(hh, k1) == 1) { bitWrite(data[0], k1 + 1, 1); } else { bitWrite(data[0], k1 + 1, 0); } } if (hh == 0) { bitWrite(data[0], 0, 1); } else { bitWrite(data[0], 0, 0); } display.setSegments(data + 0, 1, 0);

// Plot Minutes (mm) for (int k1 = 0; k1 <= 7; k1++) { if (bitRead(mm, k1) == 1) { bitWrite(data[1], k1 + 1, 1); } else { bitWrite(data[1], k1 + 1, 0); } } if (mm == 0) { bitWrite(data[1], 0, 1); } else { bitWrite(data[1], 0, 0); } display.setSegments(data + 1 , 1, 1);

// Plot Seconds (ss) for (int k1 = 0; k1 <= 7; k1++) { if (bitRead(ss, k1) == 1) { bitWrite(data[2], k1 + 1, 1); } else { bitWrite(data[2], k1 + 1, 0); } } if (ss == 0) { bitWrite(data[2], 0, 1); } else { bitWrite(data[2], 0, 0); } display.setSegments(data + 2 , 1, 2);

delay(980); //Not exactly 1 second due the compesantion for processing time

}

mm = mm + 1; if (mm > 59) { mm = 0; hh = hh + 1; if (hh > 23) { hh = 0; } }

}

3) Setup the time

The following statements in the program are used for the setup of hour and minutes.

Just adjust them before compile the program to Arduino as shown in this example:

hh = 16; //Initial setup of hours
mm = 17; //Initial setup of minutes

Step 3: How It Works

The main principle of this project is Binary Number.

For each number of hours, minutes and seconds you need to convert them from base-10 (decimal) to base-2 (binary) and them to code them into segments from "A to G" of the display.

But that is very easy using the Arduino programming.

All integer numbers inside the range of hours (00 to 23), minutes and seconds (00 to 59) are lower than 64 and so they can be arranged into the 7 segments.

Take a look on this:

// A

// ------ // | | // F | | B // | G | // ------ // | | // E | | C // | D | // ------ // 0 // ------ // | | // 16 | | 1 // | 32 | // ------ // | | // 8 | | 2 // | 4 | // ------

You can see the perfect corresponce between: Segments -->>-- Binary (Base-2)

G=32 / F=16 / E=8 / D=4 / C=2 / B=1 / A=0 

32 16  8  4  2  1  0

G  F  E  D  C  B  A

But hey !!! There is a trick here !

Remember that Base-2 starts from 1 (2 power 0) and not zero !!

Zero in this case means that the corresponding segment of display will be set to Off and I want that the first segment must be set to On.

How can we do this?

Take a look on following statements of programming:

<p>if (mm == 0) {<br>        shiftOut(dataPin, clockPin, MSBFIRST, 1);
      }
      else {
        shiftOut(dataPin, clockPin, MSBFIRST, mm << 1);
      }</p>

First I check if the variablle mm (minutes) is zero. If yes, I force the LED to be set to On.

For all the numbers higher than zero, I shift left one position of binary number to correspond to the correct segment that I need with the command hh << 1.

Example:

Minutes = 0 then binary is 00000000 and it will be set to 00000001

Minutes = 5 then binary is 00000101 and it will be shift left one position to 00001010

Step 4: Conclusion

Now you have an original binary clock and learnt something about base-2 numbers and programming.

The programs shown here work as example for future developments.

You can add more features on this clock using a RTC (Real Time Clock) for example or add some buttons to setup the time.

Use your imagination and go ahead.

I hope you have enjoyed this simple project and feel free to send your questions and comments.

Regards,

LAGSILVA

10.June.2016

Comments

author
AndrewV34 (author)2017-03-03

Hi, I tried to make this with a 7-segment LED HT16K33 backpack and it doesnt seem to be working. Any idea what I can do to make it work :-\

I love this project

IMG_2691.JPG
author
lagsilva (author)AndrewV342017-03-03

Hello AndrewV34,

You are using a LED display other than me and you need to use the corresponding Adafruit library:

https://github.com/adafruit/Adafruit_LED_Backpack

Of course you need to rewrite the code according to this library.

For this you can follow the example of clock_sevenseg to understand what you need to update in my code:

https://github.com/adafruit/Adafruit_LED_Backpack/...

Greetings,

LAGSILVA

author
zposner (author)2016-12-14

definitly interesting

author
lagsilva (author)zposner2016-12-14

Thank you !

About This Instructable

1,399views

14favorites

License:

Bio: I am a Mechanical Engineer and an enthusiastic Maker. I like to develop new ideas combining electronics and programming.
More by lagsilva:Analog Clock With LED Matrix and ArduinoChinese Rings PuzzleTalking Clock with Arduino
Add instructable to: