My First but Not Humble Robot Project



  • mrmamrma Posts: 28
    edited 2014-05-29 - 11:10:45
    Having fun with charlieplexing :smile:

    Do you remember Knight Rider? I was a big fan of the series, most notably the car named KITT. There was a red scanning light in front of the car where the grills are located. Why shouldn't my robot have one?

    You have probably heard of charlieplexing. Well, to put it in a nutshell, it is driving lots of LEDs with only a few pins. To be more specific, n pins can drive n2-n LEDs. Traditional multiplexing takes many more pins to drive the same number of LEDs. I have a few 10-LED bar graph displays waiting for their turn, I can use one of them. According to the formula, I can drive 10 LED with only 4 pins.[In reality 4 pins can drive (n2-n) -> (16-4=12) twelve LEDS].

    Below you will find my Arduino code for charlieplexing, also added a short video to give an idea of my "Knight Rider" light.

    // @author mrma -
    // @copyright Copyfree 2014
    // @brief Charlieplexing using 4 pins to light a 10LED bar graph array

    #define SPEED 30 // the delay in ms between each LED
    #define digPin1 43
    #define digPin2 45
    #define digPin3 47
    #define digPin4 49

    struct led
    byte left;
    byte right;

    // Let's create ten pairs of pins for each single LED light
    struct led leds[10] = { { digPin2, digPin1 },
    { digPin1, digPin2 },
    { digPin2, digPin4 },
    { digPin4, digPin2 },
    { digPin1, digPin4 },
    { digPin4, digPin1 },
    { digPin1, digPin3 },
    { digPin3, digPin1 },
    { digPin4, digPin3 },
    { digPin3, digPin4 } };

    // Turn a single LED on but before turn off all pins to prevent misfires

    void turnLEDon(int myLED) {

    pinMode(digPin1, INPUT);
    pinMode(digPin2, INPUT);
    pinMode(digPin3, INPUT);
    pinMode(digPin4, INPUT);

    pinMode(leds[myLED].left, OUTPUT);
    pinMode(leds[myLED].right, OUTPUT);
    digitalWrite(leds[myLED].left, HIGH);
    digitalWrite(leds[myLED].right, LOW);


    // The setup routine runs once at startup or when you press reset

    void setup() {


    // The loop routine runs over and over again forever

    void loop() {

    for (int i=0; i <= 9; i++) {

    for (int i=9; i >= 0; i--) {



    Here are the circuit diagram, and a graph of connections:

    Charlieplex Circuit.jpg
    800 x 600 - 171K
    1024 x 885 - 85K
  • ercoerco Posts: 19,546
    edited 2014-05-29 - 14:19:51
    Sweet! Everybody loves blinking LEDs & Knight Rider. Alternatively, use a 74LS154 4-to-16 decoder chip to control 16 LEDs using 4 pins. Here's one I did with a 3-to-8 decoder chip (3 lines driving 8 outputs), 7 LEDs and one 5V beeper. &
    "When you make a thing, a thing that is new, it is so complicated making it that it is bound to be ugly. But those that make it after you, they don’t have to worry about making it. And they can make it pretty, and so everybody can like it when others make it after you."

    - Pablo Picasso
Sign In or Register to comment.