Making a binary clock using a PIC Microcontroller

You can use a PIC microcontroller and an LED matrix to create a binary clock (or if you prefer you can wire up individual LEDs).  

This project uses an LED matrix block as it saves lots of wiring. 

So what is it ?

Its an led clock that displays the time information as binary numbers...

...and it is a good way of learning how to read binary (well up to 9 any way!).  

You can represent the numbers 0-9 using 4 binary digits so only four leds are needed for each time digit. There's a binary-decimal conversion table here

To display hours, minutes and seconds (2 digits each) you need 6 binary digits in total (depending on whether you use a 24 hour clock the top digit needs only 1 or 2 LEDs).

LED Binary Clock block diagram

binary clock block diagram

How to read a binary clock

the time is displayed in 24 hour mode so:

  • The 1st two digits represent 0-23 hours,
  • The next two digits represent 0-59 minutes,
  • The next two digits represent 0-59 seconds.

To show the time 6 digits are needed as follows:

Binary Clock digit defiinition

MSD 0-2
LSD 0-3
Minutes MSD 0-5
Minutes LSD 0-9
Seconds MSD 0-5
Secondss LSD 0-9

(MSD,LSD Most Significant Digit, Least Significant Digit)

Note: You could use a 5x7 led matrix as only the right hand 4 leds (also only 6 rows)are used in this project.

The black rectangle, in the diagram above, shows which leds you need to look at - the rest are not used in this project.  You read the clock starting from the top and read horizontal row of four LEDs as a binary number. Each LED that is on represents a one and each LED that is off represents a zero. You then use the conversion table to translate it into decimal until you become so good at it that you won't need the table!


This project uses the same hardware as the led matrix project using a 16F88 PIC microcontoller and an LED matrix.  Its worth taking a look there as the same hardware description applies on how to multiplex the display.

I'll just say here that instead of using 64 output pins only 10 are needed to drive the display.

PIC Microcontroller binary clock display hardware
(Click diagram to open a pdf)

binary clock hardware diagram


Binary clock display Red 8x8 LEDs matrix (for convenience) you only really need a 6x4 LED matrix and you can only buy an 8x8 or a 5x7!

Binary Clock display project details.

PIC Microcontroller Binary Clock Project
Compiler Mikroelectronika MikroC Compiler Free!
Target 16F88/16F84 (retargetable to other PICs that have an enough pins).
Software level Easy.
Software notes Multiplexing the display/clock algorithm.
Hardware level Easy.
Hardware notes No special notes
Project version 1.01
Project files Enter your details to get the Download Link
and get the microcontroller newsletter:

(Your email is safe it will never be sold or rented).
You will get All the C source code and hex file.

Note: Check your email for the project code download link.

PIC Micro Binary Clock Software

Project files for the dot matrix led display

Compiler project files

C Source files.

Header files.

Output files

Binary Clock code description.


This contains all the code except :

    • Bit manipulation routines found in bit.h
    • Type definitions in types.h

The code is simple to follow and everything is done in main().

The multiplexing method is the same for the led matrix project so have a look there for the software description of that method.

The only difficult part is to correctly control the time display but its not that difficult as you can see in the code.

Note definitions FLIPLR and ROT180 allow you to alter the display orientation without re-wiring the board!


You can improve the project to make it into a full clock by adding a set of keys in the same way as the RTC project.  This would let you set and change the time.

PIC Microcontroller Accuracy

This project relies on the accuracy of the microcontroller's internal oscillator which is only 1% - and this is not very accurate at all.  You can expect to loose ~15 minutes per day!

For a better accuracy use an external crystal as shown in some of the other projects. If you use a crystal the clock will be accurate to a few minutes per month.

Note: Even when using a standard crystal  the board layout is very important - i.e. it will be a lot better than 1% but won't be as good as watch crystal accuracy. 

You could use a DS1307 clock chip but even these accurate to about 2 seconds per day (loss) as they rely on a 20ppm watch 32kHz crystal - good track layout and correct capacitive crystal loading is needed to get the accuracy shown.

Binary clock accuracy

Clock source Accuracy Error per Day Error per Month
Internal oscillator 1% 14 minutes 7 hours

Standard crystal

100ppm 8.64 seconds 4.32 minutes

Watch crystal

20ppm 1.73 seconds 51 seconds

You can program the PIC in circuit through the ICSP connector.

You can find some notes on comparing ppm clock accuracies here.

New! Comments

Have your say about what you just read! Leave me a comment in the box below.

Jump from binary clock to
Best-microcontroller-projects home page

Privacy Policy | Contact | About Me

Site Map | Terms of Use

Visit our Facebook Page:

   Click Here

Recent Articles

  1. The TP4056: Lithium Ion/polymer Battery Charger IC

    Learn how to use the TP4056 properly. There's a right way, and a wrong way, to use it to safely charge Lithium Ion batteries.

    Read more

  2. How to use the MCP4728, a versatile four channel DAC with built in voltage reference.

    The MCP4728 chip is a four channel 12 bit DAC, with memory that outputs voltage that you can use for calibration, anywhere you want a fixed voltage.

    Read more

  3. Secrets of the Hitachi HD44780 LCD: How to display text and bargraphs.

    Find out how to connect the Hitachi HD44780 and use it to display text and graphics in any of your projects.

    Read more

  4. INA219: A voltage and current sensing chip using I2C

    INA219: How to use the INA210 for maximum accuracy in current and power measurements

    Read more

  5. Arduino Oversampling: How to Get More ADC Bits with No Extra Hardware!

    Arduino oversampling is a technique to increase ADC resolution by reading more samples then decimating. It really does work!

    Read more

  6. How to use the ADS1115

    A tutorial on using the ADS1115 precision 16 bit ADC for low power use.

    Read more

Readers Comments

"I wanted to thank
you so so so much
for all the information
you have provided in
your site it's


- Ranish Pottath

"This site really is
the best and my favorite.
I find here many useful
projects and tips."

- Milan


"Awesome site,
very, very easy and nice
to navigate!"

- Matt

Learn Microcontrollers

"Interested in

Sign up for The
Free 7 day guide:


"I am a newbie to PIC
and I wanted to say
 how great your
site has been for me."

- Dave


"Your site is a great
and perfect work.

- Suresh


"I couldn't find the correct
words to define
yourweb site.

Very useful, uncovered,
honest and clear.

Thanks so much for
your time and works.

- Anon

Back to Top