Learning   Examples | Foundations | Hacking | Links

Examples > Display

Row-columm Scanning to control an 8x8 LED Matrix

LED displays are often packaged as matrixes of LEDs arranged in rows of common anodes and columns of common cathodes, or the reverse. Here's a typical example, and its schematic:

These can be very useful displays. To control a matrix, you connect both its rows and columns to your microcontroller. The columns are connected to the LEDs anodes (see Figure 1), so a column needs to be high for any of the LEDs in that column to turn on. The rows are connected to the LEDs cathodes, so the row needs to be low for an individual LED to turn on. If the row and the column are both high or both low, no voltage flows through the LED and it doesn’t turn on.

To control an individual LED, you set its column high and its row low. To control multiple LEDs in a row, you set the rows high, then take the column high, then set the lows row or high as appropriate; a low row will turn the corresponding LED on, and a high row will turn it off.

Although there are pre-made LED matrices, you can also make your own matrix from 64 LEDs, using the schematic as shown above.

It doesn’t matter which pins of the microcontroller you connect the rows and columns to, because you can assign things in software. Connected the pins in a way that makes wiring easiest. A typical layout is shown below.

Here's a matrix of the pin connections, based on the diagram above:

Matrix pin no.

Row

Column

Arduino pin number

1

5

-

13

2

7

-

12

3

-

2

11

4

-

3

10

5

8

-

16 (analog pin 2)

6

-

5

17 (analog pin 3)

7

6

-

18 (analog pin 4)

8

3

-

19 (analog pin 5)

9

1

-

2

10

-

4

3

11

-

6

4

12

4

-

5

13

-

1

6

14

2

-

7

15

-

7

8

16

-

8

9

Circuit

the 16 pins of the matrix are hooked up to 16 pins of the Arduino. Four of the analog pins are used as digital inputs 16 through 19. The order of the pins is assigned in two arrays in the code.

Two potentiometers control the movement of a lit LED in the matrix.

click the image to enlarge

image developed using Fritzing. For more circuit examples, see the Fritzing project page

Schematic:

click the image to enlarge.

Code

 
     
     
       
  

     
     

There is a more complex example in the Arduino playground. Other examples can be found on Tom Igoe's blog: