# How to drive 30 LEDs with a smaller amount of pins?

We have 30 LEDs in a row, and we want to turn them on left to right. However there are way to many for the Arduino to have each one on a different pin.

Is there an IC that can take a binary output, and output in base 1?

• Base 1?! LOL. Actually stop and think about it. How would a number system work when the only digit you have is 0? Commented Dec 5, 2014 at 14:23
• If there isn't a binary to base 1 IC, it would seem like you could actually make one pretty easily, with a wire to ground and no inputs. Commented Dec 5, 2014 at 14:24
• @OlinLathrop: en.wikipedia.org/wiki/Unary_numeral_system Commented Dec 5, 2014 at 14:26
• There are 11 kinds of people in this world, @OlinLathrop. Those that understand unary numeral systems, and those who don't. Commented Dec 5, 2014 at 15:32

LEDs like that are commonly driven by shift registers. A shift register takes 3 inputs from the arduino (Data, Enable and Clock), takes a (for example) 8 bit number, then outputs it on 8 different pins. One example is like this: Shift Register 8-Bit - 74HC595

You really should dive into charlieplexing. With this technique it is possible to drive many leds with just a few pins. The formula is n x n-1. Meaning that with 4 pins you can drive 4 x (4-1) = 12 leds. Imagine that 12 leds with just 4 pins. With 5 pins you can therefore drive 5 x (5-1) = 20 leds.

With charlieplexing you can blink each of these leds individually or even have them burn all at the same time. It involves some really ingenious wiring and software, But there is a lot of documentation on that in the net. just search google for arduino and charlieplexing.

I made an hourglass with 20 leds just using an Attiny85 and a Larson scanner with 12 leds also using an Attiny85.

I am on the verge of writing a detailed series about charlieplexing on my website, but hey that will take a while. http://lucstechpage.weebly.com/

What you're looking for is a decoder or a multiplexer.

The right answer is a to take the the number of LEDS you have and call that the number of bits of storage you need. If you have 8 LEDs you need to interface to 8 bits of external storage. You then need to find an interface protocol with an equal number to or less amount of pins than you have. If you only have 3 external GPIO pins, you could go with the SPI interface, or the IIC interface.

Consider this part as a solution:

http://www.maximintegrated.com/en/products/interface/controllers-expanders/MAX7314.html

Okay, thermometer code. I don't know of any off-the-shelf decoders for that.

If you are into programmable logic, I think a single CPLD such as the XC2C64 could be programmed to drive (say) 50 LEDs with a 6-bit input. That gives you static drive.

An easier and cheaper way is to use multiplexed drive- drive 8 source drivers (UDN2803 or similar) with one port of your micro and 8 sink drivers (ULN2803) with another port. That will allow up to 256 LEDs to be driven with only 16 port pins, two chips and 8 resistors.

The source drivers may have to be MOSFETs or something else hefty, as they must conduct the average current of a single LED * 16 (with 12.5% duty cycle). The sink drivers must handle the average current of a single LED * 8 (but all of them may be on at once). Layout may be more convenient using a shift register and static drive- the matrix layout is better for a rectangle, not so good for a linear bar graph.