Multiplexing is really cool. Put simply, it lets you control lots of LEDs with only a few wires. I’ve been doing quite a bit with multiplexing recently, but I haven’t found a nice simple introduction yet, so I wrote one.

 

Multiplexing is based on the fact that an LED is a diode, and diodes only let current flow in one direction. This can be annoying at times (if you install them the wrong way they don’t work, and they need DC power to run off), but can be quite advantageous at other times. Most LEDs won’t be damaged if you connect them backwards at a vaguely-sane voltage, they just won’t turn on.

For example, if we wanted to switch between two LEDs being on, normally you’d connect a wire to the positive legs of each of them, and connect the other legs to ground: a grand total of 3 wires.

Two LEDs connected to wires

However, because LEDs only conduct in one direction, it’s possible to do this with just 2 wires. The LEDs are connected across the wires with one in one direction, and one in the other., as shown in the diagram.

Two LEDs multiplexed together. This saves one whole wire!

If the blue wire is connected to -, and the red wire to +, the left-hand LED will light. If the blue wire is connected to + and the red to -, the right hand LED will light.

It’s even possible to get both LEDs to light, by very quickly switching from positive to negative on each wire. This relies on a phenomenon called persistence of vision – essentially, if you switch a light on and off fast enough, the eye is too slow at seeing the change, so the LED just seems as if its on. More on that later.

Similarly, the same can be done with 3 wires. In the diagram below, any one of the LEDs can be turned on independently, if the wires its connected to are connected to the right things. For example, to turn on the LED second from right, the red wire is set to positive and the purple to negative.

The more you spend, the more you save: 3 wires can be used to light 6 LEDs, saving 4 wires.

The blue wire is said to be ‘floating’ – it is in neither positive or negative states. This essentially means there is no voltage connected, so the only way there would be a current is through electromagnetism or charge, but we don’t need to worry about that here. Because it is unconnected, and has no voltage or current, the LEDs connected to it don’t light. The rightmost LED doesn’t light because it’s connected in reverse, so only the second-from-right LED lights up. Again, multiplexing could be used here to light any combination of LEDs.

Similarly, 4 LEDs can be used:

Yup, works for 12 LEDs too!

 

The diagram above shows what can be done with 4 wires. Here, we can start to see a pattern. With 2 wires, we could control 2 LEDs. With 3 wires, we could control 6 LEDs. For 4 wires, 12 LEDs.

We can calculate the number of LEDs you can light with a given combination using a formula: n x (n-1) . So if we had 100 wires, we could light 100 x 99 = 9,900LEDs. If we wanted to light 90 LEDs, rearranging and solving the equation gives n = 10, so 10 wires would be needed. 

Neat huh? This is most useful when using a microcontroller or Raspberry Pi – you can control far more LEDs with less pins than if you were doing them all individually, and you don’t have to use expensive addressable LEDs (like Neopixels), multiplexing only uses plain ol’ LEDs.

 

One of the biggest uses of multiplexing is for LED displays:

Flashy!

For this project, the LEDs were connected in a grid: the rows were the anodes of the LEDs and the columns were the cathodes. Consider a grid of LEDs, connected in numbered rows and alphabetic columns, like the one below.

An 8×8 grid of LEDs.

To turn on A2, we’d apply a voltage to row 2, and connect column A to ground. Simple right?

Yellow = grounded, blue = voltage, green = LED lit.

But if we wanted to turn on, say, A0 and H7, if we simply applied a voltage to rows 0 and 7, and grounded columns A and H, two more LEDs would light: A7 and H0.

Lighting 2 LEDs

Yellow = grounded, blue = voltage

So, the way around this is to very quickly scan through the rows faster than the eye can see, and light the desired LEDs in that row. When you scan through the rows quick enough, it looks like the desired LEDs are all on at the same time as the eye cannot detect the change.

Shift registers are often used to further reduce the number of microcontroller pins (they allow you to convert a single stream of serial data, to a number of streams of parallel data, so you only have to use one input signal to control a number of outputs) but that’s a story for another day! There are also chips designed specifically to do multiplexing and drive large numbers of LEDs.

Multiplexing is often used for most LED displays (the kind on the front of buses or at train stations). If you point your phone camera at the front of a bus, you sometimes won’t be able to read the screen, because the camera updates faster than the screen so you can see the lines being drawn.

This same principal can be used with other components too: for example, you could read from an 8×8 grid of buttons the same way.

There is lots more to multiplexing – but maybe I’ll cover that in a later post…..

 

Categories: engineering

Leave a Reply

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

Related Posts

engineering

Circuit Playground Countdown Timer

This Christmas I was fortunate enough to receive an Adafruit Circuit Playground Express (UK stockist link)- an all round (haha) fun experimentation/development board. It’s an awesome piece of kit (and a steal at £25). It’s got Read more…

engineering

Hacking the K40 Laser Cutter

A while back, Norwich Hackspace (of which I am a member) invested in a second hand K40 Laser Cutter – the sort that are pretty darn cheap (for a laser cutter anyway) on eBay and other Read more…

engineering

FallAlarm: a Progress Update….

If anyone reading this has chatted to me over the last half-year, you might be aware that I’ve been working on quite a big secret project – and no more is it secret! Inspired by Read more…