Arduino Matrix Clock

Introduction: Arduino Matrix Clock

Description:

Build your clock using an Arduino, a matrix display, and a Real Time Clock (RTC) module. This is a fun and simple project which I feel is great for beginners. The clock uses the RTC module to accurately track time as well as the day, month, and year. In addition, the module has a built-in temperature sensor. You can learn more about the DS3231 module here as well as the I2C communication bus used for it here. Lastly we will use a Dot Matrix Display to of course, display the time, day of the week, month .etc. You can more about the display here and the MAX7219 IC driver in the datasheet below.

You can also download the pdf version for this project here. It's virtually the same as this instructable.

[UPDATE: 2/22/19] Don't use the pdf guide, I've updated this instructable but those changes are not yet reflected on the pdf.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Gather Components

The components you'll need for this project:

In addition, you’ll need an Arduino of any kind (preferably a Nano to minimize the size of the project), a breadboard, jumper wires as well as the Arduino IDE installed on your PC.

Step 2: Libraries

<br>

Download the following libraries and install the .zip file to the Arduino IDE by going
to Sketch > Include Library > Add .Zip library

NOTE: THE VERSIONS MATTER!!!

* Verify that you have the correct versions before downloading. I'd recommend downloading each library within the Arduino IDE to be on the safe side.

MD_Parola 3.0.1: https://github.com/MajicDesigns/MD_Parola

MD_MAX72XX 3.0.2: https://github.com/MajicDesigns/MD_MAX72XX

DS3231 1.0.2: https://github.com/NorthernWidget/DS3231

Alternatively,

In the Arduino IDE go to Sketch > Include Library > Manage Libraries and in the search bar type: “MAX72XX” and you should see the following (See image):

Install only MD_MAX72XX and MD_Parola. MD_MAXPanel is NOT needed.

Step 3: Testing Your Components

After Installing the libraries, test your components individually to ensure that they are working as they should. Please follow these steps before wiring everything together.

To test DS3231 RTC Module, Connect the DS3231 to the Arduino (see Wiring below). Then in the Arduino IDE, go to Files > Examples > DS3231 > DS3231_Test and upload the sketch. Open the Serial Monitor and check to see that you’re getting the correct date, time, day .etc.

To test the matrix display, first connect it to the Arduino (see Wiring below). Next, in the Arduino IDE, go to Files > Examples > MD_Parola > Parola_HelloWorld and upload the sketch. You should see HELLO printed on the display and it may or may not be printed backwards. If the text is backwards then you must change the following line:

#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW

To

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW

Upload the sketch again and the problem should be resolved.

Now that we’ve tested our components, we are ready to wire everything together!

Step 4: Wiring

Refer to the diagram or schematic or table

Step 5: CODE


Get the code here

Note: I used a code originally by Electronic Projects but modified it to support current (at the time of completion) libraries.

Clock Features:

The clock is automatically set to tell time in 24hr format but it can be easily changed to 12hr. The clock will also display the temperature (both in Celsius and Fahrenheit). I've also included a feature called 'Sleep Mode' which is set to "OFF" (See Sleep Mode below for details).

12hr Format: To set the clock to tell time in 12hr format, you'll have to comment line 88

hour =Clock.gethour(h12,PM); //24hr Format 

And uncomment lines 93 through 100

if (Clock.getHour(h12,PM)>=13 || Clock.getHour(h12,PM)==0) 
{
   h = Clock.getHour(12,PM) - 12;
}
   else
{
   h = Clock.getHour(h12,PM);
}

Sleep Mode:

This is a feature that helps reduce the brightness of the clock particularly during the hours in which we are asleep. I don't think you want to wake up in the middle of the night and by blinded by this clock. It is very bright even when it's at the lowest setting. To enable sleep mode, uncomment lines 177 to 184

if(h == 12 || h<8) //Time intervals (in this case, from 12AM to 8AM)
{
   P.setIntensity(0); //Set display brightness to lowest setting
}
   else 
{
   P.setIntensity(6); //Set display brightness to 6 (15 is the brightest)
}

Note: I've come across an issue when using sleep mode while the clock is set to 12hr mode. You'll notice that it will run twice a day since 8am and 8pm are interpreted both as 8. So if you set Sleep Mode to be active from 9pm to 7am, then it will also be active from 9am to 7pm. HOWEVER, this issue does not occur if the clock is set to 24hr mode.

Step 6: Conclusion

Congrats!!! You have a working clock. This is how mine turned out [Clock Gallery]. I hope that you not only learned a little bit more about components and coding, but that you enjoyed the journey getting there. Please share with me your thoughts on this guide over at anthotroncis@gmail.com. This is in fact my first project guide and hoped it served you well. I hope to create many more guides. In addition, if you have any questions, suggestions, and/or improvements on the project, feel free to message me.

