Using a transistor to switch LEDs ON and OFF - Page 1
Forum section: electronics / beginners

author: Tantal
author_rank: Contributor
timestamp: June 08, 2015, 11:10:29 am
content: - power source: 3,3V- 20 LEDs: 3,2V, 20mA each. Each has it's own series resistor.- microcontroller with 3,3V on the I/O pins.I would like to use the microcontroller to turn the LEDs all ON and OFF.First question:Should I use a NPN... or a PNP transistor?(the images are fromhttp://www.electronics-tutorials.ws/transistor/tran_4.html-it's not actually my circuit (so please ignore 12V & the logic gates))Second question:Which base resistor (Rb) do I need to turn 400mA (20 LEDs x 20mA) fully on or off.

author: LukeW
author_rank: Frequent Contributor
timestamp: June 08, 2015, 01:31:20 pm
content: NPN is generally better.Just like the diagram above, you just connect the "ground side" of your load circuit to the NPN transistor's collector.PNP high-side switching requires that the base be taken right up to the supply voltage (say 12V, or whatever) in order to turn it off - so if you've got a 0-3.3V microcontroller logic output you can't directly switch the transistor on and off without adding a second transistor.Question - do you really need 20mA per LED? If they are ordinary LEDs, most modern LEDs are often quite bright with currents of only 5mA or so. Reducing the LED current will prolong battery life and reduce the size (current capacity) of the transistor needed.As for the base resistor, to get technical about it, from first principles you need to know Ohm's law and the basic properties of a bipolar transistor:VE= 0VTherefore, VB= VBE, which is the drop across the transistor B-E junction.IB= (VI- VB) / RBIC= IB* hFERB= hFE* (VI- VBE) / ICIC = say 400mA, the load current.VBE= say 0.6V.VI = 3.3V.The typical hFE, the transistor's gain, can be looked up for your particular device.Suppose the hFE = 100, then the above would give you 680 ohms.As a "rule of thumb" I often skip the maths and usually just put a 1k resistor in any similar circuit.

author: fubar.gr
author_rank: Unknown
timestamp: June 08, 2015, 01:40:20 pm
content: In this application you can use either NPN or PNP, but NPN transistors are generally more easily obtainable, cheaper and have better performance characteristics so NPN is the sensible choice.The base resistor value will depend on the specific transistor you are going to use.See this video for the process of calculating the resistor valueOn preview, what LukeW said

author: Zero999
author_rank: Super Contributor
timestamp: June 08, 2015, 03:16:20 pm
content: One important thing to remember is the minimum Hfe specified on datasheets is often when VCEis quite high such as 10V.For example, notice how the PN2222A has a minimum gain of 100 when VCE= 10V IC= 150mA but when VCE is reduced to 1V it drops to 50.http://www.nxp.com/documents/data_sheet/PN2222A.pdf

author: PSR B1257
author_rank: Frequent Contributor
timestamp: June 08, 2015, 03:17:29 pm
content: If you have a 12V rail you should connect multiple LEDs in series in order to minimize the total power dissipation in the resistors.As already sayed, most LEDs are happy with less than 20mA.QuoteWell, that's a bad rule. 400mA isquitesome current. And also too much for a ordinary small signal transistor (like BC547)A BC639 (1A NPN) has at 400mA a current gain of about B=70.With 3,3V you would need a 430Ohm resistor (and would choose a smaler one to make sure the transistor is saturated).

author: Tantal
author_rank: Contributor
timestamp: June 08, 2015, 03:40:22 pm
content: Quote from: LukeW on June 08, 2015, 01:31:20 pmOK, lets assume I operate them at 5mA. Then I need bigger series resistors.Power supply:3,3VLED: 3,2V,20mA-> 5.1 ohmsPower supply:3,3VLED: 3,2V,5mA-> 20 ohmsI have been told that series resistors basicallydestroy("burn") energy (current) that would otherwise be to much for the LED.So what's the advantage of limiting current to 5mA - when I then have todestroy15mA in the series resistors?(I assume I have not fully understood this yet - so maybe you can help me with understanding LEDs. I'm a bloody newbie)

author: TimFox
author_rank: Super Contributor
timestamp: June 08, 2015, 03:45:54 pm
content: It may depend on the logic family for the driving gate.Regular TTL may not swing positive enough to shut off a PNP driver, but will certainly swing negative enough to shut off an NPN.CMOS swings close to each rail, but may have less drive current than old-fashioned TTL.LED's are current activated, i.e. the voltage is a weak function of the current, but the current is exponential in the voltage. Therefore, controlling the voltage is a bad idea, but controlling the current is a good idea. When increasing the series resistor to reduce the current from 20 to 5 mA does not "destroy" any current, just reduces the current from the power supply and through the LED.

