5
\$\begingroup\$

I saw a post here and other circuits on the internet, and I don't understand the difference between them.

I have a PIC microcontroller, and I need to use only one output to control two LEDs: when one is ON, the other should be OFF.

Searching the internet, I found two circuits that seem to be pretty much the same. But I'm not sure if one is better than the other, and if I need to consider something for calculating the resistance of the LEDs.

The circuits: enter image description here

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Well, the right hand one doesn't look right to me, first glance. The left side one has a Thevenin voltage and resistance and may work depending upon the supply rail voltage and the LEDs involved. But it has its own questions. From where did you pull these? \$\endgroup\$ Commented Jul 15, 2023 at 22:55
  • \$\begingroup\$ The supply rail voltage is 5V, and the two LEDs are Red 1.8v. Both are in the internet and the right one its in a post from this site \$\endgroup\$ Commented Jul 15, 2023 at 23:03
  • 1
    \$\begingroup\$ Then the left side could work and the right side still doesn't make any sense because of the orientation of one of the LEDs. Was that image in an answer? Or a question? (Questioners are untrustworthy. Answerers should be more trustworthy.) Regardless, this is a softball question of sorts. Should be quickly answered. \$\endgroup\$ Commented Jul 15, 2023 at 23:08
  • 5
    \$\begingroup\$ The bottom LED in the right side circuit will never light up, unless I am mistaken. \$\endgroup\$ Commented Jul 15, 2023 at 23:08
  • \$\begingroup\$ MKMB - Correct. The bottom LED (reference designators - !) is backwards. With that change, the circuit will work. \$\endgroup\$
    – AnalogKid
    Commented Jul 19, 2023 at 21:39

4 Answers 4

3
\$\begingroup\$

Basic idea

A minimalistic (but three-state) circuit solution can be implemented with only three elements - a resistor and two LEDs; it is only necessary that the LED forward (threshold) voltages meet the requirements VLED1 + VLED2 > Vcc and VLED1 (VLED2) < Vcc. In the conceptual schematics below, I have modeled the LEDs by forward-biased "ideal" diodes with 3 V threshold voltages.

Conceptual 5 V diode circuit

The microcontroller's output (not shown in the schematics below) consists of two complementary transistors which may not connect the output to the supply rails (high output impedance) or connect it either to ground (low output voltage) or to Vcc (high output voltage). I have modeled it here in the simplest possible way with a piece of wire.

High output impedance

In this case, the left resistor end is unconnected (floating). Although the string of two LEDs in series is connected between the supply rails, both LEDs are off since the overall threshold voltage of the string is higher than the supply voltage. No currents flow in the circuit.

schematic

simulate this circuit – Schematic created using CircuitLab

Low output voltage

Now the resistor is connected to ground; so a current flows through LED1 and it is on.

schematic

simulate this circuit

Middle output voltage

During the transition, when the voltage is between Vcc - VLED1 (2 V) and VLED2 (3 V), the circuit state is similar to the high impedance state - both LEDs are off and no currents flow.

schematic

simulate this circuit

We can see it in the DC sweep simulation.

STEP 1.3

This state is not essential in such a digital application because the microcontroller's output voltage quickly jumps this 1 V "dead" zone, but it may have some analog application (LED voltage indicator).

High output voltage

Here the resistor is connected to Vcc; so a current flows through LED2 and now it is on.

schematic

simulate this circuit

"Real" 5 V diode circuit

Typically, the forward voltage of an LED is between 1.8 and 3.3 volts (Wikipedia).

So we can always find suitable LEDs for both 5 V supply and 3.3 V supply. But if we still fail (as in our case since CircuitLab has only a few LEDs), we can artificially increase the forward LED voltage by connecting another diode(s) in series. For example, we can connect two LEDs in series:

1.7 V (LTL-307GE) + 1.7 V (LTL-307GE) = 3.4 V

High output impedance

schematic

simulate this circuit

Low output voltage

schematic

simulate this circuit

Middle output voltage

schematic

simulate this circuit

STEP 2.3

High output voltage

schematic

simulate this circuit

"Real" 3.3 V diode circuit

In this case, we can connect an LED and a diode in series:

1.7 V (LTL-307GE) + .6 V (1N4148) = 2.3 V

High output impedance

schematic

simulate this circuit

Low output voltage

schematic

simulate this circuit

Middle output voltage

schematic

simulate this circuit

STEP 3.3

High output voltage

schematic

simulate this circuit

Transistor 3.3 V circuit

schematic

simulate this circuit

Transistor circuit

See more in a related answer of mine.