4 People Made This Project!

Recommendations

  • Backyard Contest

    Backyard Contest
  • Silly Hats Speed Challenge

    Silly Hats Speed Challenge
  • Finish It Already Speed Challenge

    Finish It Already Speed Challenge

64 Discussions

0
Ardudroid4869
Ardudroid4869

Question 10 days ago

How do to change the clock and date year. Thank you

1589562222412329395438149137214.jpg
0
Martin T
Martin T

8 months ago

I keep getting this fault every time i try to upload #include "Font_Data.h"
i have done everything to the letter as far as i can see, making sure i am using the right release1.2.0 etc.

The Hello code works fine

any help would be appreciated.

Martin

0
AnirbanD21
AnirbanD21

Reply 3 months ago

I have also getting same problem...PLEASE admin need you help.

0
bobw39
bobw39

Reply 5 weeks ago

Make sure your project .ino (in this case Matrix_Clock.ino) file is in the same folder as Font_Data.h both should be in a folder called Matrix_Clock. If they are not close the IDE and move the files to the folder (Make one if you have too) and run it from there.

0
AnirbanD21
AnirbanD21

Reply 11 days ago

Now I made this but Time and date is not correctly showing. Date showing 1 Jan 2000, Monday. But in calendar 1vJan 2000 is Saturday.I don't know how this time and date is getting. Please help me. I tried to change in serial but couldn't.

0
bobw39
bobw39

Reply 5 weeks ago

Make sure your project .ino (in this case Matrix_Clock.ino) file is in the same folder as Font_Data.h both should be in a folder called Matrix_Clock. If they are not close the IDE and move the files to the folder (Make one if you have too) and run it from there.

0
fpvGustl
fpvGustl

5 weeks ago

hi @ all!
and thank you for this building - its very cool
PLEASE is it possible to show ONLY THE TIME??
do not need Temp and Date!
thx in advance

0
BarzanM1
BarzanM1

Question 1 year ago

how i can #include "Font_Data.h"clude

0
bobw39
bobw39

Answer 5 weeks ago

Make sure your project .ino (in this case Matrix_Clock.ino) file is in the same folder as Font_Data.h both should be in a folder called Matrix_Clock. If they are not close the IDE and move the files to the folder (Make one if you have too) and run it from there.

0
AnthoTRONICS
AnthoTRONICS

Answer 1 year ago

You can download the file by clicking on the get code here link in step 5. There you can download the code as well as the Font_Data.h or just copy the code. Make sure that when you open the Matrix_Clock.o file that you see both files like so

1.png
0
dancopy
dancopy

3 months ago

Cool design! A suggestion: make that same Watch but, controlled with IR Remote Control; Thanks

0
sertanari
sertanari

4 months ago

hi. i made this project and changed clock and temperature fonts but couldnt change date and day fonts. any idea? (i changed temp and clock font at Font_Data.h but it didnt affect day and date. also changed MD_MAX72xx_font.cpp but nothing changed.)
Font_Data.h changes:

5, 255, 255, 129, 255, 255, // 48 - '0'
4, 130, 255, 255, 128, // 49 - '1'
5, 251, 251, 137, 207, 207, // 50 - '2'
5, 195, 203, 137, 255, 255, // 51 - '3'
5, 15, 15, 8, 255, 255, // 52 - '4'
5, 207, 207, 137, 251, 251, // 53 - '5'
5, 255, 255, 137, 251, 251, // 54 - '6'
5, 3, 243, 249, 31, 15, // 55 - '7'
5, 255, 255, 137, 255, 255, // 56 - '8'
5, 207, 207, 137, 255, 255, // 57 - '9'


5, 255, 255, 9, 255, 255, // 65 - 'A'
5, 255, 255, 137, 255, 118, // 66 - 'B'
5, 255, 255, 129, 195, 195, // 67 - 'C'
5, 255, 255, 129, 255, 126, // 68 - 'D'
5, 255, 255, 137, 203, 195, // 69 - 'E'
5, 255, 255, 9, 11, 3, // 70 - 'F'
5, 255, 255, 129, 251, 251, // 71 - 'G'
5, 255, 255, 8, 255, 255, // 72 - 'H'
4, 129, 255, 255, 129, // 73 - 'I'
5, 224, 227, 129, 255, 255, // 74 - 'J'
5, 255, 255, 24, 255, 231, // 75 - 'K'
5, 255, 255, 128, 192, 192, // 76 - 'L'
5, 255, 254, 12, 254, 255, // 77 - 'M'
5, 255, 255, 3, 255, 255, // 78 - 'N'
5, 255, 255, 129, 255, 255, // 79 - 'O'
5, 255, 255, 9, 15, 15, // 80 - 'P'
5, 63, 63, 33, 255, 255, // 81 - 'Q'
5, 255, 255, 9, 255, 246, // 82 - 'R'
5, 207, 207, 137, 251, 251, // 83 - 'S'
6, 3, 1, 255, 255, 1, 3, // 84 - 'T'
5, 255, 255, 128, 255, 255, // 85 - 'U'
5, 63, 127, 192, 127, 63, // 86 - 'V'
6, 255, 127, 48, 48, 127, 255,// 87 - 'W'
5, 227, 247, 8, 247, 227, // 88 - 'X'
5, 207, 207, 136, 255, 255, // 89 - 'Y'
5, 227, 243, 153, 207, 199, // 90 - 'Z'

