Skip to main content

Charlieplexing: Controlling 6 LEDs with 3 Pins

If you've heard of Arduino, you've heard of LED cubes. Apart from the appealing looks of the LED cubes, a very simple technique has been put to use in order to control a huge number of LEDs using limited pins on the Arduino.



Charlieplexing is the simple technique we are talking of in this article that helps you control a considerable number of LEDs using negligible number of pins.  It was first proposed in early 1995 by Charlie Allen at Maxim Integrated Products for driving a multiplexed display.


Using this method you can control n2−n LEDs using n pins on the Arduino, In other words you can control 6 LEDs using just 3 Pins.

This trick exploits the fact that LEDs are diodes and conduct electricity only in one direction.

Let's go through this in steps, understanding it as clearly as possible.


So lets say you've got 2 LEDs connected this way-


Port A and B are nothing but two digital pins on the Arduino, for instance digitalPins 3 and 4. Now, as you can see when Port A is HIGH and Port B is LOW, the upper LED lights up, while the LED below stays off (because LED's afte all are diodes that allow current to pass only in one direction).
So this way we can control 2 LEDs. 
NOW, lets introduce one more digital pin, say, Port C.
Just like what we did above, we can add two LED's between Port C and Port B
You already know how to turn on each of them.  
What are we achieving by doing so?
Lets connect the two pictures to get the holistic idea.
Great, we are now controlling four LEDs using 3 Pins. 

Wait a second. 
If we are setting one Pin HIGH and another pin LOW, the corresponding LED between them seems to light up, but what do we do with the third pin? 
We set the remaining pin not in use as an input (for eg- pinMode(pin5, INPUT); ). This makes makes the pin as good as it doesn't exist or in other words makes the pin act as an open connection hanging off the air.

Back to work, notice that we can add another two LEDs between Ports A and C?
This is it. You are now controlling 6 LEDs using just 3 pins.
Similarly you can go on adding more Ports to control more LEDs.
Now lets have a quick look at a code snippet-
Suppose, we want to turn on the the top most LED in the above schematic given that ports A,B and C are digital pins 3, 4 and 5 respectively on the Arduino-

pinMode(4, INPUT); // pin 4 has no use in turning on the LED that we want.

pinMode(3, OUTPUT); //Set pin 3 as OUTPUT
digitalWrite(3, LOW); // Use pin 3 as Ground

pinMode(5, OUTPUT); //Set pin 5 as OUTPUT
digitalWrite(5, HIGH); // Use pin5 as a 5V pin


That's the basic idea of Charlieplexing.
But, how do we turn on all the LEDs together?
Simple, make each LED blink with a short delay that will be almost as good as they are constantly on.

If you've understood everything up to here, you can set out to build projects involving multiple LEDs with fewer ports- However, you must rememberto add current limiting resistors!

Cheers!


  




Comments

Popular posts from this blog

Distortion Pedal Electronics (Explained for beginners!)

If you are into DIY guitar pedals and want to start designing your own effects, this article might help you open a few doors. I write this article as an EE student who earlier struggled with understanding these circuits and would often simply copy schematics off the internet. 

This article is intended for-
1. Absolute beginners who like tinkering with electronics
2. Anyone who has been learning analog circuits and is looking for a jumpstart project.

Also before I start I'd like to mention, for anyone who wants to get a rock-solid foundation in Analog electronics, I highly recommend reading the book, 'Electronic Principles' by AP Malvino and David Bates.

Distortion Pedals come in all flavors and sizes, however, how the distortion effect is achieved in any of the pedals is more or less similar. Let's first see how the output of the pedal compares to its input.

The raw signal coming from the guitar is first amplified a little, and then the peaks of the amplified signal are clip…

5 Effective Online Tools that will Spice up your Arduino Projects!

Arduino has made electronics projects easier than ever. The question now is- Can we make the process of building projects faster and more enjoyable? Let's have a look at some of the interesting softwares/online tools developed for the Maker Community to make tinkering more effective and documenting projects easier!

1. TinkerCad

TinkerCAD's recently created circuit simulator allows you to arrange your Arduino/Attiny circuits in an easy 'drag and drop' environment and test them virtually without having to make them. This can be really helpful, for testing projects that use components which you are yet to buy. And after all, who doesn't like tinkering?


Try out Tinkercad-Circuits here!

But that's not what Tinkercad is famous for. It offers an amazingly easy to use 3D design tool for Makers, once again in a simple 'Drag and Drop' interface! You can directly download the CAD file, once you're done designing. If you've ever thought of making your own uniqu…

TV Remote Controlled Servo Motor-Using Arduino!

Greetings!
We use our TV remotes to control the functions of the TV's, but when the TV is not in use, they're absolutely useless. Today, we are going to learn how to add more functionality to ordinary IR based remotes, in this one we shall see how to control servo motors. There are so many (SO MANY) different applications of this project that one can think of. Using the following tutorial, you can make one yourself!

1. Watch the video tutorial-


2. Things you will need-

Note that you may use a different IR receiver other than TSOP1738, if it isn't available. Usually you can find this on websites like amazon and ebay.
3. The circuit diagram!

4. The IR Remote Library http://z3t0.github.io/Arduino-IRremote/
5. The Arduino Code- Just copy paste this code into your Arduino IDE

// Written by Siddharth Kothari, curiousmotor.com// Enjoy your journey Exploring Arduino!#include <IRremote.h>#include <IRremoteInt.h>#include <Servo.h>intRECV_PIN=11;//IR receiver pinintgndIR=10;/…