\$\endgroup\$
5
  • 2
    \$\begingroup\$ "both LEDs are off since the overall threshold voltage of the string is higher than the supply voltage. No currents flow in the circuit." Are you sure about that? Also, a lot of LEDs would glow noticeably in the dark at only a few uA. \$\endgroup\$
    – Maple
    Commented Jul 20, 2023 at 8:32
  • 2
    \$\begingroup\$ This means you can't use any arbitrary LEDs. For example red LEDs have about 1.6V of forward voltage. Of course two red LEDs could be used in series, but then it becomes a problem if supply voltage is only 3.3V. The LEDs in the question were red, and the supply was 5V, so this would not work unless each LED in the answer is two red LEDs in series, and even then, it may be impossible to actually turn off LEDs as they will light up very easily with low current. They are not ideal on/off devices with some forward voltage threshold. \$\endgroup\$
    – Justme
    Commented Jul 20, 2023 at 9:02
  • 1
    \$\begingroup\$ @Justme the biggest problem is the statement that "no currents flow in the circuit", which is absolutely wrong. \$\endgroup\$
    – Maple
    Commented Jul 20, 2023 at 16:34
  • \$\begingroup\$ @Maple, no currents flow in the "ideal" circuit; in the real circuit they are negligible. \$\endgroup\$ Commented Jul 20, 2023 at 17:05
  • \$\begingroup\$ @Justme, I agree with what you wrote but it still works (especially if you don't use it in a dark room :-) Many times I have connected LEDs of different voltages in parallel and the result of this trick has been very good; that's why I decided of using it here in a similar way. I haven't noticed any residual glow (well, I haven't really stared as much as you with Maple). I have told the story of this invention of mine in my blog. It also shows the path from the origin to the implementation of the idea. \$\endgroup\$ Commented Jul 20, 2023 at 19:40
11
\$\begingroup\$

The bottom LED in the right hand circuit is upside-down. If you correct this this, then the right hand circuit is the correct approach.

Drawing the left-hand design in the two conditions, output low (below left) and output high (below right), we can see why it's less efficient, and won't work for 3.3V logic and 1.8V LEDs:

schematic

simulate this circuit – Schematic created using CircuitLab

If the diodes were absent, the potential at X would be half the supply potential, leaving R16 and R17 with 1.65V across each, which is insufficient to light either LED. Installing an LED would only serve to reduce this already insufficient potential difference even further. The system could work with a supply of 4V or higher, but regardless of output state, there's always a resistor in parallel with the diodes dissipating power unnecessarily.

Drawing your right-hand design in the two possible states, we have a very different situation, illustrating how those two designs are far from equivalent:

schematic

simulate this circuit

In this arrangement, one of the LED+resistor pairs has the full supply voltage across it, regardless of the digital output state, or power supply. The "inactive" resistor and LED have 0V across them, and dissipate no power.


For a more rigorous appraisal of your left hand design, replace the system of R16, R17 and a 5V supply, with their Thevenin equivalent:

schematic

simulate this circuit

If we were to calculate an appropriate resistance Rth to pass diode current \$I_{D}=1mA\$ through D, when D has voltage \$V_{D}=1.8V\$ across it:

$$ \begin{aligned} R_{TH} &= \frac{V_{TH}-V_D}{I_D} \\ \\ &= \frac{+2.5V - 1.8V}{1mA} \\ \\ &= 700\Omega \\ \\ \end{aligned} $$

This corresponds to two resistances \$R_{16}=R_{17}=R=2R_{TH}=1.4k\Omega\$.

The same 1mA of diode current in your right hand circuit would use resistances of

$$R_{18}=R_{19}=\frac{5V-1.8V}{1mA}=3.2k\Omega$$

Now let's plug our value of 1.4kΩ for R16 and R17 back into the your left circuit, and take a look at the various resulting currents and voltages:

schematic

simulate this circuit

We have the required 1.8V across, and 1mA through D1, but there is an additional current of 1.3mA through R16. Clearly that's wasting power, more power in fact, than the LED is receiving!

\$\endgroup\$
6
  • \$\begingroup\$ You are correct. \$\endgroup\$
    – RussellH
    Commented Jul 16, 2023 at 1:04
  • \$\begingroup\$ So recapitulating, the left circuit its less efficient than the right one, but the right one may have a led dimming when its OFF? \$\endgroup\$ Commented Jul 16, 2023 at 2:15
  • \$\begingroup\$ @samuelmattio I don't know what you mean by dimming. For the right-hand circuit, neither LED will ever be in a "dimmed" state. Either one is completely on while the other is completely off, or vice versa. The only way you can have "dimming" is with the digital output having some non-digital intermediate potential. \$\endgroup\$ Commented Jul 16, 2023 at 3:07
  • 3
    \$\begingroup\$ @SimonFitch he is asking about hi-z state of the PIC output \$\endgroup\$
    – Maple
    Commented Jul 16, 2023 at 7:09
  • 1
    \$\begingroup\$ @SimonFitch yes, you forgot that the PIC output has 3 states (not 2). The right-hand circuit with PIC output in the high-impedance state can make both the LEDs shine (at lower intensity). \$\endgroup\$ Commented Jul 16, 2023 at 10:42
