Digital Clock Project Using 8 Digit 7 Segment MAX7219 Module

Introduction: Digital Clock Project Using 8 Digit 7 Segment MAX7219 Module

About: Electronics Component - PCB [Design, Printing, Inserting] - Electronic Programming

8 Digit 7 Segment MAX7219 Module is an amalgamation of two pieces of 0.56" 4 Display 7 Segment Common Cathode Module which is mounted or arranged horizontally and controlled by MAX7219 driver. The advantages of this module is that it only takes 3 pins of I/O as a communication on arduino, so as to minimize the use of arduino I/O pins. This module can be applied to various projects that require character display, especially numeric characters, for example: Digital Clock Project.

Specification of 8 Digit 7 Segment MAX7219 Module:

  • Power Supply : 5VDC
  • Data Interface : SPI Serial (Din & Dout)
  • 7 Segment Color : Red
  • 7 Segment : 8 Digit
  • Driver : MAX7219

There are 5 Pins of Interface:

  • VCC : 5VDC
  • GND : 0V / Ground
  • DIN : Data IN / SDA / MOSI
  • CS : Shift / SS
  • CLK : Clock / SCK

DOUT allows you to add 7 Segment Module to the number as needed.

As we mentioned before, this module can be applied to -one of them- Digital Clock Project. Here is an example project to display time (hour, minute, and second) and date (day, month, and year) alternately.

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: Materials You Need

You will need:

  1. 8 Digit 7 Segment MAX7219 Module
  2. SFE Duino CH340
  3. RTC I2C DS1307 Module
  4. Male to Female Jumper Wires
  5. Male to Male Jumper Wires

Step 2: Setup

Connect 8 Digit 7 Segment MAX7219 Module, SFE Duino CH340, and RTC I2C DS1307 Module with jumper wires as schematic above or configuration pin below:

  • CLK = 2 SDA = A4
  • CS = 3 SCL = A5
  • DIN = 4 VCC = 5V
  • GND = 0V GND = 0V
  • VCC = 5V

Step 3: Code

First, download the library below. After that, input it on library of Arduino IDE.

Libraries

Insert the library on Arduino IDE sketch program. Enter the example of sketch below. Then upload the program.

#include <RTClib.h>
#include <LedControl.h>
//=======================================================================================
// data pin, clock, latch

double hold;

LedControl lc = LedControl(4, 2, 3, 1);
RTC_DS1307 rtc;

//========================================================================================

void setup() {
rtc.begin();
lc.shutdown(0, false);
lc.setIntensity(0, 8); // display brightness
lc.clearDisplay(0); // erase display
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); //set clock as computer clock
//rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));

}

//========================================================================================
void loop() {
hold = millis();
while ((hold + 20000) > millis() ) {
DateTime now = rtc.now();
setCol1(now.hour());
setCol2(now.minute());
setCol3(now.second());
lc.setChar (0, 2, '-', false);
lc.setChar (0, 5, '-', false);
}

hold = millis();
while ((hold + 5000) > millis() ) {
DateTime now = rtc.now();
setCol1(now.day());
setCol2(now.month());
setCol3(now.year() - 2000);
lc.setChar (0, 2, '-', false);
lc.setChar (0, 5, '-', false);
}

}

//========================================================================================
void setCol1 (byte jam) {
String strBuffer = Konversi(jam);
byte pjg = strBuffer.length() + 1;
char val[pjg];
strBuffer.toCharArray(val, pjg);
lc.setChar (0, 0, val[0], false);
lc.setChar (0, 1, val[1], false);
}

//========================================================================================
void setCol2 (byte mnt) {
String strBuffer = Konversi(mnt);
byte pjg = strBuffer.length() + 1;
char val[pjg];
strBuffer.toCharArray(val, pjg);
lc.setChar (0, 3, val[0], false);
lc.setChar (0, 4, val[1], false);
}

void setCol3 (byte dtk) {
String strBuffer = Konversi(dtk);
byte pjg = strBuffer.length() + 1;
char val[pjg];
strBuffer.toCharArray(val, pjg);
lc.setChar (0, 6, val[0], false);
lc.setChar (0, 7, val[1], false);
}

