0
\$\begingroup\$

I'm sure this is a very simple question, but as a (near) complete beginner in electronics I would really appreciate a little help in choosing a transistor to switch a 5v LED strip from a 3V RPi GPIO pin.

The background is that the LED strip (20 x 5050 LEDs) provides illumination within a nestbox that contains an RPi and a camera, and I need to switch these lights on and off over a day/night cycle, and I may also run the lights at a lower brightness using PWM.

I have measured the current draw of the section of LED strip that I intend to use in this project at ~260mA (5Vdc), which will be powered by the RPi 5v rail. My understanding is that this should be OK with the 2A power supply I am using.

I can, apparently, run up to 16mA from the 3v GPIO pin I intend to use for switching the LED strip.

Now my question, which is, in a broader sense, how does one go about choosing the ideal transistor? I've spent much of the evening browsing parts lists and there seem to be plenty that would do the job - e.g. something like the MPSW55, with Ic of 500mA continuous and a current gain of 50 - 100 x. There seem to be many, many transistors that "fit the bill", but the data sheets also contain many values which I am unsure about. Are there any other values that I need to look for when choosing a transistor for a project, or can I safely assume that if my headline figures are met (and voltage ratings etc are high enough - which they all are for my needs), that the transistor will work?

Further to the choice of resistor, I have also tried to calculate the value of the resistor that I will need between the 3V pin and the base. Based on a 3V output, 0.7V drop across the transistor and, say, 6mA target (50x gain for 300mA), this gives an ideal value of 383 Ohms. Does this sound correct?

Thanks for reading!

\$\endgroup\$

3 Answers 3

3
\$\begingroup\$

Do you care if you switch on the high side or the low side? Because if you switch on the low side, a logic-level N-channel FET will interface directly to the 3.3V GPIO of your Raspberry Pi. It will have lower IR drop and thus have less thermal dissipation than a transistor.

A 2N7002 will handle ~200mA by itself. Use two or three in parallel and you have more than enough current to handle the LED strip, and then some. These FETs are very, very cheap. Bonus: no gate resistor needed normally.

schematic

simulate this circuit – Schematic created using CircuitLab

Or, use a single, higher-current FET like the NDS351N (1.1A).

If you want to use high-side drive you will need to translate the switching voltage up. In this case, a different circuit would work:

schematic

simulate this circuit

\$\endgroup\$
6
  • 1
    \$\begingroup\$ Nah. I get my PN2222A for 0.4 cents each in 10k qty (I teach and I give them away in handfuls to students.) I've never found a 2N700x anywhere near that price, even in some quantity. (I do have them, of course. But I didn't like paying the price they asked for them.) \$\endgroup\$
    – jonk
    Commented Aug 23, 2019 at 23:33
  • \$\begingroup\$ That's a good price. I was paying about a penny for 2n3904 and 2n7002. \$\endgroup\$ Commented Aug 23, 2019 at 23:35
  • \$\begingroup\$ Hmm. Where are you getting your "penny" 2N7002? I think I paid more!! \$\endgroup\$
    – jonk
    Commented Aug 24, 2019 at 0:12
  • \$\begingroup\$ The buyers at my former employer (a set-top-box maker) were animals. Likely though, they paid more for something else. \$\endgroup\$ Commented Aug 24, 2019 at 0:15
  • 1
    \$\begingroup\$ Bipolar transistors require base drive current; FETs don't - they work on voltage. BJT's have a minimum loss of V(ce) which varies with load current; FETs have Rds(on) which can be very, very low for a big FET but still pretty low even for a small one like the 2n7002 (about 6 ohms.) FETs are easy to parallel, BJT's are less predictable and require separate base resistors (and more drive.) \$\endgroup\$ Commented Aug 24, 2019 at 7:18
1
\$\begingroup\$

You can go for any Logic Level Mosfets (I usually go for N-channel) to control such high-powered loads such as the LED strip that you were stating.

https://i.imgur.com/iHjkbt5.png

Google any Logic Level N-Channel Mosfets that are available in your place. They usually have "L" in them e.g. IRL540, IRL2203N, etc. Check their datasheet to know how much current they can handle and parallel them accordingly.

Note: the L in the circuit I posted is connected to your RPi or any microcontroller.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks for your answer. What is the purpose of the 1M resistor? \$\endgroup\$
    – Matt
    Commented Aug 24, 2019 at 20:28
  • 1
    \$\begingroup\$ The purpose of the 1M resistor is to provide ground to the MOSFETs when the input signal is floating (i.e. disconnected). If there's no 1M resistor in there, the FETs will assume any value in there due to noise and will result in an erratic behavior. It's usually not needed if you're sure that the uC properly sinks the input to gnd if it is pulled low. Also, every MOSFET has gate capacitance on it, albeit very small. Another purpose of the resistor is to provide a safe discharge path for this capacitance. \$\endgroup\$
    – thisjt
    Commented Aug 25, 2019 at 1:13
