LED 8×8 Matrix MAX7219-19 with Scrolling Text AND Android Control via Bluetooth

In this Arduino tutorial we will learn how to control 8×8 LED Matrix using the MAX7219 driver and the Arduino board. You can watch the following video or read the written tutorial below for more details.

Overview

We will make three examples, with the first one we will explain the basic working principle of the MAX7219 , in the second example we will see how the scrolling text on the 8×8 LED Matrix works, and in the third example we will control them via Bluetooth and a custom build Android application.

MAX7219



Now let’s take a closer look at the MAX7219 driver. The IC is capable of driving 64 individual LEDs while using only 3 wires for communication with the Arduino, and what’s more we can daisy chain multiple drivers and matrixes and still use the same 3 wires.
MAX7219 8x8 LED Matrix Driver
The 64 LEDs are driven by 16 output pins of the IC. The question now is how is that possible.  Well the maximum number of LEDs light up at the same time is actually eight. The LEDs are arranged as 8×8 set of rows and columns. So the MAX7219 activates each column for a very short period of time and at the same time it also drives each row. So by rapidly switching through the columns and rows the human eye will only notice a continuous light.
Note how the pins of a common 8×8 LED Matrix are internally arranged, so if you are building a matrix on your own you should consider it. Also note that a common breakout board for the MAX7219 comes with a resistor between the 5V and the IC pin number 18. The resistor is used for setting the brightness or the current flow to the LEDs.
MAX7219 Current Regulator Resistor
The following table from the datasheet of the IC shows the value of the resistor that we should use according to the forward voltage drop of our LEDs.
MAX7219 Segment Current vs Forward Voltage Drop Table from Datasheet

Circuit Schematic


Now let’s connect the 8×8 LED Matrix module to the Arduino Board. Here’s the circuit schematic:
8x8 LED Matrix MAX7219 Circuit Schematic
The VCC and GND of the module go to the 5V and GND pins of the Arduino and the three other pins, DIN, CLK and CS go to any digital pin of the Arduino board. If we want to connect more than one module we just connect the output pins of the previous breakout board to the input pins of the new module. Actually these pins are all the same except that the DOUT pin of the previous board goes to the DIN pin of the new board.
You can get the components needed for this Arduino Tutorial from the links below:
  • 8×8 LED MAX7219 Dot Matrix Module…… Amazon
  • HC-05 Bluetooth Module ……………………… Amazon
  • Arduino Board …………………………………….. Amazon
  • Breadboard and Jump Wires ………………… Amazon
*Please note: These are affiliate links. I may make a commission if you buy the components through these links.I would appreciate your support in this way!

Basic MAX7219 Arduino Code


Once we connect the modules we are ready to take a look at the Arduino code of the first example. We will use the MaxMatrix library which can be downloaded from GitHub.
  1. /*
  2. 8x8 LED Matrix MAX7219 Example 01
  3. by Dejan Nedelkovski, www.HowToMechatronics.com
  4. Based on the following library:
  5. GitHub | riyas-org/max7219 https://github.com/riyas-org/max7219
  6. */
  7. #include <MaxMatrix.h>
  8. int DIN = 7; // DIN pin of MAX7219 module
  9. int CLK = 6; // CLK pin of MAX7219 module
  10. int CS = 5; // CS pin of MAX7219 module
  11. int maxInUse = 1;
  12. MaxMatrix m(DIN, CS, CLK, maxInUse);
  13. char A[] = {4, 8,
  14. B01111110,
  15. B00010001,
  16. B00010001,
  17. B01111110,
  18. };
  19. char B[] = {4, 8,
  20. B01111111,
  21. B01001001,
  22. B01001001,
  23. B00110110,
  24. };
  25. char smile01[] = {8, 8,
  26. B00111100,
  27. B01000010,
  28. B10010101,
  29. B10100001,
  30. B10100001,
  31. B10010101,
  32. B01000010,
  33. B00111100
  34. };
  35. char smile02[] = {8, 8,
  36. B00111100,
  37. B01000010,
  38. B10010101,
  39. B10010001,
  40. B10010001,
  41. B10010101,
  42. B01000010,
  43. B00111100
  44. };
  45. char smile03[] = {8, 8,
  46. B00111100,
  47. B01000010,
  48. B10100101,
  49. B10010001,
  50. B10010001,
  51. B10100101,
  52. B01000010,
  53. B00111100
  54. };
  55. void setup() {
  56. m.init(); // MAX7219 initialization
  57. m.setIntensity(8); // initial led matrix intensity, 0-15
  58. }
  59. void loop() {
  60. // Seting the LEDs On or Off at x,y or row,column position
  61. m.setDot(6,2,true);
  62. delay(1000);
  63. m.setDot(6,3,true);
  64. delay(1000);
  65. m.clear(); // Clears the display
  66. for (int i=0; i<8; i++){
  67. m.setDot(i,i,true);
  68. delay(300);
  69. }
  70. m.clear();
  71. // Displaying the character at x,y (upper left corner of the character)
  72. m.writeSprite(2, 0, A);
  73. delay(1000);
  74. m.writeSprite(2, 0, B);
  75. delay(1000);
  76. m.writeSprite(0, 0, smile01);
  77. delay(1000);
  78. m.writeSprite(0, 0, smile02);
  79. delay(1000);
  80. m.writeSprite(0, 0, smile03);
  81. delay(1000);
  82. for (int i=0; i<8; i++){
  83. m.shiftLeft(false,false);
  84. delay(300);
  85. }
  86. m.clear();
  87. }
