Posted on

Shared Anodes and Cathodes

shared anodes and cathodes preview

Shared anodes and cathodes are a common technique used to control lots of LEDs with a small number of microcontroller pins.  I’m going to talk about why share anodes and/or cathodes.  Then I’ll show an example of shared anodes, an example of shared cathodes, and finally combine the two for some more impressive results.

Why share anodes and cathodes?

It scales really well.  If there are no shared anodes and cathodes then to independently control N number of lights then you need at least N+1 anodes and cathodes.  If there are shared anodes and cathodes then you need A anodes * B cathodes to run N LEDs.  So for…

…16 lights you need 4 anodes and 4 cathodes.

…25 lights you need 5 anodes and 5 cathodes.

…256 lights you need 8 anodes and 8 cathodes.

…512 lights you need 8 anodes and 16 cathodes.  (or 16 and 8, it’s your call.)

…17 lights you need 4 anodes and 5 cathodes.  There will be some anode/cathode combinations with results I can’t predict.

Wiring the shared anodes and cathodes together

shared anodes and cathodes schematic

It occurs to me that in the video I put the resistors on the anodes.  It makes no difference.  As long as they are there to keep the LEDs safe, it doesn’t matter if they are before or after the LEDs.

Also please note the potentiometer in the bottom left corner of the schematic.  I’m going to use the value from this potentiometer to change the behavior of the Arduino sketch.

Code

I’ve include two sketches in the shared anodes and cathodes github project.

SharedAnodesAndCathodesA.ino will run either (a) four LEDs with shared anodes or (b) four LEDs with shared cathodes.  The code is the same, the effect is exactly the opposite.

SharedAnodesAndCathodesB.ino will run 16 LEDs with four shared anodes and four shared cathodes, as described in the wiring diagram above and the video below.  Speaking of which…

Video

Printed circuit board

I’ve designed an arduino shield that cleans up all the wiring in the 16 LED demo.  If you’re interested in having one (or more!) comment below and we’ll make it work.

ELEC-0124 3d ELEC-0124 flat

Final thoughts

RGB LEDs have four legs.  Typically the long leg is the cathode and the three shorter legs are the red, green, and blue anodes.  very quickly cycling between the three anodes will create many different hues.

This is a perfect case for using a shift register.  Try it yourself!

Expand this idea far enough and you can build large displays.  The very early classic Hercules monitors had gold and black colors in 720×350 resolution.  1080 anodes and cathodes?  Easy! 😉

See Also

Leave a Reply

Your email address will not be published. Required fields are marked *