String Konversi(int nilai) {
if (nilai < 10) {
return "0" + String(nilai);
}
else {
return String(nilai);
}
}

Step 4: Try It!

After the program successfully uploaded, the 8 Digit 7 Segment Module will display clock display like the picture above.

It will display hours, minutes, and seconds for 20 seconds, then it will automatically change to display day, month, and year for 5 seconds, and so on.

Step 5: Check the Video to Know More

3 People Made This Project!

Recommendations

  • Backyard Contest

    Backyard Contest
  • Silly Hats Speed Challenge

    Silly Hats Speed Challenge
  • Arduino Contest 2020

    Arduino Contest 2020

9 Discussions

0
AndreBlueHawk
AndreBlueHawk

4 weeks ago

Here is the latest code with all the issues fixed and some updates:
P.S. I just created an account here to post this :)


#include <RTClib.h>
#include <LedControl.h>
//=======================================================================================
// data pin, clock, latch
double hold;
LedControl lc = LedControl(4, 2, 3, 1); //LedControl(DIN, CLK, CS, 1);
RTC_DS3231 rtc; //I used DS3231 instead of DS1307
//========================================================================================
void setup() {
rtc.begin();
lc.shutdown(0, false);
lc.setIntensity(0, 4); // display brightness (0..15)
lc.clearDisplay(0); // erase display
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); //set clock as computer clock
//rtc.adjust(DateTime(2020, 5, 2, 10, 00, 00));
}
//========================================================================================
void loop() {
hold = millis();
while ((hold + 20000) > millis() ) {
DateTime now = rtc.now();
setCol3(now.hour());// Display hour min second hh-mm-ss
setCol2(now.minute());
setCol1(now.second());
lc.setChar (0, 5, '-', false);
lc.setChar (0, 2, '-', false);
}
hold = millis();
while ((hold + 5000) > millis() ) {
DateTime now = rtc.now();
setCol3(now.month()); // Display US date format MM-DD-YY
setCol2(now.day());
setCol1(now.year()-2000);
lc.setChar (0, 5, '-', false);
lc.setChar (0, 2, '-', false);
}
}
//========================================================================================
void setCol1 (byte jam) {
String strBuffer = Konversi(jam);
byte pjg = strBuffer.length() + 1;
char val[pjg];
strBuffer.toCharArray(val, pjg);
lc.setChar (0, 1, val[0], false);
lc.setChar (0, 0, val[1], false);
}
//========================================================================================
void setCol2 (byte mnt) {
String strBuffer = Konversi(mnt);
byte pjg = strBuffer.length() + 1;
char val[pjg];
strBuffer.toCharArray(val, pjg);
lc.setChar (0, 4, val[0], false);
lc.setChar (0, 3, val[1], false);
}
void setCol3 (byte dtk) {
String strBuffer = Konversi(dtk);
byte pjg = strBuffer.length() + 1;
char val[pjg];
strBuffer.toCharArray(val, pjg);
lc.setChar (0, 7, val[0], false);
lc.setChar (0, 6, val[1], false);
}
String Konversi(int nilai) {
if (nilai < 10) {
return "0" + String(nilai);
}
else {
return String(nilai);
}
}

0
81zapper
81zapper

4 months ago

awesome job clock works great
any idea on how i could make it send a digital output every hour on the hour ?

0
AliL60
AliL60

5 months ago on Step 4

