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:

LEDmatrix img

LEDmatrix schem

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 cathodes (see Figure 1), so a column needs to be LOW for any of the LEDs in that column to turn on. The rows are connected to the LEDs anodes, so the row needs to be HIGH 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 doesnt turn on.

To control an individual LED, you set its column LOW and its row HIGH. To control multiple LEDs in a row, you set the row HIGH, then take the column high, then set the columns LOW or HIGH as appropriate; a LOW column will turn the corresponding LED ON, and a HIGH column will turn it off.

Tip - Pins set to OUTPUT by use of the PinMode command are set to LOW if not otherwise stated

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

It doesnt 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.RowColumnArduino pin number
15-13
27-12
3-211
4-310
58-16 (analog pin 2)
6-517 (analog pin 3)
76-18 (analog pin 4)
83-19 (analog pin 5)
91-2
10-43
11-64
124-5
13-16
142-7
15-78
16-89

Hardware Required

  • Arduino or Genuino Board

  • 8 x 8 LED Matrix

  • 2 10k ohm potentiometers

  • hook-up wires

  • breadboard

Circuit

The 16 pins of the matrix are hooked up to 16 pins of the Arduino or Genuino board. 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, connected to analog pins 0 and 1, control the movement of a lit LED in the matrix.

click the image to enlarge

rowColScan bb

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

Schematic

click the image to enlarge.

rowColScan schem

Code

See Also

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

Last revision 2015/07/29 by SM