74HC595 Shift Register and 2N4401 BJT

Thread Starter

blake11

Joined Feb 20, 2010
21
Hey guys, back with another question. I am trying to switch some 2N4401 BJT's with a shift register. I can't seem to get it to work. I know that the register is pushing enough current, because when I pull them out of the mix, the leds light right up. Does anyone have any idea as to why they are not switching?
 

SgtWookie

Joined Jul 17, 2007
22,230
Hello Blake,
Well, the first question I'm going to have to ask you is typical of what I have to ask of most new posters:
Where is the schematic diagram of your circuit?

Basically, if your circuit isn't documented in the form of a schematic, it doesn't exist - so we can't very well help you with it.

Post a schematic, preferably in .png format. Use the "Go Advanced" and "Manage Attachment" buttons to upload the image from your computer.
 

Thread Starter

blake11

Joined Feb 20, 2010
21
Knew that was coming :). I will have it up in a bit. I was hoping to slide a quick one by you. I am not that great at drawing things up, so I will give it a go in eagle real quick.
 

Thread Starter

blake11

Joined Feb 20, 2010
21
Here you go SGT. There are a few things that I omitted from the drawing that are not directly related to this part of the circuit. I have a few QRB1114 IR sensors that give the shift register its values. But for now while I am trying to get this to work. I just wrote a little something to count up with the register and took the sensors out of the circuit. I could not find the correct BJT (I am using 2N4401) so the closet I could find are the 2N4416 in Eagle.

Pretty much here is what the circuit does. At all times the NOR gate is switching the 2N4401 Q1, Q3, Q5 on. When the sensors trip, the register causes the out put on the NOR gate to go low, and the register is also supposed to switch the 2N4401 that is corresponds to so that LED comes on.

Thanks for taking a look at it.
 

Attachments

Last edited:

SgtWookie

Joined Jul 17, 2007
22,230
You have the resistors between the emitters and ground.

When you are using NPN transistors as a saturated switch, you want the emitter connected to ground, and the load on the collector. My personal preference is to have the current limiting resistors for the LEDs on the Vcc side, as that helps to limit damage in case of accidental shorts; the resistor won't likely get burned up, but an LED would.
You will also need a resistor to limit the current through the base of the transistor.

First, determine the necessary value for your LED current limiting resistors (Rlimit).
The generic formula is:
Rlimit >= (Vsupply - Vf_LED) / I_LED
where:
Rlimit = the value of the current limiting resistor
Vsupply = in your case, Vcc
Vf_LED = The typical specification for Vf (forward voltage) @ the LED's recommended current.
I_LED = the LED's recommended current.
For example, let's say you have red LEDs that have a specification of:
Vf=2.5v @ 20ma (typ)
You're using 5v for Vcc
So, Rlimit >= (5v-2.5v) / 20mA
Rlimit >= 2.5/0.02
Rlimit >= 125 Ohms.
Next, we look at a table of standard resistance values. One is here:
http://www.logwell.com/tech/components/resistor_values.html
Bookmark that page.

Looking in the E24 (green) columns, we find that 125 Ohms is not a standard E24 value, but 130 Ohms is.

Let's see what happens when the resistance is slightly increased.
I=E/R
I= 2.5v/130 Ohms
I = 0.01923 Amperes = 19.23mA. That's pretty close; about 96% of their rating.
You're better off to run them with a bit less current; they will last longer.

OK, now check what power rating you will need.
P=EI, or Power = Voltage x Current.
P = 2.5v x 0.01923 A = 48.1mW. We double that for reliability, so 96.2mW. You can use a 1/10 W or higher rated resistor.

