Transistor

How an NPN transistor uses a small base current to switch a large one: base, collector and emitter, using it as a switch, gain, the base resistor and heat.

Electronics Info
Many small black transistors with three legs and one larger transistor with a metal tab

What is a transistor?

A transistor is an electronic switch with no moving parts. A small current into one leg switches on a large current through the other two. Think of a tap: with a small movement of your hand you let out a strong jet of water, and your hand doesn’t carry the water.

A transistor has three legs:

  • the base (B) is the tap’s handle: a small control current goes into it,
  • the collector (C) and the emitter (E) are the pipe: the large current flows through them, from the collector to the emitter.

Transistors are in every chip: a phone’s processor has billions of them. We use single transistors, most often of the NPN kind.

How do you recognise one?

Small transistors come in a black case with one flat side, called TO-92. The marking is printed on the flat side, and the three legs are below.

Two transistors in TO-92 cases, flat side towards us: the 2N2222 has its legs in the order E, B, C, and the BC547 the other way round, C, B, E. On the right is the symbol of an NPN transistor with the base B, the collector C and the emitter E, where the arrow on the emitter points outwards

Watch out: the order of the legs depends on the type of transistor. The picture shows the two transistors we use in the workshop. With the flat side towards you, the 2N2222 has its legs in the order E, B, C, and the BC547 the other way round, C, B, E. So before connecting one, check its marking and its pin order in the technical documentation (datasheet). In the symbol the emitter is the leg with the arrow, and on an NPN transistor the arrow points outwards.

The transistor as a switch

An Arduino pin may supply about 20 mA. A lamp, a motor, a relay or an LED strip needs much more, so the pin mustn’t power it directly (misconception 25). That is why we put a transistor between the pin and the load:

Schematic: pin D9 is connected through a 1 kΩ resistor to the base of a 2N2222 transistor. A 5 V, 100 mA lamp is connected between +5 V and the collector, and the emitter to ground. 4.3 mA goes into the base, 100 mA flows through the lamp and the collector, and 104.3 mA comes out of the emitter

  • The pin is LOW: no current goes into the base, the transistor is off and no current flows through the lamp.
  • The pin is HIGH: a small current, 4.3 mA, goes into the base through the resistor. The transistor switches on and 100 mA flows through the lamp, the collector and the emitter, more than twenty times what the pin supplies.

The sum of both currents, 104.3 mA, comes out of the emitter. The lamp gets its current from the 5 V supply, not from the pin. The pin only opens the tap.

The graph shows all three while the program switches the pin on and off: the voltage on pin D9 (top), the current into the base (middle) and the current through the collector (bottom).

Three graphs over 6 seconds. Top: the voltage on pin D9 is 5 V from 1 to 3 seconds and from 4 to 5 seconds, and 0 V otherwise. Middle: the base current at the same times is 4.3 mA, and zero otherwise. Bottom: the collector current at the same times is 100 mA, and zero otherwise
The collector current follows the pin: as soon as the pin is HIGH, 100 mA flows, and as soon as it is LOW, nothing flows. A transistor switches on and off in less than a microsecond, so it can also work with PWM.

Gain

A transistor amplifies the base current: the collector current can be as many times larger as the transistor’s gain, written with the Greek letter β (beta). For the transistors we use, β is about 100 or more.

\[ I_C = \beta \cdot I_B \]
The collector current against the base current, with a gain of 100 and a 100 mA lamp: the collector current rises a hundred times faster than the base current up to 1 mA of base current, and after that it stays at 100 mA, as much as the lamp lets through. The point at 4.3 mA of base current is marked
In the graph the collector current first rises a hundred times faster than the base current. With 1 mA into the base, 100 mA already flows, and that is all the lamp can draw on 5 V. More current into the base doesn’t give more current through the lamp: the transistor is fully on (engineers say saturated). We let 4.3 mA into the base, four times more than needed. That margin makes sure the transistor is always fully on, even when its β is smaller than expected.

The transistor in the Arduino workshop

From here on, this page is for the Arduino workshop. We first use a transistor in the lesson Arduino - step by step.

The base resistor

