Electronic – Transistor with two voltage levels, Vb ≠ Vcc


Why is my transistor only driving 5V instead of 6V? How can I fix it?

I have a 6V, 25mA circuit running some LEDs. I can control them by connecting and disconnecting the positive terminal of the battery pack.

I want to control them with an Arduino. So I added an NPN bipolar junction transistor with the base attached to the arduino's digital output pin and the collector-emitter acting like a wire from the positive terminal of the battery to the LED circuit. I also connected the Arduino's ground to the battery's negative terminal, but the Arduino is powered off a separate power supply.

 #####    |         |
 #   #  |/         /+\
 # A #--|         (   )
 # R #  |>         \-/
 # D #    | ####### |
 # U #    | #     # |
 # I #    o-# LED #-o
 # N #      #     # |
 # O #      ####### |
 #   #              |

The problem is that the LED circuit really needs 6V to run, while the Arduino's digital pins only output 5V. I don't quite understand why, but even though the collector is attached to 6V, the emitter is not really driving 6V, even when the base is on at 5V.

It's a little hard for me to debug, since the circuit is all diode-y, so if it doesn't get enough voltage that part just turns off in a non-ohmic way. Part of the circuit only needs 5V to function, and it works, but the longer series of LEDs only works when I connect the base to a 6V source.

What is going wrong, and just as importantly, how do I fix it?

Best Answer

You can do this a number of ways. I usually drive transistors in common-emitter mode when using them as switches. The emitter of the NPN transistor goes to the common (ground) rail, the collector to the cathode of the LED and then a current limiting resistor to B+. The transistor will turn on when the base voltage is approximately 0.7V above the emitter voltage. Use a resistor on the base of the transistor (to the I/O pin) since BJTs are current controlled devices.

When the I/O line goes high (say +5V), you will have 5V across the resistor and the B-E junction of the transistor. The transistor B-E junction will drop 0.7V with the remainder (4.3V) across the resistor. Say you use 1k for the base resistor. This will give you 4.3/1000 or 4.3mA of base drive current. This is TONS of current, and since the B-E junction is forward-biased it will amplify the base current by the gain of the transistor (usually between 50 and 200) and limit the C-E current to this level. (When using transistors as switches you usually don't care about the actual collector current, you just want to make sure the transistor is allowing much more current than you will actually draw.) The end result is that the transistor is fully on and your LED will light, limited by the series resistor you chose to limit the LED current to something like 10-20mA.

When the I/O line is low, the B-E junction has no appreciable voltage across it and the transistor is considered "off." I like to include a 4.7k-ish resistor between the base and emitter to make sure that the transistor doesn't accidentally switch on due to noise or a floating I/O pin.

This basic NPN switch circuit works well as long as your C-E voltage is under about 30V and your load is mainly resistive and relatively low current (under a few Amps). When you're trying to control higher voltages you have to start looking at either more specialized (high voltage) transistors or more complex drive circuits. When driving inductive loads (relays, motors, etc.) you need to protect the transistor from the inductive kickback that occurs when current stops flowing through an inductor. When driving high current loads you may have to again look at specialized transistors or more complex drivers to ensure the transistor remains fully switched-on.

If your load must be connected to common (instead of the transistor emitter) then you can use a PNP transistor. Emitter to B+, collector to the LED anode, LED cathode to a current limit resistor and the other end of the resistor to common. Now a logic '1' should turn the LED off and a logic '0' should turn it on, but you've got a problem. The problem is that your I/O line cannot turn the transistor off, because the highest voltage it can reach is 5V (in our example). This would maintain 1V across the B-E junction and the transistor would remain on, even only if partially on. In this case I like to "cheat". You can turn the I/O line into an input to turn the transistor off (remember I like to have a 4.7kish resistor between the base and emitter). This is not ideal because it slows down your turn-off (which may or may not be a problem) but also because you now have (in this example) 6V going to an I/O line. It may not be able to withstand this kind of voltage and you can damage the line or the internal protection circuitry on the input. What I do to mitigate the problem is to use an NPN transistor to turn on the PNP transistor. This doesn't solve the turn-off problem but for most general cases it's nothing to worry about.