Tiny LED Matrix Display Clock


Introduction: Tiny LED Matrix Display Clock

About: Hi, I have a hobby to build some DIY Audio stuff, simple gadgets, etc. Hope you will find my instructables useful! :)

I have always wanted to have old-fashioned desktop clock, that looks like something from the movies of the 90's, with pretty humble functionality: real-time clock, date, changing background light, beeper and an alarm option. So, I've come with an idea, to build one: A digital device, based on microcontroller with all the features I've mentioned above, and powered by USB - either PC or any mobile USB charger. Since I wanted to make it programmable, with menus and settings adjustment, MCU placement was inevitable in this project. ATMEGA328P IC (That every Arduino Uno board consists of) was chosen to be the "brain" of the circuit (Speaking of which, I just had plenty of them). Combining some electronic parts as RGB LED, trickle charge timekeeping chip and push-buttons, enabled the birth of the entire project - Programmable small-sized LED display desktop clock.

So, after we've covered the entity of the project, let's build it!

Step 1: The Idea

As it was mentioned before, our device contains some good-looking LED matrix displays, color changing RGB LED backlight, trickle-charge timekeeping chip, convenient USB power supply unit, and small-sized enclosure.

Let's describe device operation block diagram by parts:

1. Power Supply Unit:

Since device operates on 5 Volts DC, power supply component consists of two separate circuits:

  • Micro-USB input - For direct Charger\PC power supply.
  • 5V Linear voltage regulator circuit based on LM7805 IC.

The LM7805 IC circuit is optional, unless you prefer to implement different power supply input availability. In our device, Micro-USB PSU is used.

2. Microcontroller Unit:

Microcontroller ATMEGA328P, acts as a "brain" of the whole device. Its purpose is to communicate with all the peripheral circuitry, provide needed data and control device's user interface. Since chosen microcontroller is ATMEGA328P, we will need Atmel Studio and basic C knowledge (Schematics and programming sequences are described in the further steps).

3.Real-Time Clock circuit:

The second most important circuit in the device. Its purpose is to provide date and time data, with a requirement of storing it, with no dependency on input power connection, i.e time data is being refreshed in real-time mode. In order to make RTC component able to continue changing time\date data, 3V coin-cell battery is added to the circuit. The IC is DS1302, its operation is described in further steps.

4. Input Interface - Push Button Switches:

Input PB switches provide input interface for user. These switches are processed in the MCU and controlling device defined program.

5. LED Matrix Display

Device display consists of two IC wrapped HCMS-2902 Alphanumeric LED matrices, each IC has 4 characters of 5x7 tiny LED matrix. These displays are simple to use, 3-Wire communication supported and small-sized - everything we need in this project.

6. RGB Backlight:

Color changing backlight is based on external RGB LED, controlled by PWM signals coming from the MCU. In this project, RGB LED has total of 4 pins: R,G,B and common, where R,G,B color palette is controlled via PWM by MCU.

7. Buzzer:

Buzzer circuit is used as sound output, mainly for alarm purposes. BJT switch is used to provide enough current to the buzzer component, so it's volume will be loud enough to wake up a living person.

Step 2: Parts and Instruments

I. Electronics:

A. Integrated and Active Components:

  • 1 x ATMEGA328P - MCU
  • 2 x HCMS2902 - AVAGO Displays
  • 1 x DS1302 - RTC
  • 1 x 2N2222A - BJT (NPN)

B. Passive Components:

  • Resistors:
    • 5 x 10K
    • 1 x 180R
    • 2 x 100R
  • Capacitors:
    • 3 x 0.1uF
    • 1 x 0.47uF
    • 1 x 100uF
    • 2 x 22pF
  • 1 x 4-pin RGB LED
  • 1 x Buzzer
  • 1 x 32.768KHz Crystal

C. Connectors:

  • 1 x Micro-USB connector
  • 2 x 6-pin standard pitch(100mil) connector.
  • 2 x 4-pin standard pitch(100mil) connector.
  • 1 x Coin-cell Battery case.

D. Miscellaneous:

  • 3 x SPST Push-Button switches
  • 1 x 3V Coin-cell battery.

E. Optional PSU:

  • 1 x LM7805 - Linear Regulator
  • 2 x 0.1uF Cap
  • 2 x 100uF Cap