author: suicidaleggroll
author_rank: Super Contributor
timestamp: June 08, 2015, 03:57:06 pm
content: Driving 3.2V LEDs from a 3.3V supply is not a very good idea. LED forward voltage drops vary quite a bit. Look at the min and max for yours, I bet it's 3.1-3.3V. That means some are going to get double your intended current, and some won't get any current. You'll have drastically different brightness levels due to tolerances in the LED forward voltage drop. Not just LED forward voltage drop either, but tolerances in the transistors you use will cause them to have a range of voltage drops, which will spread things out even more.You should use at least 4V to drive those LEDs, so the wide voltage tolerance doesn't result in as big of a difference in brightness. Or better yet, use a constant current source to drive them, rather than a constant voltage source.Also this comment:Quote from: TantalDoesn't make any sense. You should refer back to Ohms law and the power law. V=IR and P=IV, rearrange them as necessary to suit your needs.With a 5R resistor and 3.2V LED, you'll get 20mA through the circuit and 2mW burned off in the resistor.With a 20R resistor and 3.2V LED, you'll get 5mA through the circuit and 0.5mW burned off in the resistor.

author: Tantal
author_rank: Contributor
timestamp: June 08, 2015, 07:24:15 pm
content: Quote from: Hero999 on June 08, 2015, 03:16:20 pmThe PN2222A was the one I intended to use. Because the datasheet has no graphs for hFEI only have those numbers:VCE= 10V IC= 150mA -> hFEbetween 100 and 300VCE= 1V IC= 150mA -> hFE= 50So I assume there is no way to exactly calculate RBfor VCE= 3.3V and IC= 400mA.I would use a potentiometer and start highenough, with 1000 ohms and play around til IC= 400mA and then exchange the potentiometer for a fixed resistor. Does that make sense?

author: PSR B1257
author_rank: Frequent Contributor
timestamp: June 08, 2015, 07:47:30 pm
content: QuoteWell...no...With B=50 you have a good place to start. The base resistor in this case would be 325Ohm (8mA base current). So a 330 or 270Ohm resistor would be appropriate.If the base current is too high, it dosent realy matter, as long as the µC (or whatever source) can supply this current.You get 400mA also with a lower base current, but in this case the collector emitter voltage is higher.And again. You dont have to calculate with 400mA. Lower the LED current and put several LEDs in one string an you get a much smaller total current.

author: TimFox
author_rank: Super Contributor
timestamp: June 08, 2015, 08:15:38 pm
content: You don't want to calculate the "exact" value for the base resistance, since hFE varies greatly from device to device.Instead, using minimum hFE values, you need to calculate themaximumbase resistor that will provide at least enough base current to saturate the transistor.

author: Tantal
author_rank: Contributor
timestamp: June 08, 2015, 08:32:50 pm
content: Quote from: PSR B1257 on June 08, 2015, 07:47:30 pmBut how can I put several LEDs in one string, when my power supply is only 3.3V?

author: Tantal
author_rank: Contributor
timestamp: June 08, 2015, 08:55:34 pm
content: Other question: Instead of putting the load before the collector, can I put it after the emitter? Like this:

author: scharkalvin
author_rank: Newbie
timestamp: June 08, 2015, 09:00:45 pm
content: You also might consider a switching fet such as the 2n7000.

author: w2aew
author_rank: Super Contributor
timestamp: June 08, 2015, 09:17:58 pm
content: Quote from: Hero999 on June 08, 2015, 03:16:20 pmWhen using a bipolar as a switch, it is customary to saturate the transistor to minimize power dissipation. The hFE values do not apply in saturation. If you look at the VceSAT specs, the base and collector current test conditions most often show the base current as 10% of the collector current. It is quite typical to setup base current of 5-10% of collector current when saturating the transistor. It is also useful to note that VBEsat (Vbe when saturated), can be quite a lot higher than 0.6V (typically 0.7, 0.8V or more, depending on current).When switching a fair amount of current (a few hundred mA or more), then it may be worth looking at a logic-level switching MOSFET instead. No worries about gate current, and typically lower VDSon than the bipolar's VCEset.

author: Tantal
author_rank: Contributor
timestamp: June 08, 2015, 10:16:24 pm
content: Quote from: w2aew on June 08, 2015, 09:17:58 pmYes, I also thought about an n-channel MOSFET. But I have no idea which one to chose.Which one would you recommend for switching 400mA @ 3.3V?Would this one be OK? FQP30N06:www.digikey.com/product-search/en?KeyWords=FQP30N06L