We never connect the base straight to a pin: between the base and the emitter the voltage is about 0.7 V, as on a diode, so without a resistor far too much current would flow out of the pin. We work out the base resistor like this:

  1. How much current does the load need? The lamp, 100 mA.
  2. How much current does the base need? IB = IC / β = 100 mA / 100 = 1 mA.
  3. Add a margin. Take 4 to 5 times more, about 4 to 5 mA. A pin supplies that easily.
  4. Work out the resistor. The voltage across the resistor is the pin’s voltage less 0.7 V:
    \[ R_B = \frac{5\ \text{V} - 0.7\ \text{V}}{0.0043\ \text{A}} = 1000\ \Omega = 1\ \text{k}\Omega \]
    If the value you work out isn’t in the E12 series, take the next larger one, as for the resistor next to an LED, and check that the base current is still at least twice what is needed.

Heat

A transistor turns the power P = UCE · IC into heat, where UCE is the voltage between the collector and the emitter. A fully switched-on transistor has a UCE of about 0.2 V, so at 100 mA it turns only 0.02 W into heat and stays cool. A half-on transistor, with 2.5 V across it, would turn 0.25 W into heat and soon get hot. That is why, as a switch, we always switch a transistor on fully, with enough current into the base.

Limits

TransistorLargest collector currentLargest C–E voltageLargest power
BC547100 mA45 V0.5 W
2N2222about 600 mA40 V0.6 W

The BC547 is good for LEDs and small relays. For lamps, motors and solenoids take the 2N2222, and for even larger currents a MOSFET or a ready-made motor driver module.

Relays, solenoids and motors need a diode

When a transistor switches off the coil of a relay, solenoid or motor, a voltage of tens or even hundreds of volts briefly appears at the collector, and it breaks down the transistor. So put a protection diode next to every coil, cathode towards the plus. Why is explained on the Diode page.

Common ground

The emitter is on ground, and the load can be powered from another source, for example 12 V for a motor. That source’s ground and the Arduino’s ground must be connected, or the base current has nowhere to flow back to and the transistor doesn’t switch on (misconception 8).

The PNP transistor

A PNP transistor works the other way round: its emitter is on plus, and it switches on when we pull its base lower. The arrow in its symbol points inwards. It is used when the load must be connected to ground and the switch on the plus side. In the workshop we use NPN.

What did we learn?

  • A transistor is an electronic switch: a small current into the base (B) switches on a large current from the collector (C) to the emitter (E).
  • The order of the legs depends on the type: the 2N2222 has E, B, C, and the BC547 C, B, E, looking at the flat side.
  • An Arduino pin switches a load through a transistor, and the load gets its current from the power supply. We always connect the base through a resistor.
  • The collector current can be β times the base current. We let a few times more current into the base than needed, so the transistor is fully on and stays cool.
  • Next to a relay, solenoid or motor we always put a protection diode, and we connect the grounds of all sources together.

Short quiz

1. What are a transistor's legs called, and which ones does the large current flow through?
The base (B), the collector (C) and the emitter (E). The large current flows from the collector to the emitter, and a small control current goes into the base.
2. Why don't we connect a motor straight to an Arduino pin?
A pin may supply about 20 mA, and a motor needs much more. The pin could be damaged. We connect the motor through a transistor, and it gets its current from the power supply.
3. A transistor has β = 100, and the load needs 200 mA. What is the smallest base current?
IB = 200 mA / 100 = 2 mA. With a margin we take 8 to 10 mA. For 200 mA you need a 2N2222, because a BC547 may carry at most 100 mA.
4. Work out the base resistor for a base current of 5 mA from a 5 V pin.
R = (5 V − 0.7 V) / 0.005 A = 860 Ω. The next larger value in the E12 series is 1 kΩ, with which 4.3 mA goes into the base, still enough.
5. Why does a fully switched-on transistor stay cool, while a half-on one gets hot?
The power is P = UCE · IC. A fully switched-on one has only about 0.2 V across it, so the power is small. A half-on one has a few volts across it while a large current still flows through it, so it turns much more power into heat.
6. There is a BC547 and a 2N2222 on the table. Are their legs in the same order?
No. Looking at the flat side, the 2N2222 has E, B, C, and the BC547 C, B, E. That is why we always check the marking and the pin order before connecting one.