How to drive a lot of LEDs from a few microcontroller pins.

 by westfw
Featured
Using the fact that many microcontroller pins have three states (+V, GND, or
"high impedence", you can drive N*(N-1) LEDs from N pins. So the little 8
pin microcontroller like a PIC12Fxxx or an ATtiny11 can drive 20 LEDs on
its five available output pins, and still have one pin left for some kind of input.

See also http://www.instructables.com/id/Charlieplexing-LEDs--The-theory/
 
Remove these adsRemove these ads by Signing Up

Step 1: 20 LEDs on 5 pins

The current crop of low pin-count microcontrollers (6 pins to 20 pins on
the whole package) are attractively priced and 'cute', but the question
arrises as to how you can make the best use of those pins for common
applications such as driving LEDs.

A direct-connect approach to driving LEDs consumes one pin for each
LED. A traditional multiplexing scheme where rows of LED anodes are
driven by one set of N pins and each row's common cathode is driven by
another set of M pins manages to light N*M LEDs with N+M pins.
However, on a processor with only 5 or fewer outputs (as is the case
with most 8-pin microcontrollers), this barely gets you any more
outputs than direct drive.
1-40 of 55Next »
jalke116 says: Nov 24, 2011. 5:48 AM
good day!!! i just want to know of what are the software used for making schematics like in this instructable...

hoping for your answers...
panic mode in reply to jalke116Feb 12, 2012. 9:17 PM
Eagle is commercial product but there is free edition which has some restrictions of course (board size, number of layers etc.). There are open source alternatives like KiCad.
westfw (author) in reply to jalke116Nov 24, 2011. 2:08 PM
These were done using EAGLE from Cadsoft. http://www.cadsoftusa.com
bpark1000 says: Jan 2, 2012. 9:21 PM
You mention the trick of re-arranging the bits to make the circuit board simpler. Good plan! The way to do it easily is to first write the software as if the bits didn't need switching. Instead of writing the output byte directly to the port, you first write it to the index register. Then you use a "scramble table" to re-arrange the bits. You index into the table, then write that byte to the port. The advantage of this scheme is if you need to change the bit order, no change is needed to the code; only the table.

(I'm not familiar with this processor. My comments are based on the ability to do indexed addressing mode.  Index into a table. For example, for the "noadjust" routine, you would have:
TABLE: .byte 0b00100, 0b00010, 0b00001, 0b10000, 0b01000

copy TEMP to index register
load accumulator TABLE,index
copy accumulator to ANODE
...
You can have separate tables for the port and the direction register. The tables can be large (256 bytes for an 8-bit scramble function) without needing a compare for each value possible. The code becomes compact and easy to debug. You can stack tables. For example, one set to give the port/direction drives, and one to do the bit scrambling (used twice: once to scramble the port bits, again to scramble the direction bits)).

Table lookup is the key to fast processing!
weeladalah says: Nov 14, 2010. 11:24 PM
can i use Attiny13A instead of Attiny11...?? thanks :)
westfw (author) in reply to weeladalahNov 14, 2010. 11:55 PM
Yes; the same principles would apply with any 6-IO cpu...
awidarto says: Jan 4, 2010. 7:47 PM
This might be of interest :
http://www.edn.com/article/CA6666229.html?spacedesc=designideas&industryid=44217
the additional transistor should be able to source additional LED in series, at some additional cost though...
dedward says: Nov 22, 2008. 3:03 AM
Hiya, I'm really interested in how you've done this, and I would like to use the technique on a project I'm working on at the moment, which is a working model theatre. Does anyone know whether it is possible to have more than one LED on at once if they are connected through to the same pins?? Thank you!!! Dedward
Freeztech in reply to dedwardSep 3, 2009. 4:04 PM
You Can, Almost all Large LED displays use this Multiplexing Theory. Its in the code to have many lights on in the same row and column on at the same time. Sadly, I'm still working on learning that Part. but there are many resources out there that can help with the code
westfw (author) in reply to FreeztechSep 3, 2009. 4:41 PM
(after nearly a year of deep thought,) I think the problem with having more than one LED on at a time in a charlieplexed environment stems from using the microcontroller pins as both the current source and current sink for the LEDs. Most microcontrollers (old-school ones, anyway, like PICs and AVRs) can easilly source/sink enough current for ONE led (10-40mA), but if you start talking about a pin sinking the current for SEVERAL LEDs, you quickly run the risk of exceeding the maximum current specs.