II. Mechanical:

  • 1 x Plastic Enclosure
  • 4 x Rubber attachments
  • 1 x prototype soldering board
  • 1 x MCU header (In the case of microcontroller failure)
  • 2 x Small 8mm bolts
  • 2 x 8mm Washers

III. Instruments And Materials:

  • Soldering wires
  • Shrinking tubes
  • Soldering tin
  • Soldering iron
  • Cutter
  • Plier
  • Tweezers
  • Drill Bits
  • Small-sized File
  • Various Screwdrivers
  • Caliper
  • Multimeter
  • Breadboard (Optional)
  • Micro USB Cable
  • Medium-sized File
  • Hot Glue Gun
  • AVR ISP Programmer

IV. Programming:

  • Atmel Studio 6.3 or 7.0.
  • ProgISP or AVRDude
  • Microsoft Excel (For display character creation)

Step 3: Schematics Description

In order to make it easier to understand circuit's operation, schematics step is divided into seven sub-groups. You should notice, that net names are defined in the schematic page also define connections between separate sub-circuits of the device.

A. Main Components Board:

As it was mentioned before, all the appropriate sub-circuits we want to be "inside" the device, are placed on a single cut prototype board. Let's proceed to the explanation of main board placed circuits operation:

1. Microcontroller Circuit:

MCU that is used in this project is a ATMEGA328P. It is powered by an external 5V power supply, in this case - micro USB connector. All the appropriate I/O pins are connected according to the design requirements. Ports I/O mapping is easy to understand, since all the net names are defined exactly as it will be used in the programming step. MCU has simple RC reset circuit, that is used either on programming sequence and power initialization.

The crucial part of MCU is the programming circuitry. There is a 6-pin programming connector - J5, make sure that VCC, GND and RESET nets are common to the external ISP programmer and main components board.

2. Real-time Clock Circuit:

The next circuit, is a main peripheral part in the project. DS1302 is a trickle charge timekeeping IC, that provides processed time and date values to our processing unit. DS1302 communicates with MCU via 3-wire interface, similar to the 3-wire SPI communication, on the following lines:

  • RTC_SCK (Output): Performs driving and sampling of data that is being transmitted on the SDO line.
  • RTC_SDO (I/O): Data driving line. Acts as input to the MCU when time/date data is being received and as output when data is being transmitted (See Programming Essentials step for further explanation).
  • RTC_CE:(Output): Data transmission enable line. When is set HIGH by MCU, data is ready to be transmitted/received.

DS1302 requires an external 32.768KHz crystal oscillator for the adequate circuit behavior. In order to avoid large drift on the circuit counting system (Drift phenomena is just inevitable in these types of integrated circuits), there is need to place two calibrating capacitors on each crystal pin (See parts X1, C8 and C9 in the schematics). 22pF was an optimal values after a lot of experiments with time keeping measures in this project, so, when you are about to solder the circuit altogether, make sure that there is an option to substitute these capacitors with ones with other values. But 22pF for small-sized board worked pretty well for very small drift (7 Seconds per month).

The last but not least component in this circuit - 3V coin-cell battery should be placed on the board in order to supply enough energy to the DS1302 IC so it would continue its time-counting operation.

4. 8 Characters LED Matrix:

Device display is based on 2 x 4 characters LED Matrix display ICs, programmed via 3-wire interface, similar to the RTC circuit's DS1302, with single difference, that data providing line (SDI) is defined as MCU's output (Unless you want to add status check ability to your display circuit).
Displays are combined in a series 3-Wire extension, thus both ICs act as a single display device, where there is an ability to program it for all the display characters definition ( See SPI series combination). All the net names of the circuit, match MCU appropriate connections - note that there are common nets, that establish communication between the displays, and thefe is no need to connect both displayscommunucation interfaces to the MCU. Programming and character building sequence are defined in further steps.

5. User Interface circuit:

User interface is divided into two sub-groups - Input and output systems:
Input System: Device itself has user provided input defined as three SPST push button switches, with additional pull-up resistors, in order to drive defined logic either HIGH or LOW to the MCU. These switches provide control system for the entire programmed algorithm, since there is need to adjust time/date values, menu control, and so on.

6. Output System:

