Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC Transistor LED

Status
Not open for further replies.

PeterDove

New Member
Hi All,

I have seen the diagrams showing a pic pin to a transistor with a LED above the transistor getting power from its own rail. When the PIC pin goes high on the base of the transistor the LED turns on.

There is always a resistor for the LED which I understand. But coming from the PIC pin to the transistor base is always a resistor. Now I have seen many different values for this Resistor. Can someone tell me how I work out what value to use? Is it related to the transistor itself?

Thanks

Peter Dove
 
It's VERY, VERY non-critical - it has to provide enough current to switch the transistor on fully, but not enough to overload the PIC (or damage the BE junction of the transistor). So it's basically realted to the gain of the transistor - which itself varies over a huge range.
 
Yes it's related to the transistor.
You want (Vdd-Vbe)*(transistor gain)/R > LED current.

BE junction is a diode, so 0.7v for Vbe is generally reasonable. At higher currents it will be larger and will be somewhat lower for very small currents.
Transistor gain varies significantly with temp, part variations, and age. Vce(sat), the voltage loss on the transistor when acting as an on/off switch, is lower when the left hand side of that eq is much larger than (like twice) the right hand side.
 
Oznog said:
Yes it's related to the transistor.
You want (Vdd-Vbe)*(transistor gain)/R > LED current.

BE junction is a diode, so 0.7v for Vbe is generally reasonable. At higher currents it will be larger and will be somewhat lower for very small currents.
Transistor gain varies significantly with temp, part variations, and age. Vce(sat), the voltage loss on the transistor when acting as an on/off switch, is lower when the left hand side of that eq is much larger than (like twice) the right hand side.

So in this case VDD is referring to the 5V coming from PIC, or are you reffering to whatever voltage I am providing to the LED? I would assume you mean from the PIC pin.

Thanks

Peter
 
Ideally you want to chose a resistor value that will just barely cause the transistor to saturate, that will allow you the least amount of delay during turn off, using too much drive current is just going to slow turn off times and stress the controller's I/O driver. Too little current and the transistor will stay in an ohmic state and waste power.
 
Sceadwian said:
Ideally you want to chose a resistor value that will just barely cause the transistor to saturate.

I would suggest otherwise, certainly calculate that value - THEN increase the current substantially, to guarantee the transistor is hard on. A lot though depends on what you're trying to switch? - if it's a high current load, use more than one transistor - or a darlington.
 
Nigel Goodwin said:
I would suggest otherwise, certainly calculate that value - THEN increase the current substantially, to guarantee the transistor is hard on. A lot though depends on what you're trying to switch? - if it's a high current load, use more than one transistor - or a darlington.

Hi Nigel,

Its just a LED, a very bright one, but about 40mA.

Thanks for the help.

Peter
 
If you use an emitter follower, you only need one resistor.

And this arrangement reduces the load on the PIC i/o compared to a common emitter circuit.

See attachment.
 

Attachments

  • LED Driver.gif
    LED Driver.gif
    3.7 KB · Views: 1,233
ljcox said:
If you use an emitter follower, you only need one resistor.

But it's less efficient, and less useful, than the other way, which is why it's rarely seen - and usually it's a sign of poor design.

And this arrangement reduces the load on the PIC i/o compared to a common emitter circuit.

In what way?.
 
Why is it less efficient? I know that Ve is about 0.7V less that Vcc, but there is still enough voltage for the LED unless it is one that needs 3V or more. But the normal LEDs only need about 1.8V.

It reduces the load since the common emitter config needs Ib to be large enough to cope with the minimum beta in order to ensure saturation. In fact, the rule of thumb is that Ib should be one tenth Ic.

Whereas, in the emitter follower case, Ib = Ic/beta.

eg. if Ic = 10 mA and Beta = 200, Ib = 50 uA.

Otherwise, using the rule of thumb. Ib = 1 mA.
 
