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.

  • 2,858 views
  • 3 comments
  • 15 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

Materials 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.

Code

The Arduino code is shown in attached file.

The code uses the libraries LedControl and Time.

Fast Tip: You can find many libraries for Arduino at Arduino Library List: http://www.arduinolibraries.info/

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.

Custom parts and enclosures

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

Schematics

Schematic for Analog Clock
Schematic file in PDF for Analog Clock

Code

Code for Analog Clock with LED Matrix and ArduinoArduino
Code for Arduino UNO R3
/*
       Analog Clock with LED Matrix
           V1.1 - 26.Jul.2017
               by 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, segundo;
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);

}

Comments

Similar projects you might like

Using 9 Axes Motion Shield with Arduino

by Techduino

  • 45 views
  • 0 comments
  • 3 respects

Guess the Number With Arduino KeyPad

Project tutorial by Giovanni Gentile

  • 98 views
  • 2 comments
  • 3 respects

LED Roulette Game

Project tutorial by Arduino “having11” Guy

  • 36 views
  • 0 comments
  • 2 respects

Bluetooth Control Multitap

Project showcase by 윤원호 and gledel

  • 6 views
  • 0 comments
  • 1 respect

Know the Temp of Your Home From Anywhere with Arduino Cloud!

Project tutorial by Isaac100

  • 2,066 views
  • 2 comments
  • 11 respects

Launch Pad Count Down Sequence Display

Project in progress by Douglas Frey

  • 97 views
  • 0 comments
  • 2 respects
Add projectSign up / Login