How to control 30 LEDs with only 6 wires on the Arduino. The trick is charlieplexing. It works because the I/O pins of the Arduino are tri-states. So they can be high, low or high impedance. Maybe someone can use it. This is a good solution to control a lot of LED’s with only a few components and to save power, because only one LED is on at a time. That’s why the video flickers a little, because the camera perceives it, but the eye does not.

## Here is the diagram of how the LEDs are connected

Between the Arduino pins there are 6 resistors of +-39 Ohm.

Do not forget these!

## A Code to light up, one Led after the oher.

// Simple Charlieplexing, Led by Led

// Define the position of the LEDs on port B. {pinoutmode,pin high)
// the first value defines the pin mode of port B and the second defines whether the pin is high.

const byte LEDS[] = {
{3,1},{3, 2},{5, 1},{5, 4},{18, 2}, {18, 16},
{6, 2}, {6, 4}, {10, 2}, {10, 8},{36, 4}, {36, 32},
{12, 4}, {12, 8}, {20, 4}, {20, 16}, {17, 1}, {17, 16},
{24, 8}, {24, 16},{40, 8},{40, 32}, {34, 2}, {34, 32},
{48, 16}, {48, 32}, {9, 1}, {9, 8}, {33, 1}, {33, 32}

};

long int waittime = 0;

void setup() {
DDRB = B00000000; // Set Pinmode of port B all to Input (tri-state)
}

void loop() {
for (int i = 0; i <= 29; i++) {

DDRB = LEDS[i] ; // Set the two needed Pins of Port B to output
PORTB= LEDS[i] ; // Set one of the 2 selected Pins high, while the other one remains low

waittime = millis();
do {

} while ((unsigned long)(millis() – waittime) < 150); // wait for 150 milliseconds
}
}

Test programs on my Gitub:

https://github.com/awall9999/Charlieplexing