Last edited:
Nigel Goodwin said:
But it's less efficient, and less useful, than the other way, which is why it's rarely seen.

Surely, all the current flows through the LED and therefore this must be the most efficient circuit?

Mike.
 
ljcox said:
Why is it less efficient? I know that Ve is about 0.7V less that Vcc, but there is still enough voltage for the LED unless it is one that needs 3V or more. But the normal LEDs only need about 1.8V.

Otherwise, using the rule of thumb. Ib = 1 mA.

My LED needs 3.6V.

Peter
 
Pommie said:
Surely, all the current flows through the LED and therefore this must be the most efficient circuit?

Because of the greatly increased voltage drop across the transistor, admittedly the base current will also flow in the load - but that's likely to only be tiny percentage of the load current, particularly in the case of driving a 40mA LED.
 
PeterDove said:
My LED needs 3.6V.

Peter
In that case, you need either an NPN transistor or an N channel MOSFET.

What current do you need through the LED?

For example, if it requires 10 mA then the base current needs to be about 1 mA. So the base resistor should be (5 - 0.7)/10 = 430 Ohm.

If you use a MOSFET such as the 2N7000, the gate resistor is not critical.

Use 100 Ohm.
 
ljcox said:
For example, if it requires 10 mA then the base current needs to be about 1 mA. So the base resistor should be (5 - 0.7)/10 = 430 Ohm.

I'm all for making sure the transistor is 'hard on', but for driving an LED at 40mA it's hardly of any importance - anything between 1K and 10K would be fine.

BTW, why did you calculate the base current as 10mA above? - a little slip perhaps? :D
 
ljcox said:
In that case, you need either an NPN transistor or an N channel MOSFET.

What current do you need through the LED?

For example, if it requires 10 mA then the base current needs to be about 1 mA. So the base resistor should be (5 - 0.7)/10 = 430 Ohm.

If you use a MOSFET such as the 2N7000, the gate resistor is not critical.

Use 100 Ohm.

Hmm, I planned on using the BC547B and using the following formula

(Vdd-Vbe)*(transistor gain)/R > LED current.

(5V-0.7V)*( about 350 ) / 10K = 150mA which is plenty above the LED current required.

Is this right?

Peter
 
Notice my post above?, ANYTHING within 1K to 10K (and even well outside that) will be perfectly fine.

However, it's NOT a good idea to calculate using a set exact transistor gain - they vary wildly!.
 
Nigel Goodwin said:
Notice my post above?, ANYTHING within 1K to 10K (and even well outside that) will be perfectly fine.

However, it's NOT a good idea to calculate using a set exact transistor gain - they vary wildly!.

Nigel I ALWAYS notice your posts, but I notice other peoples posts too and in this page we have had some wildly differing answers. I just wanted a confirmation that I had followed the formula correctly. I understand about the varied gain.


Peter
 
Nigel Goodwin said:
I'm all for making sure the transistor is 'hard on', but for driving an LED at 40mA it's hardly of any importance - anything between 1K and 10K would be fine.

BTW, why did you calculate the base current as 10mA above? - a little slip perhaps? :D
Yes, you're right. It should have been 1 mA hence 4k3.
 
PeterDove said:
Hmm, I planned on using the BC547B and using the following formula

(Vdd-Vbe)*(transistor gain)/R > LED current.

(5V-0.7V)*( about 350 ) / 10K = 150mA which is plenty above the LED current required.

Is this right?

Peter
What LED current do you want?

For reliable saturation you need the base current to be about 1/10 th of the collector current. So, for example, if Iled is to be 40 mA, then a 1k base resistor would be adequate.

If you look at the data sheet (I have the Fairchild one) of the BC547, the minimum hFE at 25C is 110 for a collector current of 2 mA. But there is no indication of the hFE at 40 mA. And there is no indication of how it varies with temperature.

So that is why I'm recommending the "rule of thumb" of Ib = Ic / 10
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top