Description: So first we need to include the MaxMatrix.h library, define the pins to which the module is connected, set how many modules we use and define the MaxMatrix object.
For displaying characters we need to define them in an array of characters or bytes, and here I have several examples. We can notice how the bits are forming the characters which are actually zeros and ones. In this case they are rotated 90 degrees but the library example suggests to use them in such a way so that would be easier later to implement the shiftLeft custom function for scrolling a text.
In the setup section we just need to initialize the module and set the brightness of the LEDs. In the loop section using the setDot() function we can set any individual LED to light up at X, Y or Row/ Column position and using the clear() function we can clear the display.
8x8 LED Matrix Smile Character
For displaying the predefined characters we use the writeSprite() function, and first two arguments are the X and Y position of the upper left corner of character. At the end using the shiftLeft() function we move or scroll the character to the left.

8×8 LED Matrix Scrolling Arduino Code


Next let’s take a look at the scrolling text example and see what’s different. Below the code you will find its description.
  1. /*
  2. 8x8 LED Matrix MAX7219 Scrolling Text Example
  3. Based on the following library:
  4. GitHub | riyas-org/max7219 https://github.com/riyas-org/max7219
  5. */
  6. #include <MaxMatrix.h>
  7. #include <avr/pgmspace.h>
  8. PROGMEM const unsigned char CH[] = {
  9. 3, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // space
  10. 1, 8, B01011111, B00000000, B00000000, B00000000, B00000000, // !
  11. 3, 8, B00000011, B00000000, B00000011, B00000000, B00000000, // "
  12. 5, 8, B00010100, B00111110, B00010100, B00111110, B00010100, // #
  13. 4, 8, B00100100, B01101010, B00101011, B00010010, B00000000, // $
  14. 5, 8, B01100011, B00010011, B00001000, B01100100, B01100011, // %
  15. 5, 8, B00110110, B01001001, B01010110, B00100000, B01010000, // &
  16. 1, 8, B00000011, B00000000, B00000000, B00000000, B00000000, // '
  17. 3, 8, B00011100, B00100010, B01000001, B00000000, B00000000, // (
  18. 3, 8, B01000001, B00100010, B00011100, B00000000, B00000000, // )
  19. 5, 8, B00101000, B00011000, B00001110, B00011000, B00101000, // *
  20. 5, 8, B00001000, B00001000, B00111110, B00001000, B00001000, // +
  21. 2, 8, B10110000, B01110000, B00000000, B00000000, B00000000, // ,
  22. 4, 8, B00001000, B00001000, B00001000, B00001000, B00000000, // -
  23. 2, 8, B01100000, B01100000, B00000000, B00000000, B00000000, // .
  24. 4, 8, B01100000, B00011000, B00000110, B00000001, B00000000, // /
  25. 4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // 0
  26. 3, 8, B01000010, B01111111, B01000000, B00000000, B00000000, // 1
  27. 4, 8, B01100010, B01010001, B01001001, B01000110, B00000000, // 2
  28. 4, 8, B00100010, B01000001, B01001001, B00110110, B00000000, // 3
  29. 4, 8, B00011000, B00010100, B00010010, B01111111, B00000000, // 4
  30. 4, 8, B00100111, B01000101, B01000101, B00111001, B00000000, // 5
  31. 4, 8, B00111110, B01001001, B01001001, B00110000, B00000000, // 6
  32. 4, 8, B01100001, B00010001, B00001001, B00000111, B00000000, // 7
  33. 4, 8, B00110110, B01001001, B01001001, B00110110, B00000000, // 8
  34. 4, 8, B00000110, B01001001, B01001001, B00111110, B00000000, // 9
  35. 2, 8, B01010000, B00000000, B00000000, B00000000, B00000000, // :
  36. 2, 8, B10000000, B01010000, B00000000, B00000000, B00000000, // ;
  37. 3, 8, B00010000, B00101000, B01000100, B00000000, B00000000, // <
  38. 3, 8, B00010100, B00010100, B00010100, B00000000, B00000000, // =
  39. 3, 8, B01000100, B00101000, B00010000, B00000000, B00000000, // >
  40. 4, 8, B00000010, B01011001, B00001001, B00000110, B00000000, // ?
  41. 5, 8, B00111110, B01001001, B01010101, B01011101, B00001110, // @
  42. 4, 8, B01111110, B00010001, B00010001, B01111110, B00000000, // A
  43. 4, 8, B01111111, B01001001, B01001001, B00110110, B00000000, // B
  44. 4, 8, B00111110, B01000001, B01000001, B00100010, B00000000, // C
  45. 4, 8, B01111111, B01000001, B01000001, B00111110, B00000000, // D
  46. 4, 8, B01111111, B01001001, B01001001, B01000001, B00000000, // E
  47. 4, 8, B01111111, B00001001, B00001001, B00000001, B00000000, // F
  48. 4, 8, B00111110, B01000001, B01001001, B01111010, B00000000, // G
  49. 4, 8, B01111111, B00001000, B00001000, B01111111, B00000000, // H
  50. 3, 8, B01000001, B01111111, B01000001, B00000000, B00000000, // I
  51. 4, 8, B00110000, B01000000, B01000001, B00111111, B00000000, // J
  52. 4, 8, B01111111, B00001000, B00010100, B01100011, B00000000, // K
  53. 4, 8, B01111111, B01000000, B01000000, B01000000, B00000000, // L
  54. 5, 8, B01111111, B00000010, B00001100, B00000010, B01111111, // M
  55. 5, 8, B01111111, B00000100, B00001000, B00010000, B01111111, // N
  56. 4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // O
  57. 4, 8, B01111111, B00001001, B00001001, B00000110, B00000000, // P
  58. 4, 8, B00111110, B01000001, B01000001, B10111110, B00000000, // Q
  59. 4, 8, B01111111, B00001001, B00001001, B01110110, B00000000, // R
  60. 4, 8, B01000110, B01001001, B01001001, B00110010, B00000000, // S
  61. 5, 8, B00000001, B00000001, B01111111, B00000001, B00000001, // T
  62. 4, 8, B00111111, B01000000, B01000000, B00111111, B00000000, // U
  63. 5, 8, B00001111, B00110000, B01000000, B00110000, B00001111, // V
  64. 5, 8, B00111111, B01000000, B00111000, B01000000, B00111111, // W
  65. 5, 8, B01100011, B00010100, B00001000, B00010100, B01100011, // X
  66. 5, 8, B00000111, B00001000, B01110000, B00001000, B00000111, // Y
  67. 4, 8, B01100001, B01010001, B01001001, B01000111, B00000000, // Z
  68. 2, 8, B01111111, B01000001, B00000000, B00000000, B00000000, // [
  69. 4, 8, B00000001, B00000110, B00011000, B01100000, B00000000, // \ backslash
  70. 2, 8, B01000001, B01111111, B00000000, B00000000, B00000000, // ]
  71. 3, 8, B00000010, B00000001, B00000010, B00000000, B00000000, // hat
  72. 4, 8, B01000000, B01000000, B01000000, B01000000, B00000000, // _
  73. 2, 8, B00000001, B00000010, B00000000, B00000000, B00000000, // `
  74. 4, 8, B00100000, B01010100, B01010100, B01111000, B00000000, // a
  75. 4, 8, B01111111, B01000100, B01000100, B00111000, B00000000, // b
  76. 4, 8, B00111000, B01000100, B01000100, B00101000, B00000000, // c
  77. 4, 8, B00111000, B01000100, B01000100, B01111111, B00000000, // d
  78. 4, 8, B00111000, B01010100, B01010100, B00011000, B00000000, // e
  79. 3, 8, B00000100, B01111110, B00000101, B00000000, B00000000, // f
  80. 4, 8, B10011000, B10100100, B10100100, B01111000, B00000000, // g
  81. 4, 8, B01111111, B00000100, B00000100, B01111000, B00000000, // h
  82. 3, 8, B01000100, B01111101, B01000000, B00000000, B00000000, // i
  83. 4, 8, B01000000, B10000000, B10000100, B01111101, B00000000, // j
  84. 4, 8, B01111111, B00010000, B00101000, B01000100, B00000000, // k
  85. 3, 8, B01000001, B01111111, B01000000, B00000000, B00000000, // l
  86. 5, 8, B01111100, B00000100, B01111100, B00000100, B01111000, // m
  87. 4, 8, B01111100, B00000100, B00000100, B01111000, B00000000, // n
  88. 4, 8, B00111000, B01000100, B01000100, B00111000, B00000000, // o
  89. 4, 8, B11111100, B00100100, B00100100, B00011000, B00000000, // p
  90. 4, 8, B00011000, B00100100, B00100100, B11111100, B00000000, // q
  91. 4, 8, B01111100, B00001000, B00000100, B00000100, B00000000, // r
  92. 4, 8, B01001000, B01010100, B01010100, B00100100, B00000000, // s
  93. 3, 8, B00000100, B00111111, B01000100, B00000000, B00000000, // t
  94. 4, 8, B00111100, B01000000, B01000000, B01111100, B00000000, // u
  95. 5, 8, B00011100, B00100000, B01000000, B00100000, B00011100, // v
  96. 5, 8, B00111100, B01000000, B00111100, B01000000, B00111100, // w
  97. 5, 8, B01000100, B00101000, B00010000, B00101000, B01000100, // x
  98. 4, 8, B10011100, B10100000, B10100000, B01111100, B00000000, // y
  99. 3, 8, B01100100, B01010100, B01001100, B00000000, B00000000, // z
  100. 3, 8, B00001000, B00110110, B01000001, B00000000, B00000000, // {
  101. 1, 8, B01111111, B00000000, B00000000, B00000000, B00000000, // |
  102. 3, 8, B01000001, B00110110, B00001000, B00000000, B00000000, // }
  103. 4, 8, B00001000, B00000100, B00001000, B00000100, B00000000, // ~
  104. };
  105. int DIN = 7; // DIN pin of MAX7219 module
  106. int CLK = 6; // CLK pin of MAX7219 module
  107. int CS = 5; // CS pin of MAX7219 module
  108. int maxInUse = 2;
  109. MaxMatrix m(DIN, CS, CLK, maxInUse);
  110. byte buffer[10];
  111. char text[]= "HowToMechatronics.com "; // Scrolling text
  112. void setup() {
  113. m.init(); // module initialize
  114. m.setIntensity(15); // dot matix intensity 0-15
  115. }
  116. void loop() {
  117. printStringWithShift(text, 100); // (text, scrolling speed)
  118. }
  119. // Display=the extracted characters with scrolling
  120. void printCharWithShift(char c, int shift_speed) {
  121. if (c < 32) return;
  122. c -= 32;
  123. memcpy_P(buffer, CH + 7 * c, 7);
  124. m.writeSprite(32, 0, buffer);
  125. m.setColumn(32 + buffer[0], 0);
  126. for (int i = 0; i < buffer[0] + 1; i++)
  127. {
  128. delay(shift_speed);
  129. m.shiftLeft(false, false);
  130. }
  131. }
  132. // Extract the characters from the text string
  133. void printStringWithShift(char* s, int shift_speed) {
  134. while (*s != 0) {
  135. printCharWithShift(*s, shift_speed);
  136. s++;
  137. }
  138. }

Labels: Android, arduino Projects, LED Matrix

Thanks for reading LED 8×8 Matrix MAX7219-19 with Scrolling Text AND Android Control via Bluetooth. Please share...!

0 Comment for "LED 8×8 Matrix MAX7219-19 with Scrolling Text AND Android Control via Bluetooth"

Popular Posts

Back To Top