Electronic – How to control 8 LEDs using only 5 pins of a microcontroller

circuitsmicrocontrollermultiplexer

How can I control 8 LEDs using only 5 pins of a microcontroller without using any shift registers or I/O expanders?

By "controlling" I mean turning an LED or a set of LEDs on or off, not just turning one only at a time like Charlieplexing.

Edited : This query had a boundary of not using any devices or ICs other than the microcontroller, any possible number and combination of wires and resistors. Some answers tend to be useful for people who have the same question but using devices or ICs is allowed.

Best Answer

8 leds on/off have 2^8 = 256 possible states

5 control pins on/off have 2^5 = 32 possible states

Since 32 < 256, and you can't use shift registers or i/o expanders, it would be impossible...

But if the 5 control pins are the pins of a MCU, you need to use only one of them for controling the 4 * 2 multiplexing process. One of the pins can be 0V or +Vcc, each of these two states enables a different set of 4 LEDs attached to the other 4 pins.

"he gave us a hint : use a wire connection combination if a problem appears try solving it in your code"

As this is a theoretical question in a curse, I think that this would be a possible correct answer. This is a kind of 2*4 multiplexing, using only 5 pins.

If you need to control a higher number of LED's, charlieplexing would allow to control untill 20 LED's.

schematic

simulate this circuit – Schematic created using CircuitLab