2
\$\begingroup\$

I want to toggle between 2 devices using one GPIO 3.3v pin and powering them with 5v.

I thought about using an NPN and PNP transistor, tying up the base and collector/emitter to 5v power supply. If the GPIO pin goes HIGH or LOW, switch trough either transistor.

So far, I have tried a lot to get it work somehow. But i do not seem to be able to have either the NPN or PNP transistor not be triggered to a degree somehow.

I am too embarrassed to show any of these noob tries, and just want to ask you guys for Ideas how to approach that problem. Am I going a completely wrong way with this?

Is thinking of it like a Y switch wrong?

Thanks für input on this very confusing matter.

EDIT: Some basic Idea, without any resistors (since they are part of my problem: I con't find out, where to place them and how strong.) Placed on my breadboard to get started with LEDs ...

One LED should be ON while the switch is pressed, then should switch to the other if pressed.

Edit 2: Thank you for all your amazing additions to the post. It will probably take me some time to look up all terms and try to understand the explanations :) So please bear with me.

enter image description here (btw: Only screenshot - CircuitLab shows me a CSRF Error when trying to register :/ )

\$\endgroup\$
  • 4
    \$\begingroup\$ Go ahead and show us what you have. I guarantee you someone on here has done it worse; don't worry about being embarrassed! We're here to help. \$\endgroup\$ – Hearth May 12 '18 at 1:24
  • \$\begingroup\$ I tried myself on the schematic thing - I am not even sure, did this correct. I am really sorry if this is wrong \$\endgroup\$ – BananaAcid May 12 '18 at 1:44
  • 1
    \$\begingroup\$ Are you actually trying to switch between two leds? That is very different to wanting two clean 5V switched outputs. \$\endgroup\$ – Henry Crun May 12 '18 at 1:57
  • \$\begingroup\$ There are a few things I notice that are a potential problem here. One, current can flow through the emitter-base junction of Q2, through the base-emitter junction of Q1, and through D2 when the switch is open; it's just three diodes in series, effectively. Two, you don't have any current-limiting resistors here, and this circuit will probably burn out your LEDs and transistors. \$\endgroup\$ – Hearth May 12 '18 at 2:04
  • 2
    \$\begingroup\$ "So please bare with me." You are inviting us to undress with you. I think you should write "please bear with me". \$\endgroup\$ – Transistor May 12 '18 at 15:47
3
\$\begingroup\$

Expanding on Tony Stewart's answer which should work for 3.3 V logic, the circuit below will work on 5 V logic as well.

enter image description here

Figure 1. One GPIO pin can drive two LEDs. Source: 1 GPIO, multiple LEDs.

How it works

  • When the output is switched low, current will flow from the positive supply via R1 and the L1, green, to the output pin. L1 will illuminate. L2, red, will be shorted out and will be dark.
  • When the output is switched high, current will flow from the pin through R2 and L2. The red LED will illuminate and the green will be dark.
  • If the output is tri-stated (wired as an input or disconnected by program control) a current will flow through R1, L1, R2, L2 and both LEDs will glow dimly. On a 3.3 V device the voltage wouldn’t be high enough to illuminate both LEDs significantly so they would appear dark.
\$\endgroup\$
1
\$\begingroup\$

What you are doing is correct as long as you are driving the gpio (and add R2)

If you let the GPIO float then both leds will try to light. As long as you drive it either high or low it works. This is not great on 3.3V, as you can only get 2.6V to run the LED off the NPN - it will run a red led OK, but gets marginal for green when supply tolerances are considered.

schematic

simulate this circuit – Schematic created using CircuitLab

This arrangement suits your original question of using the 5V. It works switching LED's or something else with a minimum ON voltage, but it is not a clean switching arrangement as Q2 runs off Q1.

schematic

simulate this circuit

\$\endgroup\$
0
\$\begingroup\$

High side switching when the input doesn't go that high is tricky, and your requirement that there be no leakage current through the load makes it trickier.

I using only NPN and PNP it took me 5 transistors to do it

schematic

simulate this circuit – Schematic created using CircuitLab

\$\endgroup\$
  • 1
    \$\begingroup\$ You will see people use a pullup resistor from Q1,4 bases to +5. Otherwise leakage currents in Q1,2,3,4 get amplified by the gain, and you get some output current at high temperatures. \$\endgroup\$ – Henry Crun May 12 '18 at 2:14
0
\$\begingroup\$

There isn't a very simple arrangement - you wind up with 3 bjt,5R, or 1pnp,2R,1PFet.

A single invertor package might do. If you use HC or AC invertors, then use the GPIO as an open drain, R5 pulls the GPIO up above the 3.3V until the protection diode conducts i.e. you get 4V on the GPIO, and the 5V invertors will be fully turned on

schematic

simulate this circuit – Schematic created using CircuitLab

Another fantastically versatile component is the analog switch. 74HC4053 triple SPDT would do this for you...

schematic

simulate this circuit

\$\endgroup\$
0
\$\begingroup\$

schematic

simulate this circuit – Schematic created using CircuitLab

Choose R based on R1=(3.3-Vf)/If -33 If R is negative it just means you cannot drive as much current.

for Red Vf=2.0 @ 10mA , R1=100 Ohms
for White Vf=3.1 @ 20mA , R1=0 Ohms and If ~10mA ( similar for Green Blue, R=0V)

33 Ohms is my estimate of your GPIO Vol/Iol=RdsOn. You can change by verifying with your device spec, usually found near the back of 600 page spec. ARM devices are usually 3.3V and 25 Ohms while 5V CPU's are ~ 50 Ohms . This characteristic is "loose" +/-50% worst case over all devices and over temperature but adequate for this application.

Your BJT design would burn out both Base emitters in series across 3.3V with a typical limit << 2V total.

\$\endgroup\$
  • \$\begingroup\$ Both your leds are going to turn on in your circuit, because if one of them is on, the other one will be around 3v since they close a loop with the 3.3v won´t it? \$\endgroup\$ – Flávio Alegretti May 12 '18 at 2:55
  • \$\begingroup\$ No. The GPIO has a CMOS shunt switch like all CMOS logic. If output is 3V positive side LED has 0V drop,. CMOS output is like a SPDT switch with a internal R of 25 to 50 ohms \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 May 12 '18 at 3:05
  • \$\begingroup\$ If one of the FETs failed, or if the input was left floating, it seems possible that both LEDs could be lit. But 3.3V probably won't burn out two series LEDs, even without a resistor. Maybe. \$\endgroup\$ – Hearth May 12 '18 at 15:39
  • \$\begingroup\$ That is unlikely \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 May 12 '18 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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