# Transistor as a switch and calculations

Posted on

## Transistor as a switch

Transistor as a switch and its calculations – When we use a microcontroller in sharing our projects, sometimes we need a large current to control a device.

Microcontrollers are generally only capable of outputting a maximum digital pin current of 40mA. This means that if you want to turn on a Brightness LED or Relay that requires a current above 40 mA, then you have to use a driver.

Some components that can be used as drivers are BJT transistors, Mosfet, SCR and others.

The advantages of BJT transistors are that they are small and cheap. The disadvantage is that they are current driven, not voltage driven like MOSFETs, and are generally more suitable for low power applications, such as driving multiple LEDs, small motors or relays.

A good first step to creating a driver is to do calculations. Two important calculations here are getting the values of the two resistors RB (Base resistor) and RL (Load resistor).

Some loads (such as a motor or relay as shown in the image above-right) will not need a load resistor as they already have their own resistance (based on the datasheet), but they may require a fly-back diode.

Fly-Back diode is a diode that is used to prevent reverse EMF which can damage Mosfets or resistors.

### What does EMF mean?

EMF or Electromotive force is a magnetic field that produces electricity.

Mains, if given an electric current, then some of the electric current will turn into a magnetic field. When the current is stopped flowing into the inductor, the magnetic field quickly returns to electric current.

If this happens, current will flow into the circuit. If this condition occurs in the relay, this current will flow quickly and “hit” the transistor.

To be able to prevent this impact, the current is flowed back to the inductor using a diode.

For non-inductive loads (eg LED) this diode is not required. Fly-Back diodes must have fast switching (eg 1N4001) or Schottky.

Let’s assume that we want to drive an LED with 20 mA with a 5VDC power supply, and we determine that the LED has a forward voltage drop of 1.7V (from the datasheet, or by measurement).

We can see from the data sheet for the transistor (2N2222 as a current example) that the Collector – Emitter Saturation Voltage V CE (sat) is approximately 0.4V with a load of 15 mA.

V = 5 – 1.7 – 0.4 = 2.9 V

And since we want 20 mA to flow, we can use Ohm’s Law to calculate RL:

RL = 2.9 / 0.020 = 145 ohms

On the market (to my knowledge) there are no resistor values for 145 ohms, so we will use a standard value of 150 ohms for RL.

The power dissipated by this resistor is using the formula = I ^ 2 * R, which will be:

PL = 0.020^2 * 150 = 0.060 (60 mW)

So a 1/8 watt resistor will fine.

### Base Resistor Calculation (RB)

We want to fully power the transistor, a sufficiently large amount of current is required. The data sheet quotes “Collector – Emitter Saturation Voltage” as one when IC is 150 mA and IB is 15 mA (Figure 2), so we can conclude that (at current levels) the transistor will only get a gain of 10 that is, 150/15 when saturated, then we will need a current of 2 mA to flow through the Base to the Emitter (i.e., 20mA / 10).

The data sheet says that, Base – Emitter Saturation Voltage VBE (sat) is around 1.3V with a load of 15 mA, so the voltage drop across the resistor is:

V = 5 – 1.3 = 3.7 V

Since we want 2 mA to flow, we can use Ohm’s Law to calculate RB:

RB = 3.7 / 0.002 = 1850 ohms

On the market (what do I know) there are no resistor values for 1850 ohms but we can use the 2K resistor value approach.

The power dissipated by this resistor is I ^ 2 * R, which will be:

PB = 0.002^2 * 2000 = 0.008 (8 mW)

So a 1/8 watt resistor would be fine here too.

### Transistor Power Dissipation Calculations

Next we need to calculate the power dissipated by the transistor which will be the sum of the base-emitter power and collector-emitter power.

Power = (VBE(sat) * IBE) + (VCE(sat) * ICE)

• VBE(sat) = 1.3V (datasheet)
• IBE = 0.002 (2 mA)
• VCE(sat) = 0.4V (datasheet)
• ICE = 0.020 (20 m)
• RØJA = 200 °C/W (datasheet)

Power = (1.3 * 0.002) + (0.4 * 0.020) = 0.0106 (10.6 mW)

Heat gain = 0.0106 * 200 = 2.12 °C

The net result here is that we are using 2 mA from the Arduino output pin to control the 20 mA LED.

Now, an Arduino can drive 20 mA directly, but the above should allow you to calculate resistors for other loads.

I hope this Transistor as a switch article is useful.