Introduction: 8x8 Matrix Letter Game

I am trying to learn how to use the 8x8 matrix with Arduino and stumble across an article with using shift registers 74HC595N. So I thought to share my result, which subsequently being converted into a simple alphabet letter guessing game with just one button to trigger the random alphabet character to be displayed on the led matrix.

Step 1: Collecting All the Materials

For this project you will need the following:

- Arduino (any type will do, I am using UNO)

- 8x8 LED matrix, you can get one from here which is the Arduino Basic starter learning kit that includes the led matrix

- 74HC595N, this is included in the basic starter learning kit, or you can source it else where.

- Prototyping board, or some pcb breadboard and some cables and solder

Step 2: Connect the 8x8 LED Matrix to the 74HC595 Shift Register

The first picture shows how the 8x8 LED matrix is being configured, it is connected into rows and column, all the Anode of the LED in rows 1 is connected together in R1, all the Anode of LED in rows 2 is connected together to R2 and so on. The Cathode of all the LED in Column 1 is connected together through C1, cathode of all LED in column 2 is connected together through C2 and so on.

Thus to save the number of pin used we can use the shift registers 74HC595N, the way the shift register works is it allows the data to be latched. Looking at the second picture, shows how the shift registers work. The data gets into the shift registers via SER input PIN14, the SRCLK PIN11 is the serial clock which shift each data from serial input into each register. 74HC595N consists of 8 registers Q0 to Q7. Thus we will can shift up to 8 bits of data. Once all the data had been feed through the 8 registers, setting the RCLCK PIN 12 to HIGH will shift the data out to the LED Matrix, we do this one column at a time by controlling column via Arduino pin 6 to pin 13.

Arduino already have this function to be able to shift the data

shiftOut(dataPin, clockPin, bitOrder, value) // the value is expressed in Byte

So each display will require 8x8 bits (8 byte) of data.

Pin OE (output enable) of the 74HC595N needs to be connected to the ground, and SRCLR will need to be connected to 5V (Vcc).

Step 3: Test the Circuit by Connecting It to Arduino

Once the wiring of the LED and 74HC595 is complete, it is important to test it first to see whether all the connection had been done correctly by wiring it up to the Arduino as shown in the above picture. Don't forget to put 220 ohm resistor between each arduino output to each row to limit the current that goes through the LED.

You can use the following program to test the circuit, the program will display character "A", "B" and "R" for 1 seconds each and repeat.

int latchPin = 4; // pis connected to shift registors<br>int clockPin = 5;
int dataPin = 3;
int pins [8] = {6, 7, 8, 9, 10, 11, 12, 13}; // common cathode pins
byte A[8] = {   B00000000, // Letters are defined
                B00011000,// you can create your own
                B00100100,
                B01000010,
                B01111110,
                B01000010,
                B01000010,
                B00000000
            };
byte B[8] = {     B00000000,
                  B11111100,
                  B10000010,
                  B10000010,
                  B11111100,
                  B10000010,
                  B10000010,
                  B11111110
            };
byte blank[8] = { B00000000,
                  B00000000,
                  B00000000,
                  B00000000,
                  B00000000,
                  B00000000,
                  B00000000,
                  B00000000
                };
byte R[8] = {  B00000000,
               B01111000,
               B01000100,
               B01000100,
               B01111000,
               B01010000,
               B01001000,
               B01000100
            };
void setup() {
  Serial.begin(9600); // Serial begin
  pinMode(latchPin, OUTPUT); // Pin configuration
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  for (int i = 0; i < 8; i++) { // for loop is used to configure common cathodes
    pinMode(pins[i], OUTPUT);
    digitalWrite(pins[i], HIGH);
  }
}
void loop() {
  for (int k = 0; k < 1000; k++) { // showing each letter for 1 second
    display_char(A);
  }
  for (int k = 0; k < 1000; k++) {
    display_char(B);
  }
  for (int k = 0; k < 1000; k++) {
    display_char(R);
  }
 // add more letters show method here
}
void display_char(byte ch[8]) { // Method do the multiplexing
  for (int j = 0; j < 8; j++) {
    digitalWrite(latchPin, LOW);
    digitalWrite(pins[j], LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, ch[j]);
    digitalWrite(latchPin, HIGH);
    //delay(1);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, B00000000); // to get rid of flicker when
    digitalWrite(latchPin, HIGH);
    digitalWrite(pins[j], HIGH);
  }
}

Step 4: Connect the Button

Now that you get the test program working, that also means that you had done the wiring correctly, congratulations. To setup the alphabet game, we are going to connect a button from Arduino pin 2, to one side of the switch and also 10K resistor to GND, this will pull the LOW signal to the input pin 2. The other side of the switch should be connected to VCC (5V).

When the switch is pressed the reading from Arduino pin 2 will be high.

Step 5: Modify the Program to Be Able to Show All the Letters Randomly

Now it is time to modify the program to be able to show all the letter of the alphabet, and using random number generator function in Arduino library. To ensure that the number generated is random, we need to set the seed as shown below:

randomSeed(analogRead(0));

in the Setup() section of the Arduino code, this will ensure that the number generated using

random(1,26);

function is random, otherwise you will be getting the same sequence of numbers.

Now that we had the random number generated, it is time to map the number to the letters of the alphabet that we had create, for that I use the following function

void getChar(int num){<br>  switch (num){
    case 1: display_char(A); break;
    case 2: display_char(B); break;
    case 3: display_char(C); break;
    case 4: display_char(D); break;
    case 5: display_char(E);break;
    case 6: display_char(F);break;
    case 7: display_char(G);break;
    case 8: display_char(H);break;
    case 9: display_char(I);break;
    case 10: display_char(J);break;
    case 11: display_char(K);break;
    case 12: display_char(L);break;
    case 13: display_char(M);break;
    case 14: display_char(N);break;
    case 15: display_char(O);break;
    case 16: display_char(P);break;
    case 17: display_char(Q);break;
    case 18: display_char(R);break;
    case 19: display_char(S);break;
    case 20: display_char(T);break;
    case 21: display_char(U);break;
    case 22: display_char(V);break;
    case 23: display_char(W);break;
    case 24: display_char(X);break;
    case 25: display_char(Y);break;
    case 26: display_char(Z);break;
    default:
    break;
  }
}

I had attached the entire final Arduino program.

You can also find other electronics or computer related projects that you might be interested in on my website.

Step 6: Final Thoughts

The LED matrix can be expanded into other projects such as the following:

- Arduino Dice simulator: using the same LED matrix circuit and a small modification to the code

- Arduino Binary Clock: the detail build can be found in my website