3
\$\begingroup\$

If you want to also have a 'both off' state, here is a simple circuit:

schematic

simulate this circuit – Schematic created using CircuitLab

A slightly silly circuit that uses as few as four components to drive 3 individual LEDs to indicate the pin LOW, HIGH, and HIGH-Z

schematic

simulate this circuit

\$\endgroup\$
6
  • \$\begingroup\$ May I ask why are you using transistors to short diodes instead of using them as high and low side switches? This seems awfully inefficient. \$\endgroup\$
    – Maple
    Commented Jul 16, 2023 at 6:58
  • 1
    \$\begingroup\$ You could use them as high and low switches, however with high-Z both would be 'on'. You could add two more transistors and a couple resistors and get the best of both worlds. \$\endgroup\$ Commented Jul 16, 2023 at 7:10
  • \$\begingroup\$ Spehro Pefhany, May I ask you a slightly "off-topic" meta question? I have noticed that I can't edit my older (than in this page) schematics because the EDIT button under the schematic doesn't appear after I go into edit mode on my answer. Do you have the same problem? If so, what could be the reason? \$\endgroup\$ Commented Aug 4, 2023 at 17:49
  • 1
    \$\begingroup\$ Yes, same. No idea what has changed. Obviously if a mistake was found later it would be a lot of trouble to recreate a complex schematic, so it it's not great if it's going to be a permanent 'time-out' on schematic edits. <shrug> \$\endgroup\$ Commented Aug 4, 2023 at 18:00
  • \$\begingroup\$ Thanks for the reply. So we will wait for them to fix it if it is a bug, but it is possible that it was done for some purpose. For now, I click on simulate this circuit, copy the schematic and paste it in the new location. But the simulation settings are not copied and I have to manually transfer them. \$\endgroup\$ Commented Aug 5, 2023 at 3:39
1
\$\begingroup\$

I don't agree with the comments that two circuits are identical.

The circuit on the right (after fixing lower diode direction) only draws current through one diode and one resistor when the MCU output is active. If you configure output as hi-Z then the circuit will draw current limited by two resistors in series. The LED behavior depends on this current. They both may be dimly lit, or (if they are different) one of them can be darker than the other.

The circuit on the left always draws current via R16 and R17, although it will be tiny through one of them when either LED is active. If MCU output is hi-Z then the diodes will be fully off, so that is a plus.

Here is (very simplified) example with 1.8V 5mA red LED in 5V circuit:

Left circuit:

LED ON: 3.2V * 5mA = 0.016W dissipation on one resistor; 1.8V * (1.8V / 640R) = 0.005W dissipation on another resistor; 21mW wasted.

LED OFF: 5V * (5V / 1280R) = 0.0195W dissipation on two resistors; 19.5mW wasted.

Right circuit:

LED ON: 0.016W dissipation on one resistor. 16mW wasted.

LED OFF: It is hard to predict subthreshold current of the LED, and it is not usually included in the datasheets. However it is certain to be less than 3.9mA of two resistors in series, so the dissipation will be less than 19.5mW of the left circuit.

Conclusion: the circuit on the right is more power efficient, however may suffer from dim LED glow in OFF state.

\$\endgroup\$
4
  • 2
    \$\begingroup\$ @RussellH Yeah, I realized my mistake and was editing the post when you commented. I think in my mind I was looking at the diodes as they were in OP, despite mentioning one of them should be reversed. \$\endgroup\$
    – Maple
    Commented Jul 15, 2023 at 23:56
  • \$\begingroup\$ @RussellH By the way, the "dimly" part is relative, and I found it the hard way. On one of our products we had a problem with LED headlights being bright enough to drive at night despite being switched off. Turns out, the driver we were using had leakage current just a bit higher than we expected. \$\endgroup\$
    – Maple
    Commented Jul 15, 2023 at 23:59
  • \$\begingroup\$ So basically for the right one, that its the more efficient one, i will have to test it because its relative if will dim sometimes when its OFF, and if i choose the left one it will lose some power but it will function without the dim when the LED its OFF \$\endgroup\$ Commented Jul 16, 2023 at 2:13
  • \$\begingroup\$ @samuelmattio yes, that's exactly right. If you want a third state with both LEDs off then you need to test if your LED is dim enough to look OFF when the pin is hi-z, or use left circuit and accept some inefficiency. Note that both circuits will benefit from lower LED forward voltage. \$\endgroup\$
    – Maple
    Commented Jul 16, 2023 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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