RGB LED Multiplexing Help

Hey everyone,

As a project for an engineering class we are required to use Arduino Uno boards to do various projects, my group and I are making a 4x4x4 LED cube. AS a modification we decided to use 10 mm diffused RGB common cathode LEDs purchased from evilmadscientist.com. We assembled the cube more or less following the instructions for the 4x4 cube by Hypnocube (http://www.hypnocube.com/Docs/HC4_Instructions.pdf). But we're having difficulty multiplexing the LED's; after completing the soldering we have 16 leads for each color (so 48 in total) and then 16 leads for the cathode/ground. There's only 20 pins on the Arduino board, the ground leads can all be connected so there's only one pin for ground but we're lost as to what to do for the colors. We don't really have enough time to take it apart and resolder into different wiring so it will have to stay as the HypnoCube design :fearful:. Are there chips we should use? If so, how do these work and what effect will they have on coding/wiring/resistance? Any help would be appreciated! XD

There's no schematic in those instructions, but looking at the PCB, it looks to me that it is organised as 4 layers of 16 leds. So you should indeed have 16 anode leads per colour, with each lead connected to 4 anodes of the same colour. However, after you have bundled the common cathode leads, there should be only 4 of them.

Think of each LED in the cube having coordinates (x, y, z) where each of x, y and z goes from 0 to 3. For each led, its (x, y) coordinate pair determines which 3 of the 16x3 anode connections it uses, and its z coordinate determines which of the 4 cathode connections it uses.

Each of the 4 cathode connections needs to be driven to ground by the collector of an NPN transistor, BC337 or similar (the emitter of that transistor is connected to ground). Only one of the 4 transistors will be turned on at a time. If there are enough pins left when you have dealt with the anodes, you can drive the base of each transistor from a separate pin via a series resistor (using 4 pins). Alternatively, use a 2-to-4 line decoder with active high outputs (e.g. 74HC238), then you only need 2 pins to drive it.

For the anode connections, you need one series resistor each (total 48 resistors), and you need to drive them active high. I suggest you check out the ShiftPWM library. If you select the series resistors to limit the current in each led to just under 9mA, you can drive the leds directly from the 75HC595s and stay within their ratings.

You may find it simpler to get just one layer working initially, by grounding the cathodes of that layer and leaving the cathodes of the other layers unconnected. Then use the ShiftPWM library and 6 74HC595s to drive the anodes. When you've got that layer working, then you can try adding multiplexing to get all 4 layers working.

Thank you for your description of how the cube LED alignment works in terms of x, y & z; it was very helpful! XD Also the info on the common cathode...thinking about it that makes perfect sense.
With regards to the transistors, we didn't plan on using them (I have very little electrical knowledge and we were assured by others we wouldnt need them...). Should we be using them? If so how would that work? As of now the only components we have is the Arduino Uno board, 4 LED panels soldered in the pattern shown on Hypnocube, resistors and 22-gauge wire....? We need help :frowning:

You definitely need some sort of driver for the columns. If you run the LEDs at 9mA each so that you can drive the anodes directly from the 74HC595s, then the maximum current for each of the 4 cathode blocks is 16 x 3 x 9 = 432mA. The Arduino is limited to 40mA per pin, so there is no way you can drive the cathodes directly. I suggest one BC337 transistor per cathode block. Connect the emitter to ground, the collector to the cathode block, and the base to the Arduino output pin through a 470 ohm resistor.

You will also need shift registers of some sort to drive the anodes, e.g. 6 x 74HC595. If you look at that Hypnocube board, you will see that is has several other ICs besides the PIC.

Thank you so much for your help! I think we'll get it to work now! Thank you! :smiley: :smiley:

One last question; from my understanding we need 4 transitors then (one for each cathode block) but how do the shift register work? Like how do the 6 hook up? Also will we need any other parts if we are using the transistors and shift registers?

I'm suggesting you use the shiftpwm library, see http://www.elcojacobs.com/shiftpwm/. You need to cascade the 6 shift registers so you can drive them all from the same Arduino pins. See http://www.arduino.cc/en/Tutorial/ShiftOut for how to connect the shift registers. It shows 2 shift registers, but you can generalise it to more. However, in your case, you are multiplexing the LEDs, so each of the 220 ohm resistors will go to one of the 48 LED anode blocks instead of to a single LED.

You should adjust the value of the 220 ohm resistors to get 9mA current. The red, green and blue LEDs will probably need different values, i.e. use one value for all the reds, a second value for all the greens and a third value for all the blues. Probably about 330 ohms for the reds and 220 or 270 ohms for the greens and blues. Try putting 5v across a LED, series resistor and current meter to detemine the correct value resistor for 9mA current.

PS - with only 9mA current, the LEDs aren't going to be all that bright, bearing in mind that each one will be on at most 1/4 of the time because of the multiplexing. If you wanted to run them at higher current, you would need either to use shift registers with higher output current capability, or to buffer each of the 48 outputs with a PNP transistor and series resistor. It looks like the Hypnocube probably uses 8x8 multiplexing instead of 16x4 multiplexing, which would make it even less bright - but they make up for it by driving the LEDs at higher current.