IMG_20200107_113721.jpg
0
sertanari
sertanari

Reply 4 months ago

i've done! added some extra "P.setFont(0, numeric7Seg);" in the code.. changed days and months in turkish.

/*Arduino Clock by AnthoTRONICS
* Last edit: December 21,2018
*/
// Libraries you'll need (Same as the ones in the guide):
// MD Parola: https://github.com/MajicDesigns/MD_Parola // click the link to download the library
// MD_MAX72XX: https://github.com/MajicDesigns/MD_MAX72XX//click the link to download the library
// DS3231: https://github.com/adafruit/RTClib
/*CODE:*/
// Header file includes
// These are for the matrix
#include <MD_Parola.h>
#include <MD_MAX72XX.h>
#include <SPI.h>
#include "Font_Data.h"
//These are for the clock
#include <DS3231.h>
#include <Wire.h>
DS3231 Clock;
bool Century=false;
bool h12;
bool PM;
byte dd,mm,yyy;
uint16_t h, m, s;
#define MAX_DEVICES 4 // Set the number of devices
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN A3
// Hardware SPI connection
MD_Parola P = MD_Parola(HARDWARE_TYPE,CS_PIN, MAX_DEVICES);
#define SPEED_TIME 75 // speed of the transition
#define PAUSE_TIME 0
#define MAX_MESG 20
// Global variables
char szTime[9]; // mm:ss\0
char szMesg[MAX_MESG+1] = "";
uint8_t degC[] = { 6, 3, 3, 56, 68, 68, 68 }; // Deg C
uint8_t degF[] = { 6, 3, 3, 124, 20, 20, 4 }; // Deg F
char *mon2str(uint8_t mon, char *psz, uint8_t len)
// Get a label from PROGMEM into a char array
{
static const __FlashStringHelper* str[] =
{
F("OCAK"), F("SUBAT"), F("MART"), F("NiSAN"),
F("MAYIS"), F("HAZiRAN"), F("TEMMUZ"), F("AGUSTOS"),
F("EYLUL"), F("EKiM"), F("KASIM"), F("ARALIK")
};
strncpy_P(psz, (const char PROGMEM *)str[mon-1], len);
psz[len] = '\0';
return(psz);
}
char *dow2str(uint8_t code, char *psz, uint8_t len)
{
static const __FlashStringHelper*str[] =
{
F("PAZARTESi"), F("SALI"), F("CARSAMBA"),
F("PERSEMBE"), F("CUMA"), F("CUMARTESi"),
F("PAZAR"), F("PAZARTESi")
};
strncpy_P(psz, (const char PROGMEM *)str[code-1], len);
psz[len] = '\0';
return(psz);
}
// Time Setup: Code for reading clock time
void getTime(char *psz, bool f = true)
{
s = Clock.getSecond();
m = Clock.getMinute();
h =Clock.getHour(h12,PM);//24HR Format
sprintf(psz, "%02d%c%02d", h, (f ? ':' : ' '), m);
//12hr Format
//uncomment if you want the clock to be in 12hr Format
/*if (Clock.getHour(h12,PM)>=13 || Clock.getHour(h12,PM)==0)
{
h = Clock.getHour(h12,PM) - 12;
}
else
{
h = Clock.getHour(h12,PM);
}*/
}
void getDate(char *psz)
// Date Setup: Code for reading clock date
{
char szBuf[10];
dd=Clock.getDate();
mm=Clock.getMonth(Century); //12
yyy=Clock.getYear();
sprintf(psz, "%d %s %04d",dd , mon2str(mm, szBuf, sizeof(szBuf)-1),(yyy + 2000));
//strcpy(szMesg, "29 Feb 2016");
}
void setup(void)
{
P.setFont(0, numeric7Seg);
P.begin(2);
P.setInvert(false); //we don't want to invert anything so it is set to false
Wire.begin();
P.setZone(0, MAX_DEVICES-4, MAX_DEVICES-1);
P.setZone(1, MAX_DEVICES-4, MAX_DEVICES-1);
P.displayZoneText(1, szTime, PA_CENTER, SPEED_TIME, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(0, szMesg, PA_CENTER, SPEED_TIME, 0,PA_PRINT , PA_NO_EFFECT);
P.addChar('$', degC);
P.addChar('&', degF);
}
void loop(void)
{
P.setFont(0, numeric7Seg);
static uint32_t lastTime = 0; // millis() memory
static uint8_t display = 0; // current display mode
static bool flasher = false; // seconds passing flasher
P.displayAnimate();
if (P.getZoneStatus(0))
{
switch (display)
{
case 0: // Temperature deg C
P.setFont(0, numeric7Seg);
P.setPause(0,1000);
P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_UP);
display++;
dtostrf(Clock.getTemperature(), 3, 1, szMesg);
strcat(szMesg, "$");
//strcat(szMesg, "26.5$");
break;
case 1: // Temperature deg F
P.setFont(0, numeric7Seg);
P.setTextEffect(0, PA_SCROLL_UP, PA_SCROLL_LEFT);
display++;
dtostrf((1.8 *Clock.getTemperature() )+32, 3, 1, szMesg);
strcat(szMesg, "&");
// strcpy(szMesg, "71.6&");
break;
case 2: // Clock
P.setFont(0, numeric7Seg);
P.setTextEffect(0, PA_PRINT, PA_NO_EFFECT);
//Sleep Mode
//Uncomment to enable Sleep Mode and adjust the hours to your needs
/*if (h==12 || h<8)//Time intervals (in this case, from 12AM to 8AM)
{
P.setIntensity(0); //Set display brightness to lowest setting
}
else
{
P.setIntensity(6); //Set display brightness to 6 (15 is the brighest)
}*/
P.setPause(0,0);
if (millis() - lastTime >= 1000)
{
lastTime = millis();
getTime(szMesg, flasher);
flasher = !flasher;
}
if(s==00&& s<=30){
display++;
P.setTextEffect(0, PA_PRINT, PA_WIPE_CURSOR);
}
// strcpy(szMesg, "36 % RH");
break;
case 3: // day of week
P.setFont(0,nullptr);
P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
display++;
dow2str(Clock.getDoW()+1, szMesg, MAX_MESG); // Added +1 to get correct DoW
//dow2str(5, szMesg, MAX_MESG);
break;
default: // Calendar
P.setFont(0,nullptr);
P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
display = 0;
getDate(szMesg);
break;
}
P.displayReset(0); //rest zone zero
}
}///////end of loop

