Project tutorial

Analog Clock with LED Matrix and Arduino © CC BY-NC-SA

This is my project about an Analog Clock on a LED matrix and Arduino.

  • 10,507 views
  • 8 comments
  • 30 respects

Components and supplies

Necessary tools and machines

Paper Template to cover the LED Matrix

Apps and online services

About this project

Introduction

LED matrix with MAX7219 are very versatile and can be used in several projects with Arduino.

In this case, I used it to simulate an analog clock without its hands, with very interesting results. The hours and minutes are placed around the center of matrix giving a familiar look of analog clocks. The code I have developed applies a little of trigonometry (sine and cosine) to calculate the coordinates of hours and minutes to be shown into LED matrix. With that I saved many lines of coding.

The assembly is very simple using few components and you will have no problems to work on it.

Let's do it!

Video

Material List

The material you need is shown in the following list:

  • Arduino UNO R3
  • Module of LED Matrix with MAX7219 (Maxim Integrated)
  • Tactile Push Buttons (02 x)
  • Breadboard (small size)
  • Jumper Wires
  • Paper template to cover the LED Matrix (see attached file for printing)

Note: This project uses the Arduino internal clock. It is not so accurate as an external RTC (Real Time Clock), but for the purposes of this project, it works very well.

Schematic

The schematic is attached and you should follow it closely for the jumpers connections.

Setup

After starting, the default time shown is 00:00 hs.

For adjustments there are only two tactile buttons to perform the setup of time:

  • Setup of Hours
  • Setup of Minutes

Just keep it pressed for adjustments.

The hours are shown in the display by numbers between 1 and 12. The minutes are shown by numbers between 0 and 55 in steps of 5 minutes.

In the last column of display is shown the fractional minutes from 1 to 4 that must be added to the minutes shown in the main template of clock.

In the middle of display, there is an LED blinking each second and there are also two LEDs for AM and PM indication.

Code

Analog_Clock_with_LED_Matrix_V1_1.inoArduino
Arduino's code for Analog Clock with LED matrix
/*
       Analog Clock with LED Matrix
    V1.1 - 26.Jul.2017 - Arduino UNO R3
             Author: LAGSILVA
*/

#include <LedControl.h>
#include <Time.h>
#include <TimeLib.h>

/*
  ***** Pin numbers for LedControl *****
  pin 10 is connected to the DataIn
  pin 08 is connected to the CLK
  pin 09 is connected to LOAD / CS
  We have only a single MAX72XX.
*/
LedControl lc = LedControl(10, 8, 9, 1);

byte xRef = 4; // Reference Row
byte yRef = 3; // Reference Collunm
byte mm1, mm5, hora, minuto;
byte ultMinuto = 10, ultHora = 10;
byte horaPin = 7, minutoPin = 6;
boolean ajustaHora = true, ajustaMinuto = true;
float pi = 3.1415927, xHH, yHH, xMM1, yMM1, xMM5, yMM5;


void setup() {

  pinMode(horaPin, INPUT_PULLUP);
  pinMode(minutoPin, INPUT_PULLUP);

  /* Wakeup call for MAX72XX */
  lc.shutdown(0, false);

  /* Set the brightness to a medium values */
  lc.setIntensity(0, 2);

}


void loop() {

  // Setup of Hours & Minutes
  ajustaHora = digitalRead(horaPin);
  ajustaMinuto = digitalRead(minutoPin);

  if (!ajustaHora) {
    adjustTime(3600);
  }

  if (!ajustaMinuto) {
    adjustTime(60);
  }

  hora = hour();
  minuto = minute();

  if (minuto != ultMinuto || hora != ultHora) {

    ultMinuto = minuto;
    ultHora = hora;
    lc.clearDisplay(0);

    // Minutes in steps of 5 (range of 0 to 55)
    mm5 = minuto / 5 * 5;

    //Minutes (1 to 4)
    mm1 = minuto % 5;

    // AM period
    if (hora >= 0 && hora <= 11) lc.setLed(0, xRef + 1, yRef, true);

    // PM period
    if (hora >= 12 && hora <= 23)lc.setLed(0, xRef - 1, yRef, true);

    // Coordinates for Hours & Minutes (steps of 5)
    xHH = round(-cos(hora * pi / 6) * 2) + xRef;
    yHH = round(sin(hora * pi / 6) * 2) + yRef;
    lc.setLed(0, xHH, yHH, true);

    xMM5 = round(-cos(mm5 * pi / 30) * 3.1) + xRef;
    yMM5 = round(sin(mm5 * pi / 30) * 3.1) + yRef;
    lc.setLed(0, xMM5, yMM5, true);

    //Coordinates for Minutes (1 to 4)
    yMM1 = yRef + 4;
    xMM1 = (mm1 - 1) * 2 + xRef - 3;
    if (mm1 > 0) lc.setLed(0, xMM1, yMM1, true);

  }

  // Center LED Blinking
  if (ajustaHora && ajustaMinuto) {
    lc.setLed(0, xRef, yRef, true);
    delay(200);
    lc.setLed(0, xRef, yRef, false);
    delay(800);
  }
  else delay(250);

}

Custom parts and enclosures

Paper Template
Paper Template to be print and put over the LED Matrix

Comments

Similar projects you might like

A Microwave Interface for the IKEA Duktig Kids Kitchen

Project showcase by Myles Eftos

  • 1,308 views
  • 8 comments
  • 7 respects

Servo Signals and Characterization

by 3 developers

  • 1,098 views
  • 4 comments
  • 13 respects

Music Adaptive RGB LED with Arduino and Processing

Project in progress by ounane mohamed elfarouk

  • 1,016 views
  • 6 comments
  • 10 respects

Cellular IoT with Blynk & Hologram

by Moheeb Zara

  • 5,027 views
  • 9 comments
  • 18 respects

Monitoring Temperature Remotely with Blynk for Dummies

Project in progress by Cmtelesann

  • 1,224 views
  • 2 comments
  • 4 respects

How to Make a Customizable Punchable Keyboard Button

Project tutorial by Amal Mathew

  • 1,528 views
  • 4 comments
  • 4 respects
Add projectSign up / Login