A. Buzzer circuit provides sound output in both states, menu switching acknowledge sound and alarm algorithm. NPN transistor is used as a switch, providing enough current to the buzzer, making it sound in an appropriate itensity. Buzzer is controlled directly by MCU's software.
B. RGB LED is used as backlight part of the device. It is controlled directly by MCU, with four options for backlight choice: RED, GREEN, BLUE, PWM or OFF modes.
Notce that resistors that are connected in series to the LED R, G and B pins have different values, since each color has different intensity over a constant current. For green and blue LEDS there are the same characteristics, when red has slightly greater intensity. Thus red LED is connected to the greater ressistance value - in this case: 180Ohm (See RGB LED Explanation).

7. Connectors:

Connectors are placed on the main board in order to enable communication between external interface components such as: Display, RGB LED, Power input and push button switches, and main board. Each connector is dedicated to different circuit, thus complexity of device assembly drops dramatically. As you can see in the schematics, each connector nets order is optional and can be swapped, if it makes wiring process much simpler.

After we've covered all the schematics concepts, let's proceed to next step.

Step 4: Soldering

Probably for some of us it is the hardest step in the whole project. In order to make it much easier to make device work as soon as possible, soldering process should be completed in the following sequence:

1. MCU and programming connector: it is recommended t solder 28 pin header instead of MCU itself in order to be able to substitute MCU IC in the case of failure. Make sure device is able to be programmed and powered on. It is recommended to place pin description sticker on the programming connector (See third picture).

2. RTC circuit: after soldering all the needed parts, make sure that calibrating capacitors are easy to be substituted. If you want to use 3V coin cell battery case - make sure it matches device enclosure dimensions.

3. Display: Two display ICs should be soldered on the separate small-sized board (Pic. 1). After soldering all the needed nets, there is need to prepare off-board wires (Pic. 4): these wires should be soldered and conducted on the side of the display board, note, that tension and mechanical stress applied to the wires would not affect solder joints on the display board.

4. On the wires from the previous step, label stickers should be placed - that would make assembly process much easier in the further step. Optional step: add a male single-pin connector to each wire (Arduino style).

5. Solder remaining connectors on the main board, including peripheral components. Once again, it is recommended to place stickers with a pin description for each connector.

6. Buzzer circuit: buzzer is located inside the device, so it should be soldered on the main board, there is no need for the interconnecting connector.

7. RGB LED: In order to save main board space, I have soldered the series resistors ON the LED pins, where each resistor corresponds to its own matched color and appropriate MCU pin (Pic. 5).

Step 5: Assembling

This step defines project appearance - electrical and mechanical. If all the recommended notes were taken into account, assembly process becomes very easy to perform. The following step-by-step sequence provides full process information:

Part A: Enclosure

1. Drill three holes, according to the push button knob diameter (3mm in this case).
2. Drill one buzzer-dedicated hole on the side of the enclosure. Any desired drill bit diameter can be used.
3. Drill small hole as a basis for grinding according to the USB connector you should use (Micro USB in this case). After that, perform grinding with the small-sized file, to match connector dimensions.
4. Drill relatively large hole as a basis for grinding. Perform grinding with a medium sized file, according to the display dimensions. Make sure that display ICs are present on the external side of the enclosure.
5. Drill medium sized hole on the bottom of the device, according to the RGB LED diameter.

Part B - Attachments:

1. Solder two wires to each of the three push buttons (GND and signal). Label stickers and single pin connectors on wires are recommended.
2. Attach four prepared wires to the RGB LED pins. Place label stickers and shrinking tubes on the solder joints.
3. Attach four rubber legs on the bottom of the device.

Part C - Connecting The Parts:

1. Place RGB LED on the bottom of the enclosure, connect it to dedicated connector on the main board. Attach it with the hot glue.
2. Place three push button switches, connect them to dedicated connector on the main board, attach them with the hot glue.
3. Place USB connector, connect it to the programming connector power supply pins (VCC and GND). Make sure that polarity of the power supply lines matches soldered parts. Attach it with hot glue.
4. Place display board, connect it to dedicated connector. Attach it with the hot glue.


1. It is recommended to add bolt-nut pairs to the main board-enclosure and upper cover (As it is shown in this case).
2. In order to avoid broken wires failure, attach them with their appearance inside the enclosure is taken into account.

Step 6: Brief Programming Introduction

After all the parts are soldered, it is recommended to perform initial device testing before proceeding to the final assembly step.

MCU code is written in C, and ATMEGA328P is programmed via any ISP Programmer (There are various types of Atmel programming devices: AVR MKII, AVR DRAGON etc. - I've used cheap USB ISP Programmer from the eBay, that is controlled by ProgISP or AVRDude software). Programming environment has to be Atmel Studio 4 and above (I strongly recommend the newest versions of software).
If external, non Atmel Studio inherent programmer is used, there is need to give .hex file path to the programming software (Usually located in Debug or Release folder of the project). Make sure that before proceeding to the assembly step, device can be programmed, and any basic AVR dedicated project build and compilation process are based on ATMEGA328P microcontroller (See Atmel Studio tutorial).

Step 7: The Code Description

Decice code algorithm is layered into two semi-separate layers:
1. Core layer: Communication with peripheral circuits, device operations definition, initialization and component declarations.
2. Interface layer: User-device interaction, menu functionality, clock/buzzer/color/alarm adjustment.

The program sequence is described in the Pic. 1, where each block corresponds to the MCU state.
Described program acts as basic "operating system" that provides interface between hardware and outside world. The following explanation describes essential program operation by parts:

Part A: Core Layer:

1. MCU I/O Initialization: First of all, there is need to initialize hardware components:
- Code-used constants.
- Ports I/O - Interface.
- Peripheral communication declarations.

2. Basic General Functions: Some functions are used by separate code blocks, the define operations on pins that are controlled by the software:
- Enable/Disable RTC and display board communication.
- Buzzer sound generation on/off.
- 3-Wire Clock up/Clock down functions.
- Display character creation functions.

3. Peripheral Initialization: After I/O ports are configured, communication between circuits functions definition take place. When finished - MCU begins initialization of RTC and display circuits using functions that were defined above.

4. Core functions definition: At this stage, the device is set and ready to perform communications with some peripheral circuits. These functions define:
- Switch toggle control
- RGB LED operation (Especially PWM)
- Buzzer square wave generator

5. Display Functions: I did not find much on the internet about the HSMS ICs I've used, so I wrote its library by myself. Display functions provide complete character displaying functionality, including display of ASCII characters and any integers. Functions are written in the generalized way, so if there is need to summon display functions from any part of the code, it is easy to use them since they are generalized by operation (For example: String display, single character display etc.).

6. RTC operation functions: All the RTC functions are written in generalized way (Similar to the Display functions set) according to the operation of DS1302 IC. Code is based on written library, which are available in many variations on gitHub . As you will see in the final code, display and RTC functions set are included in the separate .c and .h files.

Part B - Interface Layer:

1. Main function: at the void main() section, there is declaration of all the core initialization functions. Right after the initialization of all the components, MCU enters infinite loop, where device functionality is controlled by a user.

2. Real-time Switches, Backlight and Display Control: While running in an infinite loop, MCU performs refresh on each part of the device. It chooses what data to display, which button was pressed and which backlight mode was chosen.

3. User menu functions: These functions have tree-like form (See Pic. X), where menu system and hierarchy is defined as a state machine. Every state machine controlled by a user input - push button switches, thus when appropriate push button was pressed - state machine will change its value. It is designed in a way that any of the changes in the device performed in menu, are changed instantly.

4. User Menu Switching: when the user input is provided, menu state has to change its state. So, these functions provide user-dependent control over a state machine. In this particular case: next, previous and OK.

Step 8: Final Code and Useful Files

And that's it!
In this step, you can find all the files you may need:
- Electrical Schematics
- Complete Source Code
- Display Character Builder

Optional Feature:
There are a variety of characters that are available to be displayed in the display ICs library, but some are not included. If you wish to build characters by yourself, add case state with an ASCII reference in Print_Character(' ') function (See display.c functions).

Hope you'll find this Instructable useful :)
Thanks for reading!



    • Microcontroller Contest

      Microcontroller Contest
    • Woodworking Contest

      Woodworking Contest
    • Casting Contest

      Casting Contest

    We have a be nice policy.
    Please be positive and constructive.