EmbeddedRelated.com

(So far, 43 people got it right out of 203 for a success rate of 21%)

(Thank you to Clive "Max" Maxfield for submitting this question.  Make sure to have a look at his "Cool Beans" blog.)

I recently was working with a LED-based project that set me to thinking. Let's suppose that the only items we have at our disposal are an Arduino Uno, one or more breadboards, a bunch of flying leads, and an unlimited number of LEDs and associated current limiting resistors. Neglecting a breadboard for the sake of simplicity, we could drive a single LED as shown below (observe that we are using 'L' for "LED" rather than the usual 'D' for "diode" to avoid confusion with the Arduino's digital input/output pins):

Now, let's assume that we are working with 18 input/output pins (D2 to D13 and A0 to A5). Let's further assume that each LED has a forward (On) current of 20 mA. From the Arduino website we know that each input/output pin can sink or source 40 mA.

So, the main question is, "What is the maximum number of LEDs we can individually turn On and Off without affecting any other LED?" Based on the solution to the main question, a follow-on question is, "What is the maximum number of LEDs we can have fully On at any particular time?"

Pick one:
Individually control 18 LEDs with up to 18 LEDs On at same time
Individually control 45 LEDs with up to 12 LEDs On at same time
Individually control 72 LEDs with up to 8 LEDs On at same time
Individually control 81 LEDs with up to 4 LEDs On at same time


[ - ]
Comment by pabloxidFebruary 14, 2020

what about charlieplexing?

[ - ]
Comment by MaxMaxfieldFebruary 14, 2020

OMG -- I wasn't even aware of that technique -- I just looked it up on the Wikipedia (https://en.wikipedia.org/wiki/Charlieplexing)

Using Charlieplexing, we could drive 306 LEDs with our 18 pins (although the circuit and control would make our eyes water), but it's tool late to add that in now.

So let's pretend that what I MEANT the quiz question to say was ""What is the maximum number of LEDs we can individually turn On and Off without affecting any other LED and WITHOUT USING CHARLIEPLEXING?" LOL

[ - ]
Comment by charliepFebruary 16, 2020

Max,

Why all the extra resistors in series with the LEDs ? With the Arduino, I always avoid the series resistor by modulating the LED on / off using an interrupt routine and keeping the maximum duty cycle to 50%. Never lost an LED yet.


Charlie

[ - ]
Comment by MaxMaxfieldFebruary 17, 2020

Hi Charlie -- I guess I just always use current limiting resistors so I can turn the LED on and forget about it. I would be interested to know if over-driving a LED for a 50% duty cycle degrades its operating life. I'll save this question for the next time I'm talking to a "LED Head" :-)

[ - ]
Comment by John64738February 19, 2020

Why isn't the first answer correct?  There are 18 outputs, so if you wire the IO lines to one LED each and the other end of the LED to the PSU ground (not an Arduino I) then you can switch 18 LEDs on at the same time - assuming of course the Arduino can source 360mA across all its outputs.

[ - ]
Comment by MaxMaxfieldFebruary 19, 2020

Hi there -- if the main question was "what's the maximum number of LEDs we can have on at any one time?" then -- as you say -- the first answer would be the correct one.

However -- the main question actually read: "What is the maximum number of LEDs we can individually turn On and Off without affecting any other LED?" The answer to this is .... well, I don't want to say because I don't want to spoil the quiz for others (if we ignore the "Charlieplexing" technique mentioned in the earlier comments).

I then went on to add a subsequent question, which was: "Based on the solution to the main question, a follow-on question is, 'What is the maximum number of LEDs we can have fully On at any particular time?'"

[ - ]
Comment by tcfkatNovember 16, 2022

Hello Max,

furthermore, the ATmega328P (afaik the MCU used on the Arduino Uno) can only sink/source via Vcc or Gnd maximum 200mA. This limits further the maximum current drawn ...

Greetz, Eric

absolutemaximumratings_atmega328p_51191.

[ - ]
Comment by MaxMaxfieldNovember 16, 2022

Good point!

[ - ]
Comment by NusaCatJanuary 16, 2023

I think the question is faulty because of the phrase "without affecting any other LED". If one can't turn on  any LED without turning off another first it would seem to violate that requirement. Which of course extends to being able to turn on ALL the LED's simultaneously.

Also "fully on", which suggests that any version of multiplexing * is not allowed, because anything less than 100% duty cycle isn't fully on. When clearly you did have multiplexing as the answer. Even if you forgot Charlieplexing.

[ - ]
Comment by MaxMaxfieldJanuary 16, 2023

You are correct -- I should have phrased this better (I hang my head in shame :-)

To post reply to a comment, click on the 'reply' button attached to each comment. To post a new comment (not a reply to a comment) check out the 'Write a Comment' tab at the top of the comments.

Please login (on the right) if you already have an account on this platform.

Otherwise, please use this form to register (free) an join one of the largest online community for Electrical/Embedded/DSP/FPGA/ML engineers: