I am trying to have a microcontroller light up a few LED's, all LED's have a forward voltage of about 3V. The issue is that my power supply(which in this mock-up is 9V) will push too much voltage if less than 3 LED's are on at one time, my question then is how can vary the resistance of the circuit or change the circuit so that when the microcontroller changes the number of LED's currently on the circuit doesn't fry?

On the real microcontroller there are extra I/O pins so if those need to be utilized feel free.


simulate this circuit – Schematic created using CircuitLab

Edit: I should also add that I am newer to electronics and may need more explanation on more complex ideas

From the comments made it seems I've made some errors in my assumptions it seems that the diodes would actually be in parallel in the original schematic, this leads me to ask, if I simply changed the power supply to a 3V supply, would the circuit work as I wanted it to? I suspect no, simply because that seems too easy

  • 1
    \$\begingroup\$ Individual current limiting resistor on each LED would be the simplest way to go about this, keeping in mind the individual current limits of the microprocessor's pins and overall current limit. Power supplies shouldn't change voltage or "push too much voltage" if load changes, so maybe there's something different about yours that we should know about? \$\endgroup\$
    – vir
    Jan 20 at 18:59
  • \$\begingroup\$ Zener diode shunt in parallel with the whole circuit. Or get the right power supply for your circuit in the first place. \$\endgroup\$
    – user253751
    Jan 20 at 19:21
  • 4
    \$\begingroup\$ Unfortunately your question as it stands doesn't make much sense. Firstly, I'm not aware of any micros manufactured today which run from 9V - 5V or 3.3V is much more likely. Secondly, if your micro is turning LEDs on & off using its GPIOs, then those LEDs are not in series with each other - so their individual forward voltages don't get added up. Thirdly, each of your individual LEDs needs its own current-limiting resistor - these are the parts which makes sure that you don't push too much current through any of the LEDs. \$\endgroup\$
    – brhans
    Jan 20 at 19:44
  • 3
    \$\begingroup\$ What does it mean for a power supply to "push too much voltage"? \$\endgroup\$
    – Hearth
    Jan 20 at 19:45
  • \$\begingroup\$ @Hearth by push too much I meant I was concerned about sending more than 3V through one of the diodes \$\endgroup\$ Jan 20 at 22:55

2 Answers 2


It will be really difficult to run the LED's with just a switch like a BJT or mosfet with PWM. You need at least an RC circuit to control the current with a switch, because even if you do have a 'switch' it would only be a short time before the voltage would exceed the maximum rating of the LED and you would risk buring it out. So the best thing to do would be to use a current limiter such as a resistor at minimum, then use a BJT or mosfet controlled by the microprocessor.

Here is an idea below, but instead of the BJT being driven by the 555, you could use the GPIO from the microprocessor

enter image description here

  • \$\begingroup\$ Thank you for your response but could you simplify for me what you mean? I'm unfamiliar with a lot of the terms. Additionally I was hoping that the circuit would work without having to manually flip a switch, if that is do-able \$\endgroup\$ Jan 20 at 22:50
  • \$\begingroup\$ The other options require ICs, that is the simple option \$\endgroup\$
    – Voltage Spike
    Jan 21 at 0:19

Firstly, do not use a series connection for the LEDs. Much too difficult to control if LEDS need to be individually switchable.

Second, since you have unused IO pins, configure one IO pin per LED as output, and use the pin to drive the gate of a MOSFET that is connected in series with an LED and current-limiting resistor (R= 9/LED current). Connect each of the series-connected MOSFET+resistor+LED legs in parallel on the 9V supply. Now you have a individually controllable LEDS, as many as you wish.

EDIT to add longish reply to question in comment:

I assumed you wanted to be able to turn the individual LEDS on or off independently of the others. If that is a correct assumption, then you require one microcontroller output per LED to implement independent turn on/off for each LED (i.e. individually switchable).

I further assumed that independent on/off control of the each LED only was your objective. If dimming is also your objective, then individual LED dimming independent of the other LEDs is also possible with some more complex SW control. You would need ot write some code for the microcontroller that turns each LED on and off rapidly (more than 60 times per second), with the "on" duration being somewhere between 0% (LED off) and 100% (LED full on) of the on/off cycle.

A 3V supply would not really avoid the MOSFET resistor for two reasons: 1) you need the MOSFET to allow the microcontroller to turn the LED on/off, since most microcontroller do not have enough drive to power an LED without such arrangement. 2) a current limiting resister prevents the current from exceeding the LED's safe operating current/power and vapourizing within a short time. Typical LEDS have a maximum rated forward current of 20mA, so the limiting resister needs to be about (9-2)V/20mA = 350 $ \Omega $. Or with a 3V supply (3-2)V/20mA = 50 $ \Omega $.

  • \$\begingroup\$ I'm sorry I'm not the best at this, could you simplify for me. Also what does individually switchable mean? And if I used a 3V supply could I avoid the mosfet resistor thing? \$\endgroup\$ Jan 20 at 22:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.