void loop() {
hold = millis();
while ((hold + 20000) > millis() ) {
DateTime now = rtc.now();
setCol1(now.hour());
setCol2(now.minute());
setCol3(now.second());
lc.setChar (0, 2, '-', false);
lc.setChar (0, 5, '-', false);
}

copy this while coment the original lines so you don't have to delete the lines from original code
this the whole code with the commented lines
#include <RTClib.h>
#include <LedControl.h>
//=======================================================================================
// data pin, clock, latch
double hold;
LedControl lc = LedControl(4, 2, 3, 1);
RTC_DS1307 rtc;
//========================================================================================
void setup() {
rtc.begin();
lc.shutdown(0, false);
lc.setIntensity(0, 8); // display brightness
lc.clearDisplay(0); // erase display
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); //set clock as computer clock
//rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
//========================================================================================
void loop() {
hold = millis();
while ((hold + 12000) > millis() ) {
DateTime now = rtc.now();
setCol1(now.hour());
setCol2(now.minute());
setCol3(now.second());
lc.setChar (0, 2, '-', false);
lc.setChar (0, 5, '-', false);
}
hold = millis();
while ((hold + 3000) > millis() ) {
DateTime now = rtc.now();
setCol1(now.day());
setCol2(now.month());
setCol3(now.year() - 2000);
lc.setChar (0, 2, '-', false);
lc.setChar (0, 5, '-', false);
}
}
/*void loop() {
hold = millis();
while ((hold + 20000) > millis() ) {
DateTime now = rtc.now();
setCol3(now.hour());
setCol2(now.minute());
setCol1(now.second());
lc.setChar (0, 5, '-', false);
lc.setChar (0, 2, '-', false);
}
hold = millis();
while ((hold + 5000) > millis() ) {
DateTime now = rtc.now();
setCol3(now.day());
setCol2(now.month());
setCol1(now.year() - 2000);
lc.setChar (0, 5, '-', false);
lc.setChar (0, 2, '-', false);
}
*/
//========================================================================================
/*
void setCol1 (byte jam) {
String strBuffer = Konversi(jam);
byte pjg = strBuffer.length() + 1;
char val[pjg];
strBuffer.toCharArray(val, pjg);
lc.setChar (0, 0, val[0], false);
lc.setChar (0, 1, val[1], false);
}
//========================================================================================
void setCol2 (byte mnt) {
String strBuffer = Konversi(mnt);
byte pjg = strBuffer.length() + 1;
char val[pjg];
strBuffer.toCharArray(val, pjg);
lc.setChar (0, 3, val[0], false);
lc.setChar (0, 4, val[1], false);
}
void setCol3 (byte dtk) {
String strBuffer = Konversi(dtk);
byte pjg = strBuffer.length() + 1;
char val[pjg];
strBuffer.toCharArray(val, pjg);
lc.setChar (0, 6, val[0], false);
lc.setChar (0, 7, val[1], false);
}
*/
void setCol3 (byte jam) {
String strBuffer = Konversi(jam);
byte pjg = strBuffer.length() + 1;
char val[pjg];
strBuffer.toCharArray(val, pjg);
lc.setChar (0, 1, val[0], false);
lc.setChar (0, 0, val[1], false);
}
//========================================================================================
void setCol2 (byte mnt) {
String strBuffer = Konversi(mnt);
byte pjg = strBuffer.length() + 1;
char val[pjg];
strBuffer.toCharArray(val, pjg);
lc.setChar (0, 4, val[0], false);
lc.setChar (0, 3, val[1], false);
}
void setCol1 (byte dtk) {
String strBuffer = Konversi(dtk);
byte pjg = strBuffer.length() + 1;
char val[pjg];
strBuffer.toCharArray(val, pjg);
lc.setChar (0, 7, val[0], false);
lc.setChar (0, 6, val[1], false);
}
String Konversi(int nilai) {
if (nilai < 10) {
return "0" + String(nilai);
}
else {
return String(nilai);
}
}

0
MikeH133
MikeH133

2 years ago

Update.... I have "solved" the time display issue but I cant make sense of the day month year bit so ive "remmed" it out for now..... here is the modified sketch

#include <RTClib.h>

#include <LedControl.h>

//=======================================================================================

// data pin, clock, latch

double hold;

LedControl lc = LedControl(4, 2, 3, 1);

RTC_DS1307 rtc;

//========================================================================================

void setup() {

rtc.begin();

lc.shutdown(0, false);

lc.setIntensity(0, 4); // display brightness

lc.clearDisplay(0); // erase display

//rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); //set clock as computer clock

//rtc.adjust(DateTime(2018, 1, 15, 16, 59, 00));

}

//========================================================================================

void loop() {

hold = millis();

while ((hold + 20000) > millis() ) {

DateTime now = rtc.now();

setCol1(now.second());//reversed hour min second

setCol2(now.minute());

setCol3(now.hour());

lc.setChar (0, 2, '-', false);

lc.setChar (0, 5, '-', false);

}

//hold = millis();

//while ((hold + 5000) > millis() ) {

//lc.setChar (0, 2, '-', false);

//lc.setChar (0, 5, '-', false);

//}

}

//========================================================================================

void setCol1 (byte jam) {

String strBuffer = Konversi(jam);

byte pjg = strBuffer.length() + 1;

char val[pjg];

strBuffer.toCharArray(val, pjg);

lc.setChar (0, 0, val[1], false);

lc.setChar (0, 1, val[0], false);

}

//========================================================================================

void setCol2 (byte mnt) {

String strBuffer = Konversi(mnt);

byte pjg = strBuffer.length() + 1;

char val[pjg];

strBuffer.toCharArray(val, pjg);

lc.setChar (0, 3, val[1], false);

lc.setChar (0, 4, val[0], false);

}

void setCol3 (byte dtk) {

String strBuffer = Konversi(dtk);

byte pjg = strBuffer.length() + 1;

char val[pjg];

strBuffer.toCharArray(val, pjg);

lc.setChar (0, 6, val[1], false);

lc.setChar (0, 7, val[0], false);

}

String Konversi(int nilai) {

if (nilai < 10) {

return "0" + String(nilai);

}

else {

return String(nilai);

}

}

0
dheacock
dheacock

Reply 2 years ago

In the "setCol1", "setCol2", and "setCol3" functions, I swapped out character position arguments in the lc.setChar functions (here's a code snippet):

void setCol1 (byte jam) {

String strBuffer = Konversi(jam);

byte pjg = strBuffer.length() + 1;

char val[pjg];

strBuffer.toCharArray(val, pjg);

lc.setChar (0, 1, val[0], false);

lc.setChar (0, 0, val[1], false);

}

//========================================================================================

void setCol2 (byte mnt) {

String strBuffer = Konversi(mnt);

byte pjg = strBuffer.length() + 1;

char val[pjg];

strBuffer.toCharArray(val, pjg);

lc.setChar (0, 4, val[0], false);

lc.setChar (0, 3, val[1], false);

}

void setCol3 (byte dtk) {

String strBuffer = Konversi(dtk);

byte pjg = strBuffer.length() + 1;

char val[pjg];

strBuffer.toCharArray(val, pjg);

lc.setChar (0, 7, val[0], false);

lc.setChar (0, 6, val[1], false);

}

That seems to fix the digit order issue I was having, which I believe was similar to yours.

Regards, Doug

0
subroto
subroto

Reply 5 months ago

You also have to do these changes as attached with respect to the actual code

void loop() {
hold = millis();
while ((hold + 20000) > millis() ) {
DateTime now = rtc.now();
setCol3(now.hour());
setCol2(now.minute());
setCol1(now.second());
lc.setChar (0, 5, '-', false);
lc.setChar (0, 2, '-', false);
}
hold = millis();
while ((hold + 5000) > millis() ) {
DateTime now = rtc.now();
setCol3(now.day());
setCol2(now.month());
setCol1(now.year() - 2000);
lc.setChar (0, 5, '-', false);
lc.setChar (0, 2, '-', false);
}

0
pelajar
pelajar

1 year ago on Step 5

terima kasih ilmunya gan, moga kedepannya ada pembelajaran juga dalam menggabungkan 7Segment dengan dot matrix(7219) dalam 1 coding

0
スサノオ
スサノオ

2 years ago

Thanks a lot for the code. It helped a lot. Is there any way I can change the 24 hour clock to 12 hour? Thanks in advance. :)

0
MikeH133
MikeH133

2 years ago

Hi,

Ive copied this project and have a problem...

the clock reads backwards ie if 10-20-30 displays it means 01 second 02 mins 03 hours. The first digit increments the seconds and the increases ripple across to the other digits from left to right.

The date does the same so as per today's date 81-10-51 should be 15-01-18

im struggling with the sting manipulation to correct this and don't know why it is happening!

any help would be appreciated please!!!