Multiplexing for a 7 year old

I have been wanting to make a LED clock for sometime and can’t really believe I never have. So I rummaged through some parts and found some nice 4 segment LED displays. I found some code for a simple clock at nootropicdesign, and it did something pretty neat. It slowed down multiplexing so you could see it, then it would get faster until it appeared “on”. It was a good sketch, but I thought, it needs set buttons, a blinking colon, and a way to trigger the multiplex slow down trick with out restarting. (and resetting the clock!) So I made this little clock and it worked great.

This was a great way to show my 7 year old (who wrote his first Arduino sketch the other night) about multiplexing. A picture is worth 1,000 words right? Well, a hands on demo is worth even more than that. After explaining how it works, he totally understood.

Then I noticed I had, sitting on my bench, some Lexan laser cut, for those little Nokia LCD’s I love so much, that had a 4 segment LED display size hole in them. I made the clock and moved some pins around to free up 3 PWM pins for an RGB LED. Because it’s always good to have a full PWM controlled RGB LED, ya know, just in case. Thinking of programming the LED different colors/brightness according to sun position. I also remembered I have a few Dallas 1307’s.. Maybe tomorrow, it’s late right now, and besides I’m busy porting software for a Touch Shield I got. πŸ™‚

If your new to multiplexing, it basically combines pins of LED’s and then through switching on only certain pins at a time, you can light only certain LED’s. If you were to apply power to more than 1 cathode and anode, you would get unwanted LED’s lighting. So how can this work? I have to light 14 LED’s just to display 1:00! What makes this work is you light one segment at a time. With a microcontroller, you can do this in an order and at a rate that’s fast enough that the human eye thinks that they are on solid. Most LED 4 digit displays found in microwaves, stoves, appliances, and VCR/DVD players are multiplexed. Its a great way to light a lot of LED’s with less pins than connecting each directly to the microcontroller. Below is a circuit diagram of the LED display I used. The link for the code is below as well, as always, hack away. πŸ™‚ Detailed pinout for Arduino are in the code comments.


Get the code here. (Arduino 22 .pde file)

Schematic (Eagle file)

Schematic (png file)

5 thoughts on “Multiplexing for a 7 year old

  1. Wow. Love this. Gives me confidence to reuse a similar clock display that I salvaged from a broken clock radio. I’m significantly older than 7, but it definitely helped me to understand multiplexing with that example.

  2. Hi,

    I’m new to this arduino world (digital electronics in general) and I’m a bit confused about how you made this clock.

    So an Arduino Uno has 14 digital pins as far as I know. But after going through your code you have:
    4 pins for each digit
    7 pins for the seven segments of each digit
    1 pin to blink the colon between hours&minutes
    3 pins for the three buttons
    3 pins for the RGB led

    That’s 18 digital pins in total but an Arduino UNO only has 14?
    You are using the ATMEGA328 in your final solution right?

    I was thinking about making a clock based on this for my children, they can’t tell time yet because they are too young. I would like the RGB led to show a red color when they need to sleep, and when they can get out of bed in the morning I would like to change the color to green.

    Could you post a full picture of your design diagram?

    Best regards,

    • Hi Jan, good questions! I realized that I had not made a schematic for that project, so I made one today. It is now in the post above.
      Just a word about Arduino Pins, there are actually 20 pins that you can use. There are digital 0-13 (3, 5, 6, 9, 10, and 11 capable of PWM output), and then Analog In A0-A5. These Analog pins can also be referred to as pins 14-19. Even though they are analog β€˜input’ pins, they behave just the same as a digital pins, with the added function of 8 bit ADC on each one. (It can measure voltage in 1,024 steps.)
      Let me know if you have anymore questions, I’ll be glad to help you. Below is a pinout of a ATmega328 the way the Arduino bootloader uses the pins. Have fun with your project and thanks for stopping by!

  3. Hi there,
    nice clock πŸ™‚
    i have similar four digit 7 segment common anode display and i would like to make a clock out of it(hopefully with thermometer – dallas DS1820, but that can wait),
    could you help me out with connecting this to arduino nano through shift registr (74hc595) and i found out that i can use ULN2803A to minimize the pins on arduino board , the board i have is Arduino nano rev 3.0 with ATmega328, as far as i know the nano has 12 digital pins and 8 analog so it should be enough for this project, to make things clear, im just starting with arduino and i have two board the nano and Mega 2560, i want to connect this to nano because i want to make it porable.
    thanks a lot for any help.

Comments are closed.