0
wilcox
wilcox

Question 4 months ago


Please, someone knows how to set the clock an date?

2
sertanari
sertanari

Answer 4 months ago

i set the time and date with this code. then uploaded the clock code.
/*
https://somtips.com
https://youtube.com/somtips
*/
#include <RTClib.h>
#include <Wire.h>
RTC_DS3231 rtc;
char t[32];
void setup()
{
Serial.begin(9600);
Wire.begin();
rtc.begin();
rtc.adjust(DateTime(F(__DATE__),F(__TIME__)));
//rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
void loop()
{
DateTime now = rtc.now();
sprintf(t, "%02d:%02d:%02d %02d/%02d/%02d", now.hour(), now.minute(), now.second(), now.day(), now.month(), now.year());
Serial.print(F("Date/Time: "));
Serial.println(t);
delay(1000);
}

0
owahid96
owahid96

6 months ago

Hello there,
I've made this clock. And it works successfully.
I have a request. Can you please add a scrolling option in the code to scroll some text on the screen after showing temperature. Please! please!! please!!!

IMG_20190227_204218.jpgIMG_20190226_215910.jpgIMG_20190226_215919.jpg
0
anthias64
anthias64

1 year ago

Hello
Unfortunately I can't compile the code, I get this error

Arduino:1.8.9 (Windows Store 1.8.21.0)
(Windows 10), Scheda:"Arduino/Genuino Uno"
lto1.exe: internal compiler error: in
lto_output_varpool_node, at lto-cgraph.c:624
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html>;
for instructions.
lto-wrapper.exe: fatal error: C:\Program
Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\tools\avr/bin/avr-gcc
returned 1 exit status
compilation terminated.
c:/program files/windowsapps/arduinollc.arduinoide_1.8.21.0_x86__mdqgnx93n4wtt/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe:
error: lto-wrapper failed
collect2.exe: error: ld returned 1 exit
status
exit status 1

Have you any idea why ?
Thanks !!

0
RenéS79
RenéS79

Reply 8 months ago

its the version of the AVR. You can change it if you go to the Boardmanager select Arduino AVR Boards. Install the Version 1.6.21 in the Dropdown menue.

boardmanager.PNGVersion select.PNG
0
physiquebjbj
physiquebjbj

8 months ago

hi
how can fix this problem
error: 'numeric7Seg' was not declared in this scope

0
RenéS79
RenéS79

Reply 8 months ago

You must include the .h file found in the source code folder from git in one folder with the .ino file. Works for me.

Unbenannt.PNG