author: TimFox
author_rank: Super Contributor
timestamp: June 08, 2015, 10:18:17 pm
content: Quote from: Tantal on June 08, 2015, 08:55:34 pmThat circuit requires a far higher swing on the output of the gate, and the transistor remains active (not saturated) with excessive dissipation.

author: PSR B1257
author_rank: Frequent Contributor
timestamp: June 09, 2015, 02:52:21 pm
content: Quote from: Tantal on June 08, 2015, 08:32:50 pmIt dosent work with 3.3VBut you showed a picture with a 12V supply...QuoteYes, should work.

author: suicidaleggroll
author_rank: Super Contributor
timestamp: June 09, 2015, 03:08:36 pm
content: Quote from: PSR B1257 on June 09, 2015, 02:52:21 pmHe also said that was an example image off of the net and did not represent his circuit, and that his circuit's power supply was 3.3V.As I mentioned earlier TimFox, you do not want to use a 3.3V supply to drive 3.2V nominal LEDs. There's not enough buffer room and your brightness will be all over the place unless you hand pick a subset of your LEDs with matched forward voltage drops. You also do not want to use a BJT due to the higher Vce. You don't have enough room as it is, you need to get your transistor voltage drop to an absolute minimum if you intend to move forward with this circuit. A very low Rds(on) Nch MOSFET is what you should be looking for.

author: PSR B1257
author_rank: Frequent Contributor
timestamp: June 09, 2015, 06:25:03 pm
content: QuoteGuess I missed this partHere is a neat circuit which allows to drive several LEDs from a low supply voltagehttps://www.eevblog.com/forum/beginners/voltage-regulator-circuit-for-smd-leds/The CMOS 555 also works with 3.3V

author: Zero999
author_rank: Super Contributor
timestamp: June 09, 2015, 07:59:03 pm
content: Quote from: suicidaleggroll on June 09, 2015, 03:08:36 pmIt will work though. It may not be ideal but it'll work.The typical forward voltage is often specified at something like 20mA but the LEDs will give plenty of useful light at much lower currents. Select a series resistor to give the maximum rated current, at the lower end of the forward voltage range and it should be pretty safe.

author: Tantal
author_rank: Contributor
timestamp: June 10, 2015, 11:36:30 am
content: Quote from: suicidaleggroll on June 09, 2015, 03:08:36 pmWhich one would you recommend? I have here a FQP30N06 with Rds(on) = max. 45 mOhm @ 16A, 5V.

author: PSR B1257
author_rank: Frequent Contributor
timestamp: June 10, 2015, 03:10:32 pm
content: QuoteNot only do you need a MOSFET with low RDS,on, but also -and this is important- a logic level type. The FQP30N06 is not specified for 3.3V gate-source voltage.You will need something like an IRF3708.Do you already have the LEDs at hand? Then measure the actual voltagedrop at 5mA or 10mA and decide wether or not the LEDs are bright enough at a particular current.If the voltagedrop is Vf>3.2V you're in trouble (refer to the multiple statements of Hero999)At Vf<3V you're off the hook.Rule of thumb: The maximum voltage across the LEDs should be less than 90% of the supply voltage.

author: suicidaleggroll
author_rank: Super Contributor
timestamp: June 10, 2015, 03:21:25 pm
content: Quote from: Hero999 on June 09, 2015, 07:59:03 pmMaybe, maybe not. He's riding the tolerance fence, not a good place to be. If the LED Vf is a little on the high side and the "3.3v" supply is a little on the low side, it might not light up at all (at least not enough to be visible next to its neighbor running at 20mA). I would be surprised if, with a set of 20 3.2 Vf nominal LEDs and a 3.3v nominal supply, there wasn't a strong temperature dependence and an obvious difference in brightness between at least a few of the LEDs, unless he goes through the effort to hand pick a subset that match.

author: Tantal
author_rank: Contributor
timestamp: June 10, 2015, 06:26:40 pm
content: Quote from: PSR B1257 on June 10, 2015, 03:10:32 pmDatasheets says: Vgs(th) (max.) = 2,5V @ 250µAShould be OK, no?

author: suicidaleggroll
author_rank: Super Contributor
timestamp: June 10, 2015, 06:52:26 pm
content: Quote from: Tantal on June 10, 2015, 06:26:40 pmNo.Vgs(th) is the point at which the FET is JUST STARTING to turn on. You typically need to drive the FET to at least double Vgs(th) to get a reasonable Rds(on). Also, the Vgs(th) for that FET is somewhere between 2-4v (again, you need to watch tolerances), which means to guarantee that the device would be completely on with good Rds, you should be feeding it at least 8v.For a 3.3v drive, you should be looking at devices with a maximum Vgs(th) of about 1.7v or lower.

