Using a LED matrix with Arduino

Rodrigo Sousa Coutinho
Arduino Playground
Published in
4 min readMar 1, 2017
A smile, and a lot of wires!

Got an 8x8 LED matrix such as the LBT2088AH that you want to connect to your Arduino? Here’s how it works:

The LED matrix. The numbers represent the pins

The matrix has 8 rows and 8 columns of LEDs, each with a pin you can connect to your Arduino. This means you have 16 pins to connect. And notice that the pin numbers bare no relation with the actual row or column… go figure!

Anyway, the idea is that you go trough each row of the matrix in turn and turn its pin to HIGH. So, if you wanted to set the LEDs on row 5, you’d set pin 1 to HIGH, and all other row pins to LOW.

Next, you select which columns you want to light up. The columns you want to light up should be set to LOW, while the ones you want off should be set to HIGH. So, if you wanted to light up column 3, you’d need to set pin 4 to LOW, while keeping the other column pins in HIGH.

Confusing, isn’t it? Anyway, let’s assemble this thing.

The circuit

The schematic for the circuit looks like this:

The schematic looks deceptively simple…

Lots of wires to assemble… and because the pins don’t really match the rows or columns at all, here’s the breadboard view to help you out. Note that I used a smaller breadboard as auxiliary support, since the LED matrix is too big to use a single breadboard.

The breadboard is a mess… Hopefully the colored wires help a bit!

The code

The full code looks like this:

If you run this in your Arduino with the circuit described above, you should see a nice smile!

Smile!

Let’s go trough what the code does:

The 1st line sets the character you want to show. Each number represents a row, and each number is a bit array with 1 for a connected LED and 0 for a disconnected LED. This means the 1st row (0x3c), which is binary 00111100, has two LEDs off, followed by 4 LEDs on, with 2 off LEDs to close the party. If you want to build your own character, head over to the character builder. With only a few clicks you'll build your own personal character.

The rest of the setup is all about defining the pins for rows and columns, and turning them into outputs — not very interesting, but needed.

The loop is where the fun begins. The first for iterates through each row. It’s immediately followed by another for loop to cleanup the columns. If you don’t do that, you’ll get some half glowing LEDs. Give it a go! Just comment that line and run the code again.

Next, we set the row to HIGH. From now on, each column we turn to LOW will turn on a LED on that row.

The following for loop iterates trough the columns. The idea behind the strange piece of code character[row] & 1 << col is to get a value that is true (anything other than zero) if the bit in the col position starting from the end is 1. If that's the case, that column is set to LOW, and therefore the LED lights up.

Next we delay for 1 millisecond to make sure the LEDs have enough time to light up. You can also play a bit with this: try to remove the delay, and you should see the 1st LEDs become dimer. If you set the delay to 300, you’ll be able to see rows being drawn one by one.

Finally we set the row pin to LOW, so we can start working on the next one.

You can download the full schematics and code from GitHub. It includes a couple of other characters for you to try.

--

--

Rodrigo Sousa Coutinho
Arduino Playground

Hi! I’m co-founder and Director of Data Science at OutSystems, with a passion for data, great products, and geeky stuff!