Digital Clock Project Using 8 Digit 7 Segment MAX7219 Module

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

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

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.

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

Share

    Recommendations

    • Halloween Contest 2018

      Halloween Contest 2018
    • Optics Contest

      Optics Contest
    • Plastics Contest

      Plastics Contest

    4 Discussions

    0
    None
    スサノオ

    8 months 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
    None
    MikeH133

    9 months 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);

    }

    }

    1 reply
    0
    None
    dheacockMikeH133

    Reply 8 months 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
    None
    MikeH133

    9 months 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!!!