1
\$\begingroup\$

how does one go about choosing the ideal transistor?

  1. The collector current ability should match with the maximum load requirement. In your example the maximum load current is 260mA. I would choose any transistor with the collector current ability of more than 350 mA.

  2. Now, I am sure load current capability is considered. Next is to check the base current needed. The thumb rule of 10 or 20 always works but we can check that in the datasheet. (I will post images soon after I grab my laptop) so, if I go with 20 as the current gain for the transistor, the base current should be 260mA/20 = 13 mA. Okay.

  3. Check ability of the raspberry Pi to drive a base if a transistor. The GPIO pin ability is limited to drive continuous loads of 13 mA as it will also raise the temperature of the raspberry Pi. A good solution is not to load the raspberry Pi too much. My personal wish is to not to load raspberry Pi but to use another option

  4. Cascading another transistor will help to reduce the load on the raspberry Pi. First transistor will drive the base of the second transistor. Using this method you effectively reduce the burden on the raspberry Pi.

    Even with 2 mA of GPIO current, you will be able to drive about 13 mA of base current in the second transistor. Eventually there are transistors whose gain are significantly higher and are called Darlington transistors. You can use them too.

  5. Lastly, you should see the power dissipation across the transistor. With all the 260 mA flowing through it, depending on the VCE (collector emitter voltage drop) the power dissipation will be VCE times 260 mA. If you assume the VCE to be 1 V, then power dissipated as heat will be 260 mW. To transistor should be able to withstand that much power. You should choose power dissipation capability and package accordingly.also consider base current and about 0.7 V drop for the total heat dissipation.

  6. The forward voltage of the resistors are in the range of 3.3 V for Blue LEDs which means we should not drop too much voltage across VCE from the available 5 V rail. Else the LEDs will not be driven in the best condition.

  7. Lengthy LED rails can act like a small inductor inducing peak surges during turnoff of the LEDs. You can add a free wheeling diode across the LED bus which will protect the transistor from high VCE.

  8. Moving forward, MOSFETs are best choice due to their almost none VDS drop when the MOSFETs are turned on. With a on resistance in the range of 100 mOhms, it dissipates only about
    260 mA * 100 mOhms = 26000 uW or 26 mW. Compare this value against the BJT solution above. Bonus is that raspberry Pi need not shell any current at all to drive it. It is a voltage driven Gate input and hence MOSFET is the best choice to save energy.

  9. Finally, you can also use optocouplers to protect the raspberry PI from the voltage transients coming from the load side. It also helps in basically isolating the LED supply and raspberry Pi supply when needed. Any failure in the MOSFET wil not harm the Pi then.

Based on a 3V output, 0.7V drop across the transistor and, say, 6mA target (50x gain for 300mA), this gives an ideal value of 383 Ohms. Does this sound correct?

Gain of 50x for a normal BJT sounds little on higher side for the current we are talking about. You can verify it by looking at the characteristics in the datasheet. I go with a thumb rule of 10x but datasheet is the best friend.

\$\endgroup\$
5
  • \$\begingroup\$ Thank you for this comprehensive reply, which really does help answer my general query. So, beyond the "headline" figures of current ability and Hfe, I should look at heat dissipation and the current required to drive the transistor - but within the range of BJT, Darlington and MOSFET transistors are many that would "work", but perhaps not be optimal solutions. This BS170 seems a likely candidate? Re: points 7 & 9, how important do you think they are in my scenario and how would I go about implementing this? \$\endgroup\$
    – Matt
    Commented Aug 24, 2019 at 10:15
  • \$\begingroup\$ Sorry to comment spam your answer, but as a followup question: MOSFET seems like a better all round solution for logic level switching from the Pi, for all of the reasons that you have already mentioned. Is there any reason not to make these my "go to" solution, even for lower power projects, since I am not worried about the minimal extra costs and it would simplify the number of components that I keep on hand? Are there any drawbacks to using MOSFET over BJT? \$\endgroup\$
    – Matt
    Commented Aug 24, 2019 at 10:18
  • \$\begingroup\$ @Matt personally I would prefer MOSFET too for this switching application. Regarding point 7, you have to only put one 1N700x series diode from 5 V rail to the Collector of drain of MOSFET ( in reverse bias condition) \$\endgroup\$
    – User323693
    Commented Aug 24, 2019 at 13:09
  • \$\begingroup\$ You can omit opto too if it is a short term setup \$\endgroup\$
    – User323693
    Commented Aug 24, 2019 at 13:47
  • \$\begingroup\$ BS170 is good for this application. Power dissipation is good, gate voltage threshold is more than sufficient. I would definitely use it \$\endgroup\$
    – User323693
    Commented Aug 24, 2019 at 13: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.