Now you need to calculate the base current limiting resistor (Rbase, or Rb for short. No, it's not a sammich. ;))

The generic formula for calculating a base current limiting resistor, or Rb, is:
Rb = (Vin - Vbe) / (Ic / 10)

Now what the heck is that? Ok, let's go through it step by step.
Rb = you know that already, right? The base resistor? Oh yeah.
Vin = the voltage that will be applied to the resistor that is away from the base of the transistor. This will be the output from your 74HC595, or 5v.
Vbe = the voltage on the base, measured with respect to the emitter - in this case, it will also be ground, but that is not always so. For most purposes, you can assume that Vbe will be around 0.7v, unless you are using the transistor at over 1/2 of it's rated current.
Ic = the current that you will be sinking through the collector.
10 = the beta or gain (hFE) of the transistor when used as a saturated switch. You will find this is the most frequent value used.

So, from the above example, it was calculated that the LED will need 19.23mA sunk from it. We'll round that to 20mA just to keep the math easy
Plugging the numbers into the formula:
Rb = (Vin - Vbe) / (Ic / 10)
Rb = (5v - 0.7v) / (20mA / 10)
Rb = 4.3v/ 0.002A
Rb = 2150 Ohms.
In this case, you could use 2.1k or 2.2k; either should work.
 

Thread Starter

blake11

Joined Feb 20, 2010
21
Thank you Sgt for the detailed reply. I will have to wrap my head around the last part when it comes to calculating base current limiting resistor. I usually put the resistors in front of the LED going to ground, but when I started researching how to use the BJT, every example I found had the set up that I am using now. I didn't understand why they did it, but I though the resistors should be in front also. Thank you for clearing that up. So, from your explanation, I guess I am not getting enough current to the BJTs that are being controlled by the shift register. The resistors are 120 ohm, because the LEDs are rated at 3.4 forward drop and 20 mA. I calculated it using 15mA to give the LEDs a fighting chance :). Thank you again for the help.
 

SgtWookie

Joined Jul 17, 2007
22,230
You would be getting FAR too much base current, and overloading your 74HC595 shift registers by a large margin, while your LEDs would be dim, if lit at all.
Your 74HC595 will be trying to source 36mA.

Wired the way I've described (2.2k Ohms on the base) your 74HC595 will only have to source 2mA maximum.

So for your LED resistors:
Rlimit = (5v-3.4v)/15mA
Rlimit = 1.6/.015
Rlimit = 106.7 Ohms
110 Ohms is the closest standard value.

Don't believe everything you read on the WWW. There are plenty of terrible circuit examples around. I've actually posted a few. :rolleyes:
[eta]
See the attached simulation.
Notice that in the left example, Ib is high and Ic is is low. This is the opposite of what you want.
Notice that in the right example, Ib is low and Ic is high. Your LED will glow brightly, and your 595 will be lightly loaded.
 

Attachments

Last edited:

Thread Starter

blake11

Joined Feb 20, 2010
21
Thank you for all your help. I will change up the configuration as soon as I get home and report back with the outcome.
 

SgtWookie

Joined Jul 17, 2007
22,230
I will have to wrap my head around the last part when it comes to calculating base current limiting resistor.
Keep trying. It's tough to understand at first. Then one day it will "click", and that LED in your brain will go on :)

Going back to the formula for Rb for transistor saturation again:
Rb = (Vin - Vbe) / (Ic/10)
I didn't explain Vin very well, I'm afraid.
Vin = the voltage on the input to the base resistor, measured with respect to the transistor's emitter.

You can think of the base-emitter junction of a transistor as a simple forward-biased diode, like a 1N4148 or 1N914. With your NPN transistor, the base is the anode, the emitter the cathode. Such diodes will have a Vf of about 0.7v when 5mA current flows through them. Here is a plot that I made of a 1N4148 diode, using values I measured using a lab supply:



You can see why 0.7v is a typical value that's used; it covers most of the range. However, if Ic is rather large (>300mA for a 2N4401) then Ib will need to be >30mA. That's when it's time to look for a more capable transistor.

I usually put the resistors in front of the LED going to ground, but when I started researching how to use the BJT, every example I found had the set up that I am using now. I didn't understand why they did it, but I though the resistors should be in front also. Thank you for clearing that up. So, from your explanation, I guess I am not getting enough current to the BJTs that are being controlled by the shift register.
Your shift registers are supplying almost ALL of the current to drop the voltage across the resistor, and your LEDs are getting almost no current.
 

Attachments

Thread Starter

blake11

Joined Feb 20, 2010
21
Sgt, you're a lifesaver. Working like a charm now. I am going to sit down with a few books tonight and really try to grasp how a BJT works. Thanks again for all the awesome explanations.
 
Top