In a traditional multiplexed environment it is easy to make the anodes and/or cathodes each have their own high-current drivers as needed, but it's much more difficult to do this with a connection that can be anode, OR cathode, OR off depending on circumstances (at least, without reaching a circuit complexity level that is the opposite of what we're trying to achieve by charlieplexing.)
akatsuki666 says: Feb 5, 2009. 4:56 PM
can you download it on the computer if so what websight?
westfw (author) in reply to akatsuki666Feb 5, 2009. 5:22 PM
What operating system are you using? And what AVR hardware? Did you actually build the PCB that was downloadable? While this code is a sample of how to do "Charlieplexing", it's certainly not an "easy to understand" thing for a beginner. You might want to look at This Instructable, which uses 6 outputs from an Arduino to drive 27 LEDs...
MultiViews in reply to westfwJul 2, 2009. 1:09 PM
Hi, i'm also kind of new to the arduino and multiplexing i know hom it works but the only thing i need help with is how i can send "GND" signals through the pins.? What do i need to write in the code to make it do that?
westfw (author) in reply to MultiViewsJul 2, 2009. 1:34 PM
In Arduino, "digitalWrite(pin, LOW);" outputs GND signals through that pin, for all practical purposes. (digitalWrite(pin, HIGH); sends +5, and "pinMode(pin, INPUT)" turns the pin off, mostly.)
MultiViews in reply to westfwJul 2, 2009. 2:25 PM
Thank you :D
akatsuki666 says: Feb 5, 2009. 3:01 PM
umm i tryied to download the file to my arduino microcontroller and it has a error for about everything u typed. why does it do that??????
westfw (author) in reply to akatsuki666Feb 5, 2009. 3:57 PM
Um. How exactly are you trying to "download" it? It's an assembler program rather the C or Arduino sketch, so it has an entirely different way that it needs to be built (and a different set of tools.)
akatsuki666 says: Jan 27, 2009. 5:42 AM
i kno im getting annoying.. but how do you ground the microcantroller?????????????
westfw (author) in reply to akatsuki666Jan 27, 2009. 7:33 AM
"GND" on circuits like this usually just means a common connection to the negative side of the power supply. (VCC or VDD being the positive side...)
akatsuki666 in reply to westfwJan 27, 2009. 3:33 PM
man you own lol. ty
akatsuki666 says: Jan 25, 2009. 7:11 PM
how u kno what resistors to use agin? umm
(total - led voltage)/ma = ohms??? if that is pls say or tell me the right 1
westfw (author) in reply to akatsuki666Jan 25, 2009. 9:03 PM
That looks right to me. There are lots of Intsructables/Tutorials/calculators about computing the LED resistances...
akatsuki666 says: Jan 24, 2009. 8:23 PM
hi its my first time too and im just wondering... what is the ma of a led???
westfw (author) in reply to akatsuki666Jan 25, 2009. 12:06 AM
Most common LEDs are spec'ed at up to 20mA or so (continuous.) In an arrangement like this, where each LED is only on for a fraction of the time, you can get away with higher currents, but the absolute max depends on the exact LED. There are "high power" LEDs that will take over 1A.
geeklord says: Aug 7, 2008. 4:14 PM
Hey im a 13 year old kid, and it looks like using a microcontroller would be a fun thing. Where the heck did most of u guys learn this stuff? Even if i knew how to just set up a microcontroller and just copy&pasted code would be nice
geeklord in reply to geeklordJan 12, 2009. 2:45 PM
thanks for all the comments. I'll probably get an arduino...
Zdawg in reply to geeklordJan 10, 2009. 6:56 AM
Boe Bot kitwhats a microcontrolerhi, im 13 also and i use microcontrolers for a ton of fun things, a great way to get a start is with a parallax, whats a microcontroler kit(my first kit), or a parralax Boe bot, which im still working on improving. for the most fun i woudl recoment getting the boe bot
chuck norris in reply to ZdawgFeb 26, 2009. 8:39 PM
I agree, Parallax Does an exellent job of teaching these kinds of techtronics. I started with the BASIC Stamp 2 Board Of Education kit and I can honestly say that every penny was worth it. I would definatly recommend buying the Boe-Bot kit if you are a fairly quick learner. All of Parallax's starter kits are definatly high-quality and the included textbook is really well-written (i.e, something that you can actually read without letting the ZzZzZs turn your book into a pillow.) One Kit can pretty much teach you all of the basic -level stuff, and from there you can buy other kits, or you can put some thought into design and make just about anythhing you can come up with. But i would recommend taking a computer science class to become more familiar with programming computers. Also, if you are unfamiliar with Java, computer sciences can help, if you are a seasoned veteran to programming, we have our own subspecies! Here it is:

