Project tutorial

Simple Clock with LED Matrix © CC BY-NC-ND

A simple clock using LED matrix and RTC to display the time, date and temperature.

  • 4,982 views
  • 9 comments
  • 16 respects

Components and supplies

Apps and online services

About this project

1. Introduction

The LED matrix module is really versatile for use with microcontrollers and this project introduces a very simple digital clock using a single 8x8 LED matrix and an Arduino to show the time, date and temperature in degrees Celsius and Fahrenheit.

The matrix module is controlled by MAX7219 and the data of time and temperature are provided by a DS3231 RTC (Real Time Clock) module.

In this case, the DS3231 is more interesting to use because it has an internal temperature sensor and it is more accurate for time reading.

Video

2. Components

  • Arduino UNO R3
  • 8x8 LED matrix module with MAX7219
  • RTC DS3231 module
  • Breadboard
  • Jumpers

3. The Clock

Due to the size of LED matrix (8x8) only a number with two digits can be shown at same time.

The numbers are in 5x3 (rows x columns) and the first two rows at the top of matrix are used to represent the labels of all features.

Each feature is shown during a second before go ahead to the next.

At first row are:

  • Time: Hour (H) / Minute (M) / Second (S)
  • Date: Day (D) / Month (M) / Year (Y)
  • Temperature: Celsius (ºC) / Fahrenheit (ºF)

At second row are:

  • Weekdays: Mo / Tu / We / Th / Fr / Sa / Su

Note: The weekday is shown only when the date is viewed.

- RTC Time Setup:

If is the first time you are using the RTC module, you can adjust the time using the following statements I have included in the code marked as comments:

//setTime(20, 49, 00, 18, 02, 2019); // Set the Time and Date  
//RTC.set(now());                    // Set the RTC time

Remove the comments marks "//" at begining of those statements; set the values of time and date; compile the code again.

After these steps, rewrite the comments marks "//" on the same two statements, recompile the code and resend it to Arduino.

Code

Simple_Digital_Clock_with_LED_Matrix_and_RTC_DS3231_V1_4.inoArduino
Code for Arduino UNO
/*
     Project:   Simple Digital Clock
     Hardware:  Arduino UNO R3 - RTC DS3231 - MAX72xx LED Matrix
     Version:   Rev 1.4
     Date:      26.Feb.2019
     Author:    LAGSILVA
     License:   CC BY-NC-ND 4.0
                (Attribution-NonCommercial-NoDerivatives 4.0 International)
*/

#include <LedControl.h>                 // Library for LED Matrix - MAX72XX
#include <Wire.h>                       // Library for DS1307RTC - Pins of Arduino UNO: A4 (SDA), A5 (SCL)
#include <DS3232RTC.h>
#include <Time.h>                       // Library for Time
#include <TimeLib.h>

#define DS3232_I2C_ADDRESS 0x68         // I2C address (RTC)

// Global Variables
int lapse = 735;   // 735ms = (8000ms - 25ms * 5 * 8 * 2) / 8 - 15 = 750ms - 15(compensation value)

/*
  Pin numbers do Arduino para conexao com o MAX72XX (matriz de LED com controlador MAX72XX)
  pin 5 is connected to the DataIn (DIN)
  pin 6 is connected to LOAD (CS)
  pin 7 is connected to the CLK (CLK)
*/

LedControl lc = LedControl(5, 7, 6, 1);  // LedControl(int dataPin, int clkPin, int csPin, int numDevices)

// Array of Digits - 0 a 9 - Size 5x3

byte num[10][3] = {

  // Conventional Font type

  {0xF8, 0x88, 0xF8}, // 0
  {0xF8, 0x00, 0x00}, // 1
  {0xE8, 0xA8, 0xB8}, // 2
  {0xF8, 0xA8, 0xA8}, // 3
  {0xF8, 0x20, 0xE0}, // 4
  {0xB8, 0xA8, 0xE8}, // 5
  {0x38, 0x28, 0xF8}, // 6
  {0xF8, 0x80, 0x80}, // 7
  {0xF8, 0xA8, 0xF8}, // 8
  {0xF8, 0xA0, 0xE0}, // 9

};


