# LED Array Multiplexing & Charlieplexing With Your Arduino

So, are you finding the number of pins on your Arduino Board less than sufficient? If Yes, why not apply a technique of Multiplexing or Charlieplexing? You can get many work done with these techniques without purchasing a new board, and that too with the same amount of pins on them.

Multiplexing
Multiplexing is actually a very common way of driving LEDs, particularly when they are assembled as either a dot matrix display or more than one seven-segment display[SSD]. Multiplexing takes the advantage of this fact that if a light source is switched on and off fast enough [or blinked fast enough], the human eye perceives it as a continuous image, even though it is in fact only on for a very brief period.

 2 Seven Segment Display[SSD] Multiplexed by 9 Arduino Pins
The Above Diagram clearly shows that applying multiplexing technique in this problem, actually takes only 9 pins, where as in normal operation it would have taken 18 pins. So after this you will still have pins left for other works.

In order to display two different numbers on each seven segment display, we must use a procedure much like:

setup()
{
Declare all the pins as output pins, that are being in use
}
loop()
{

1. Pins 3 to 9 will be required for digit to form, write the desired data on them.
2. Turn Display 1 On by grounding the DI01 pin.
3. Apply a desired delay so the eye perceives the digit/character desired.
4. Turn Display 1 Off by ungrounding it.
5. Set different potential value on 3 to 9 pins as required for second digit/character to    appear.
6. Turn Display 2 On by grounding the DI02.
7. Apply a desired delay so the eye perceives the digit/character desired.
8. Turn Display 2 Off.
}

If we have given the delay small enough, the eye will perceives as we want it to, thus displaying two different characters on 2 different Seven Segment Displays.
In the above example, the duty cycle (ratio of “on” time to “off” time) for each display is 50%. For a four-digit display, it would be 25%. For 8 digit Display it would be 12.5%, and so on the duty cycle will decrease in the inverse proportion of the number of displays used.
Due to rapid blinking of the LED component, readily the life of the LED is reduced, to a much extent. And there is always a overshoot and a undershoot of the value of the current [as practical condition always differ from the ideal] , thus if this overshoot, surpasses the highest rated current capacity of the LED component for a while long, it will certainly burn/damage the devise or LED component.  So, LEDs must be connected with the current limiting resistors, typically there value lies between 300 to 500 ohms.

### Charlieplexing

Charlieplexing is a technique proposed in early 1995 by Charlie Allen for driving a multiplexed display which require a relatively few I/O pins of a MCU that is used to drive an array of LEDs.
The method uses tri-state logic capabilities of MCUs in order to gain efficiency over traditional multiplexing. Although it is more efficient in its use of I/O, but there are issues that cause it to be more complicated to design and render it nearly impractical for larger displays. These issues include duty cycle, current requirements and the forward voltages of the LEDs.
 2 pins Charlieplexed with 2 LEDs, In normal operation they would have required 4 pins
In the above arrangement in order to turn the LED1 on, we would make Output of DI01 High(or +5V), and Output of DI02 as Low (or ground). For LED2 we’d do the opposite: Output of DI01 as Low and Output of DI02 as High. To turn both LEDs on off state, we can either write the same value on them i.e, High or Low.

 3 Microntroller Pins are Charlieplexed with 6 LEDs, in normal operation it would have required 12 pins

In the above arrangement we drive six LEDs from just three pins by making use of Arduino digital IO (DIO) pins.
Referring to the above scheme, to drive LED1, we have to set DIO1 to be high, DIO2 to be  low [DIO1 & DIO2 both are output pins here], and DIO3 to be an input pin. LED2 would be turned on by DIO1 being set low, DIO2 being set high [DIO1 & DIO2 both are output pins here], DIO3 still being an input. For LED4 you have to set DIO1 to be an input, DIO2 to be low, and DIO3 to be high [DIO2 & DIO3 both are output pins here]. LED6 would call for DIO1 to be low, DIO2 to be an input, and DIO3 to be high, and so on. Careful and skillful programming will allow you to create a code that can turn on any LED as it is required.

You must be puzzeled by thinking why when LED6 is on, LED1 and LED3 aren’t, they’re even connected between the same pins & that too with the correct polarity. This puzzle is solved by understanding the forward voltage drop—there isn’t a high enough voltage drop across the two LEDs when connected in series to allow them to glow.

From this technique, the number of LEDs that you can drive from n pins is (n*n – n). For example, 6 Digital Input-Output pins yield 30 LEDs; 4 Digital Input-Output pins yield 42 LEDs; and so on.