Homo sapiens programmiens- A solitary, red-eyed mammal which often talks to inanimate objects.
True skills.JPG
westfw (author) in reply to ZdawgJan 10, 2009. 4:12 PM
See also http://www.instructables.com/id/How-to-choose-a-MicroController/
which discusses a number of strategies for starting with microcontrollers in some detail. It does include mention of the Parallax Basic Stamp, Arduino, and other "entry level" alternatives...
Zdawg in reply to ZdawgJan 10, 2009. 6:57 AM
they both use a BASIC Stamp microcontroler,
Zdawg in reply to ZdawgJan 10, 2009. 6:59 AM
and they both come with guides on how to program them with examples, and if u follow it u will be programing them in no time! there are also online codes and help and a discussion frum on the parralax website
Xellers in reply to geeklordSep 14, 2008. 7:51 AM
Buy an Arduino, and get the free software with example codes. Also, on their main website there are many tutorials and guides that help you learn.
westfw (author) in reply to geeklordAug 14, 2008. 6:59 PM
Take a look at the How to Choose a Microcontroller instructable. Be sure to read the comments; there's a lot of good data there as well as in the instructable itself.
ookid says: Dec 3, 2008. 6:51 PM
Kind of a newbie question but how do you open the eagle files in eagle?
westfw (author) in reply to ookidDec 3, 2008. 10:56 PM
Depending on your OS, you should be able to unzip to .brd and .sch files, and then just double-click them. Or use the "open" menu of eagle.
ookid in reply to westfwDec 4, 2008. 6:16 AM
thanks very much it worked like a charm
DT sleper says: Aug 12, 2008. 12:10 AM
Geeklord visit sparkfun.com and look at the picaxe microchips they are cheap, the software is free and they are easy to learn. Its a good place to start or look at parallax.com at their basic stamp it is also easy but more expensive. I haven't upgraded myself to more powerful chips yet because I am happy with the picaxe.
aiden120000 says: Jan 13, 2007. 3:05 PM
i wish i understood what this is talking about
dforsyth says: Jul 6, 2006. 10:46 AM
Did soemthing like this with a PIC. Made the 20th LED a IR, and put a push button and IR detector on it.
http://www.2dkits.com/zencart/index.php?main_page=product_info&products_id=6
westfw (author) in reply to dforsythJul 26, 2006. 12:42 AM
Ah, so you did the "blinkies"! I found them via a site about DuckCon and ordered five last christmas for the kids and family. Haven't put any together yet, though. Nice looking circuit and PCB. Very resonably priced, too...
1-40 of 55Next »
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!