void setup() {

  // Setup of Display "0"
  lc.shutdown(0, false);                // Wakeup Display "0"
  lc.setIntensity(0, 8);                // Set the Brightness of Display (0 to 15)
  lc.clearDisplay(0);                   // Clear Display "0"

  setSyncProvider(RTC.get);             // Function to read RTC (Real Time Clock)
  setSyncInterval(60);                  // Set the number of seconds between re-sync
  //setTime(19, 42, 00, 26, 02, 2019);    // Set the Time and Date
  //RTC.set(now());                       // Set the RTC time

}


void loop() {

  byte h, m, s, dd, mm, yy;
  long tC, tF;

  h = hour();
  m = minute();
  s = second();
  dd = day();
  mm = month();
  yy = year() % 100;

  // Plot Hour
  plotNum(h, 7);

  // Plot Minute
  plotNum(m, 6);

  // Plot Second
  plotNum(s, 5);

  // Plot Day
  plotNum(dd, 4);

  // Plot Month
  plotNum(mm, 3);

  // Plot Year
  plotNum(yy, 2);

  // Plot Temperature (C)    // Celsius degrees
  tC = RTC.temperature() / 4;
  plotNum(tC, 1);

  // Plot Temperature (F)    // Fahrenheit degrees
  tF = tC * 1.8 + 32;
  plotNum(tF, 0);

}


void plotNum (byte temp, byte stat) {

  byte tens = temp % 10;
  byte units = temp / 10;
  byte wd = weekday();

  wd = (9 - wd) % 7;

  if (wd == 0) {
    wd = 7;
  }

  for (byte i = 7; i >= 3; i--) {
    for (byte k = 0; k < 3; k++) {
      lc.setRow(0, k + 5, num[units][k] >> i);
      lc.setRow(0, k + 1, num[tens][k] >> i);
    }
    delay(25);
  }

  lc.setLed(0, stat, 0, true);            // Plot Status

  if (stat >= 2 && stat <= 4) {
    lc.setLed(0, wd, 1, true);            // Plot Weekday
  }

  delay(lapse);                           // Time delay between modes

  lc.clearDisplay(0);                     // Clear display

  for (byte i = 4; i <= 8; i++) {
    for (byte k = 0; k < 3; k++) {
      lc.setRow(0, k + 5, num[units][k] >> i);
      lc.setRow(0, k + 1, num[tens][k] >> i);
    }
    delay(25);
  }

}

Custom parts and enclosures

Paper Template for LED Matrix
Printed paper template to cover the LED matrix

Schematics

Schematic - Simple Digital Clock
Fritzing schematic

Comments

Similar projects you might like

Digital And Binary Clock With Two LED Matrix And RTC

Project tutorial by LAGSILVA

  • 6,479 views
  • 11 comments
  • 30 respects

Analog Clock with LED Matrix and Arduino

Project tutorial by LAGSILVA

  • 12,993 views
  • 9 comments
  • 45 respects

Digital & Binary Clock In 8 Digits x 7 Segments LED Display

Project showcase by LAGSILVA

  • 2,110 views
  • 3 comments
  • 9 respects

Ternary Digital Clock with Arduino

Project tutorial by LAGSILVA

  • 4,550 views
  • 6 comments
  • 12 respects

Amazing Binary Clock using LED Matrix Module

Project tutorial by LAGSILVA

  • 9,352 views
  • 10 comments
  • 50 respects

Tiny Calendar and Clock Featuring Moon Phase in a LED Matrix

Project showcase by LAGSILVA

  • 6,331 views
  • 6 comments
  • 35 respects
Add projectSign up / Login