author: Tantal
author_rank: Contributor
timestamp: June 11, 2015, 07:16:06 am
content: Quote from: suicidaleggroll on June 10, 2015, 06:52:26 pmOK, so how about this one: NDP6060Lhttp://www.tme.eu/en/details/ndp6060l/tht-n-channel-transistors/fairchild-semiconductor/Vgs(th) max. 2VRds(on) 25mOhm @ 5V, 24A

author: Zero999
author_rank: Super Contributor
timestamp: June 11, 2015, 08:15:27 am
content: Quote from: suicidaleggroll on June 10, 2015, 03:21:25 pmIt won't be anywhere near as bad as you think.Modern LEDs give a usable light at a tiny fraction of their maximum current rating and if the LEDs are all from the same batch then their forward voltages should be pretty similar. The forward voltage also has a negative temperature coefficient which means once current starts to flow, it'll heat up and it the voltage would drop. As long as it's designed so the maximum ratings aren't exceeded then it'll work. It may not be perfect but it'll work.

author: j.a.mcguire
author_rank: Contributor
timestamp: June 11, 2015, 10:50:02 am
content: Why do you need the and gate if you're joining the input pins? Doesn't that override the purpose of the gate?Plus if your switch feeds from +12V or +5V do you really have a separate input at vin? Is that to separately power the gate ic?

author: suicidaleggroll
author_rank: Super Contributor
timestamp: June 11, 2015, 01:48:20 pm
content: Quote from: Tantal on June 11, 2015, 07:16:06 amIt's a bit gigantic for the application, but it should be fine.

author: PSR B1257
author_rank: Frequent Contributor
timestamp: June 11, 2015, 02:43:38 pm
content: QuoteThat's fine, but do not take to much attention of this figure.The FQP30N06 has a maximum Vgs(th) of 4V, but that does not mean it operates properly at this voltage.You have to refer to the graph calledON Characteristics(or similar)For the NDP6060L it looks like this:

author: LabSpokane
author_rank: Super Contributor
timestamp: June 11, 2015, 07:41:49 pm
content: Quote from: Tantal on June 08, 2015, 10:16:24 pmTake a look at the NTD3055:http://www.onsemi.com/pub_link/Collateral/NTD3055L170-D.PDFThey are about $.50/ea in low quantity and will switch up to 9A. It's still extreme overkill, but it's hard to get a MOSFET that's much less expensive.

author: Tantal
author_rank: Contributor
timestamp: June 12, 2015, 02:42:30 pm
content: Quote from: LabSpokane on June 11, 2015, 07:41:49 pmI found two more:STP55NF06L:http://www.digikey.com/product-search/en?x=0&y=0&lang=en&site=us&keywords=STP55NF06LSTU95N2LH5:http://www.digikey.com/product-search/en?x=0&y=0&lang=en&site=us&keywords=STU95N2LH5Both with very low Rds On and Vgs(th) only 1V (1.7V). And both under $1.

author: PSR B1257
author_rank: Frequent Contributor
timestamp: June 12, 2015, 02:58:45 pm
content: QuoteDrain-source breakdown Voltage=25VTherefore not suited for your application.

author: suicidaleggroll
author_rank: Super Contributor
timestamp: June 12, 2015, 03:07:54 pm
content: Quote from: PSR B1257 on June 12, 2015, 02:58:45 pmHis maximum Vds is 3.3v, where's the problem?

author: PSR B1257
author_rank: Frequent Contributor
timestamp: June 12, 2015, 06:32:04 pm
content: Had another thread in mind, where a 36V LED is to be controlled

author: LukeW
author_rank: Frequent Contributor
timestamp: June 13, 2015, 07:02:10 am
content: Quote from: Tantal on June 12, 2015, 02:42:30 pmAs was mentioned above, you may not want to run the FET gate close to Vgs(th). Parameters like the effective Rds can change as a function of Vgs, and they are often quoted for relatively high Vgs voltages (say 10V). It's not a binary "all or nothing" thing once you cross the threshold voltage.Particularly in applications where the drain current is high, or super-low on state resistance is needed, you may need to look at driving the gate from a higher voltage, say 10V, and interfacing that to the 3.3V or 5V microcontroller domain. A gate driver IC like a MCP1402 may be considered.But in this 400mA application, that's fairly small, so Vgs probably doesn't need to be that high.