Electronic – How to determine Resistor values for PNP transistor

pnptransistors

I am trying to use a PNP transistor as a high-side switch, as shown here:
enter image description here

How would I determine the values for R1 and R2? My circuit has a 12V battery connected as shown, and an Arduino digital pin connected to R1. my load is just a resistor and an LED to ground. The transistor I am using is this. The load needs a maximum of 140mA.

A few more questions I have regarding this circuit is:
1) Do I need a diode between the Arduino and R1? It seems like when I hook up the pin without a diode it is constantly on no matter what, even when the Arduino pin goes HIGH.
2) Since the 12V line for now is connected via battery, when I shut off the Arduino the load doesn't turn on but the LED I have in series with the Arduino and R1 does turn on. Why does it do this.

Many of these questions come from a misunderstanding of PNP transistors, so I am sorry for that.

Thank you in advance.

Best Answer

Here is the circuit of a basic high side load driver with low side input.

Vin high turns on Q1.
Q1 on pulls Q2 base low via R3 turning on Q2.

R2 is optional - if Vin is always defined R2 is not needed.
If Vin is eg a microcontroller pin that may be open-circuit after reset until initialised R2 ensures that the circuit stays off until Vin is asserted high under program control.

R4 is usually not essential but in some extreme cases stops Q2 turning on due to base current leakage. This is usually only an issue when very low load currents may be significant.

R3 is designed to provide enough base drive for Q2.
Q2 current gain = Beta-Q2.
Q2 requires a base current of >= Iload_max/Beta_Q2
Usually Beta is forced at a value usefully lower than the datasheet value.
eg if a transistor has a beta of 200-300 under the relevant conditions then driving it with at least say Iload_max/100 (forced beta of 100) ensures it is turned on hard for all likely production samples of Q2.

Q1 switches Ib_Q2.
So Ib_Q1 >= Ib_Q2/Beta_Q1.
This is usually a very low current value and it is usual to overdrive Q1 substantially 'just because'.
eg say Iload_max = 500 mA and Beta_Q2 =200
Decide to drive Q2 at beta=100.
Ib_Q2 = IloadMax/BetaQ1
= 500/100 = 5 mA.

For Vdd=12V, R3 = V/R ~= (12-0.6)/0.005A = 2280 ohm.
R3 of 2k2 is OK but 1k is also OK.

Ib_Q1 = Ib_Q2/Beta_Q1
= 5 mA/100 say = 0.05 mA.
With 5V Vin, R1 =
V/I = (5-0.6)/0.05 mA = 88kohm.
While a value of say 82k or 68k could be used. it's more usual to use a 10k for Ib_Q1 ~= 0.5 mA.
This is well within the drive spec of any microcontroller.

If speed is an issue then a lower value of R1 may be used and a "speedup capacitor" may be connected across R1 - but that's getting beyong the basic circuit.

schematic

simulate this circuit – Schematic created using CircuitLab

______________________

NOT recommended:

ZD1 effectively "level shifts" Vin up by about 8V.
So for Vin = 0/5V, Q2 sees about 4/0 volts drive.
Hence Vin low = on and Vin high = off.

The zener must reduce the Vdd supply enough for the microcontroller to NEVER see more than Vcc_microcontroller at the Vin pin.

A say 100k resistor from the R1- Zd1 junction to ground may be wise to ensure this point is not ever pulled above Vcc_uC. This resistpor needs to be large enough to not turn on Q3 by itself in any situation. Hard to design well.

schematic

simulate this circuit