How to Build a 8×8 RGB LED Matrix with PWM using an Arduino
A while ago I designed a circuit that would power an 8×8 RGB LED Matrix (192 LEDs in all) using only 3 pins from an Arduino Diecimila and supporting Pulse Width Modulation. I’ve uploaded some videos of this project on Youtube and folks have been emailing me with questions on how it works. In this post I’ll try to answer all those questions so you can build your own.
I started with the LED Matrix component itself. I used an RGB 8×8 common anode matrix from LedSee (only $10 on ebay). The matrix takes 32 pins: 8 anodes, 8 cathodes for Red, 8 for Green and 8 for Blue. Then I had an arduino Diecimila which was about $25 I think but you can use any ATMega based board.
A little googling revealed that a thing called a Shift Register could help me drive all those 32 pins using just a couple from the arduino. Shift Registers are cheap and easy to source. I used the 74HC595 IC.
The arduino website has a tutorial on Shift Registers which can be found here: http://www.arduino.cc/en/Tutorial/ShiftOut. This explains what they are, how they work, the clock, latch and data pins as well as how to chain them together.
After a few evenings of experimentation I knew I could drive 8 pins per 74HC595 chip. If I chained enough together I could drive all 32 pins. So I was set.
Next I drew up the schematic on paper. I played with a few prototypes using Breadboard until I had confidence that the circuit would work. This was a smart move as it turned out there was a problem. I found through experimentation that the Red LEDs were overpowering the Green and the Blue. I couldn’t figure it out since the code treated them all as equals. I went back to the reference manual for the LED matrix and found that the operating voltage of the RED LEDs in the matrix is actually lower than the Blue or Green.
I was able to even them out by introducing a higher resistor (330) into the RED cathodes than is in line with the blue and green (220 ohms). That was a true moment of enlightenment.
There’s a lot of wires so I put it into Visio. Here’s the result:

The blue, green and yellow lines go to the Arduino.
Next up I worked on the code. Besides turning the LEDs on and off I wanted to actually get different colors. I had no idea how to do this but it turned out Robert aka “MadWorm” had already figured it out: [LINK]. My code is essentially based entirely off of Robert’s so I won’t complicate or confuse you with my own extensions.
To better understand the ISR business, I’ll refer you this time to ucHobby [LINK]
The arduino supports an interrupt which is essentially a routine that runs in the the background, almost like a separate thread, from your code. This interrupt is what updates the Matrix pins and it happens very very fast. Even better is that it frees up the main loop of your Arduino sketch to do the interesting stuff like update the actual matrix data.
Pulse Width Modulation or PWM is essentially a way of simulating an analog output from a binary source. Huh? Wha?
If I turn on a Red LED I get red, if I turn on a Blue LED I get blue. If I turn them on both at the same time I get purple. What if I want to get some color in between? with this type of system you can’t get anything but 7 colors (R, G, B, RG, RB, GB, RGB). The only way is to turn on the LEDs partially. But an LED can only be fully on or fully off, how can you get a “partial” LED? The answer is PWM.
Pulse Width Modulation varies the time for which an LED is active. It’s still either fully on or fully off during that time, but if you think of that time as a wave, the “width” of the “pulse” during which the LED is active varies. Here’s a good visual:
![]()
The result is an ability to “mix” colors by different degrees and get a far wider range than the 7 possible combinations of RGB. The good news is this is all implemented within Robert’s ISR code above.
So I soldered away busily for three nights and in the end I had a nice little circuit board. Definitely not as small as it could be but good enough for a RevA.
At this point I had everything working nicely so I built simple case of Cherry/Lexan and four hex-head bolts to finish up.
That’s basically it! You can checkout the pictures below or find the video on Youtube. I had a lot of fun making this thing. It sits proudly on my desk today and although many have tried, no one can resist asking “what is that thing”.
The PWM is very tough to videotape but take a peek at the pics. Here’s my daughter playing with the prototype:








[...] More information here>> [...]
[...] selvittelemään mitä kaikkea tarvitsisin ja mitä osat tulisivat maksamaan. Franciss Hanahanin blogista löysin ohjeet kuinka tehdä rgb led matriisille ohjain. Ohjaimena käytetään Arduino [...]
Hi Francis, i was wondering, it wasn’t necessary an external boost power supply for the leds, like transistors? or just with the arduino
Thanks
Good question. I multi-plexed them so there’s only 1 on at a given time. It’s so fast the eye can’t tell. Otherwise yes I would’ve had to boost the power with some transistors.
Can you explain what code did you use. I think that Robert’s code is for Arduino, is it? What code is used in Proseccing to control the Arduino?
I don’t understand how an 8×8 matrix equals 192 LEDs. Last I checked 8×8 was 64.
Simple @Scott. RGB LEDs have 3 anodes and one cathode (or vice versa). They act like 3 LEDs in one.
8 x 8 x 3 = 192
@Lauri : You’re right, Rob’s code is for the arduino. For Processing I wrote a simple app based on the example serial port code on the Processing 1.0 site. This works nicely with similar code found on the Arduino.cc website. There’s really nothing to it and I’d encourage you to check the examples which are very clear on the respective websites. Hope that helps.
hi there
i m doing a interactive project which need things like this
would you pls show me the arduino code?
i used to made a 8×8 sing color leds panel, but i don’t know how to make another one in the scanning way.
will be very appreciate!
luke
Hello again Francis
Wich pins of the arduino did you use to connect the data, clock and latch from the 74hc595?
That’s all, thanks
Hi, I am in the process of building this project , got all the parts ordered from ebay and plan to have this working in about 2 weeks. But i see one problem that doesent make sense. In the schematic you have posted you show one shift register controlling only the green leds, another controlling the red, and another controlling the blue leds. Even the resistors are laid out the same way , the problem is that the 8×8 matrix ’s are not laid out that way, at least the ones i have found or even the one you say you used in the project description, won’t the circuit need to be completely redesigned or am i missing something here?
@Robotjam; I’m not sure what LED matrix you’re using, mine was laid out as is drawn in the schematic. The shift registers were chained together, I used 4, one for Red, Green, Blue and a fourth for the anodes (it was a common anode display). The schematic is correct and you can check the arduino.cc forums as a group of folks have made an Eagle sketch with really nice PCBs based on it. Hope that helps,
-fs
Not really but thanks anyway
@Robotjam, could you post the link to the datasheet of the LED matrix you’re using? I’ll try to dig up same from the one I used.
Looks like LedSee is no longer selling them but there are a couple of other suppliers on ebay. I used one like this:
http://gzwg.blogspot.com/2009/09/60×60mm-8×8-rgb-led-matrix.html
The datasheet shows the internal wiring but you can see from the photo the pins are arranged to match what I have in the schematic. Hope that helps,
-fs
Here is a link to the exact one i bought on ebay, sorry it is so long.
Looks exactly like the one you just posted.
http://cgi.ebay.com/8-8-60-60mm-RGB-Full-Color-Dot-Matrix-LED-Display_W0QQitemZ250526948971QQcmdZViewItemQQptZLH_DefaultDomain_0?hash=item3a5491de6b
If its the same as yours what am i not understanding?
@Robotjam – You tell me
What made you originally think the circuit needs to be redesigned? I think looking at the diagram that the pin layout is the same as mine, the number in the circle refers to the pin, notice 17,18,19,20 then skips 8 (green) and jumps to 29, 30 etc. Using that diagram you can figure out which pins light which leds but you can easily test it when you get it, wire up a cathode and an anode and see which LED lights up.
It is that your layout board has a separate red section, separate green section and a separate blue section. It was my understanding that the pin layout of these things is R/G/B, R/G/B, R/G/B not R/R/R/…, G/G/G/…, B/B/B… Does that help you understand what i am not understanding?
Got it. So that’s incorrect, the pin layout is as per the datasheet on the page you linked to, pins 1-8 map to cathodes for blue, pins 9-16 map to cathodes for red, 17-20 map to anodes, 21-28 map to cathodes for green, 29-32 are anodes. Hope that helps,
-fs
Yes it does, Thank you, sorry for taking up your time like that
hello francis
I made this with independent leds in order to do a rgb table. I already tested it and it works!, but the animations are limited, i not able to see the smile or the explode, only the rainbow, and the disco lights, there is something that i have to do on the code to activate them? i don’t think that i had bad connections cause i’m able to see some animations and all the leds are working. Another thing, reading your issue about the resistor, a funny thing happens to me. I have 68 ohms for blue, 100 ohms for red and 120 ohms for red. The green and blue are ruling in the matrix, you can barely notice the red color. But if i put the values that you used, the red color is going to be with more intensity difference, i’m confussed. sorry about the english.
Thanks for your help,
Hello Francis, I was wondering what power supply you would recommend, also in a privious post someone mentions the program called Processing. do I (we) need that to get this programmed or will the Arduino program be sufficiant. And lastly (sorry to ask so many questions) I am planning on giving a couple of these things out as Christmas ornaments so in order to keep cost and size down would a Really Bare Bones Board (RBBB) http://www.moderndevice.com/products/rbbb-kit
work instead of a larger and more expensive Arduino board?
Thank you for your help, this project is awesome.
How many LEDs can you control this way? 8×8/8×16/16×16/16×24/24×24/24×32/32×32 Which is the limit? Or maybe I could control more if I use more shift registers?
@FCsabi – well you get 8 pins per shift register but at some point you’ll run out of Hz and things will slow down (need a faster PIC or multiple in parallel).
Your schematic shows that you need only 3 pins from the Arduino to drive 64 LEDs.If I multiply this by 4 I get 12 digital pins to use (64×4 = 256 LEDs).I think the Arduino Duemilanove has more than 12 pins.
Am I wrong?
Thanks for the reply for my other message
@FCsabi – The pins are the data, clock and latch for the shift registers, 3 pins total. The output of the shift registers is what drives the LEDs and there are 192 in total. 8×8 red, 8×8 green and 8×8 blue. Each arranged in an 8×8 grid.
The LEDs are multiplexed in the matrix and they share a common cathode to 8 Red anodes, 8 Green anodes, 8 Blue anodes and 8 cathodes, hence 4 registers.
Thanks for answering my questions.
.
Now I understand it.The problem is I wanted to make an RGB LED display that shows realtime image from a computer with at least 16×16 resolution or more if possible.The programming is quite easy , I programmed a lot in C++ and C# before.I could buy RGB LEDs from online stores that are the same like yours.The ones that have 3 cathodes for each color and 1 anode.I could build myself the RGB matrix using some tutorials and your schematic to control all of them and its PWM. If there is a way to control more RGB LEDs using the Arduino, please tell me. It would be impossible for me to make a led screen using only 8×8 grid matrixes and an Arduino to control each one.:(
If I manage to finnish my project you will be included in the credits.
@FCsabi – 16×16 is a lot of LEDs. for RGB that’s 768 total and you may run out of clock speed to multiplex these all fast enough, but might be possible, give it a try I guess.
I know folks have done what you’re talking about and you can find a lot of videos of same on Youtube but most use different PICs than the Atmega.
You might also consider an LCD display, which has higher resolution, smaller form factor and you can find ready-made boards on Sparkfun. These are way smaller (usually 1.5″ square) than this thing though.
Sounds like a fun project, good luck with it, and post back a link when you get done building!
-fs
Francis, that is nice work there. I am going to implement some of these ideas for a college project. I am hoping to output to my own array of RGB LEDs. Do you know how to implement this. Is it so that say all the red legs on the different rows are joined together in the same why its done on multiplexing?
@Matt, thanks! I’m a novice so I might get this wrong but basically multiplexing is basically setting some pins high and others low so you end up with a single LED lit at a given time. By this means you can isolate a single LED in the matrix and turn it on, even though it’s connected to it’s neighbours. Do it fast enough and you end up with what looks like two or more LEDs on at the same time. There are some good tuts on the interweb that explain it pretty well if you go looking. Hope that helps.
Leave your response!
Tags
Recent Comments
Archives
What I'm Doing...
Blogroll
Recent Posts
Categories
Recent Posts
Most Commented
Meta