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.

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.

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:

- 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).

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.

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:
- How much current does the load need? The lamp, 100 mA.
- How much current does the base need? IB = IC / β = 100 mA / 100 = 1 mA.
- Add a margin. Take 4 to 5 times more, about 4 to 5 mA. A pin supplies that easily.
- 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
| Transistor | Largest collector current | Largest C–E voltage | Largest power |
|---|---|---|---|
| BC547 | 100 mA | 45 V | 0.5 W |
| 2N2222 | about 600 mA | 40 V | 0.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?
2. Why don't we connect a motor straight to an Arduino pin?
3. A transistor has β = 100, and the load needs 200 mA. What is the smallest base current?
4. Work out the base resistor for a base current of 5 mA from a 5 V pin.
5. Why does a fully switched-on transistor stay cool, while a half-on one gets hot?
6. There is a BC547 and a 2N2222 on the table. Are their legs in the same order?