Arduino Playground

Charlieplexing Playground

Charlieplexing is a technique that lets you control a large number of LEDs using just a few Arduino pins. In this example, we're only using pins 2-10 to control 72 LEDs.

Each LED is connected to a different combination of pins. For instance, the top-left LED's negative end (cathode) is connected to Arduino pin 2, and it's positive end (anode) is connected to pin number 3.

Click on "Run Code" to see it in action!

Challenge: Can you change the code to display a pattern that looks like the letter "H"?

Advanced challenge: Change the code to scroll the text "HELLO!" on the LED matrix.


Have questions? Feedback? Please share with us below:

sketch.ino

/**
   Charlieplexed LED Matrix Scanning demo.

   Copyright (C) 2019, Uri Shaked. Released under the MIT license.
*/

#define SCAN_DELAY 50

byte LEDS[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10 };
const byte LED_COUNT = sizeof(LEDS);

void setup() {
}

void loop() {
  for (int i = 0; i < LED_COUNT; i++) {
    for (int j = 0; j < LED_COUNT; j++) {
      if (i != j) {
        pinMode(LEDS[i], OUTPUT);
        pinMode(LEDS[j], OUTPUT);
        digitalWrite(LEDS[i], LOW);
        digitalWrite(LEDS[j], HIGH);
        delay(SCAN_DELAY);
        pinMode(LEDS[i], INPUT);
        pinMode(LEDS[j], INPUT);
      }
    }
  }
}