Learn

Using an NPN transistor as a low-side switch

Sign up freeor see every lesson
  • 192parts on the bench
  • 25boards running now
  • 1.00xreal time, on every board
NPN transistor switching a motorlive0.000 s 0.00x
Click the switch to turn it on
The switch stands in for a board pin. The 2N2222 sinks the motor’s current through a 1 k base resistor.

A board pin can give about 20 mA. A small motor wants several hundred milliamps to get going, a relay coil fifty to a hundred, a strip of LEDs more. The pin cannot supply that, so it switches something that can: a transistor. A small current into the base of an NPN transistor lets a much larger current flow from its collector to its emitter, and the pin only ever has to provide the small one.

The circuit above is the usual arrangement, called a low-side switch. The motor hangs from the 5 V rail down to the transistor’s collector, the emitter goes to ground, and the base is driven through a 1 k resistor. The slide switch stands in for a board pin: in one position it gives the base resistor 5 V, a HIGH, and in the other it gives it 0 V, a LOW. It starts LOW. There is a 1N4007 across the motor, which the flyback diode page explains.

Press Run, click the switch over to HIGH and watch the readout under the transistor. The current jumps to about 428 mA, holds there while the motor spins up, then falls and settles at about 124 mA with the motor at full speed.

Sizing the base resistor

The base-emitter junction is a diode, so the base sits a diode drop above ground, about 0.8 V at this current. The base resistor has the rest of the pin’s voltage across it, so the base current is (5 V - 0.8 V) / 1 k = 4.2 mA, which any board pin can supply comfortably.

The transistor’s current gain, beta, is about 100 for a 2N2222, so 4.2 mA into the base allows up to about 420 mA through the collector. Whether that much actually flows depends on the load. Once the motor is running it only wants 124 mA, far less than 420, so the transistor has current to spare and turns fully on. That fully-on state is called saturation, and in it the collector sits just 0.06 V above the emitter: the transistor dissipates 124 mA x 0.06 V, about 7 mW, and stays cold.

The usual rule is to give the base a tenth of the collector current you need rather than a hundredth, which designers call a forced beta of 10. It guarantees saturation across the spread of beta between one transistor and the next and as they warm up. For 124 mA that is 12 mA of base current, and (5 - 0.8) / 12 mA is 350 ohms, so 330 ohms.

The start-up surprise

A motor that is not turning has no back EMF, so it is just its winding resistance, 6 ohms here, and 5 V / 6 ohms is 830 mA. For the first tenth of a second that is what the motor asks for, and 4.2 mA of base current can only allow about 420 mA. So the transistor is not saturated at start-up. It limits the current and drops the difference across itself: 2.4 V at 428 mA is about a watt, for a tenth of a second, every time the motor starts. On the bench that is a warm transistor and a sluggish start.

Change the base resistor to 220 ohms in the editor and try again. The base now gets 19 mA, the transistor saturates from the first instant with 0.08 V across it while 819 mA flows, and the motor starts briskly. But 19 mA is at the limit of what an Uno pin should give, and 819 mA is beyond the 600 mA continuous rating most 2N2222 datasheets give for the small plastic case. The honest conclusion is that a motor this size wants a bigger switch: a TIP120 Darlington, or a logic-level MOSFET, which is the next page.

Why the switch goes on the low side

With the emitter on ground, the base only has to reach about 0.8 V to turn the transistor on, and a 3.3 V or 5 V pin can do that easily. Put an NPN transistor above the load instead, collector to the supply and emitter to the motor, and the emitter rises with the motor’s voltage; the base would need to be above 5 V to switch it fully on, which the pin cannot manage. For switching the high side, you use a PNP transistor or a P-channel MOSFET.

Common mistakes on a real bench

Leaving out the base resistor. The base is a diode to ground, so a pin wired straight to it is a pin shorted through a diode, and the pin or the transistor gives up first. Forgetting a common ground: when the motor runs from its own supply, that supply’s negative has to be joined to the board’s GND, or the base current has no path home. Getting the pins wrong: a 2N2222 in a TO-92 case is usually emitter, base, collector from the left with the flat face towards you, and a BC547 is the other way around, so check the datasheet for the exact part in your hand. And running the motor from the board’s own 5 V pin, where the start-up current can pull the supply down far enough to reset the board.

The same circuit on an Arduino Uno

The gallery has this exact circuit driven from an Uno: pin 9 into the 1 k base resistor, and a sketch that ramps the PWM duty up and down so the motor speeds up and slows down. Open it with the button below and watch the shaft follow the duty. PWM works on a transistor switch because the motor’s inertia averages the pulses into a speed, the same way an LED’s brightness averages them on the PWM page.

Questions

What base resistor do I need for an NPN transistor switch?

Work out the load current, divide it by 10 to get the base current, and use R = (Vpin - 0.8 V) / Ib. For a 100 mA load from a 5 V pin: 10 mA of base current and (5 - 0.8) / 0.01 = 420 ohms, so 390 or 330 ohms. Check the pin can supply that base current.

Why is my transistor getting hot?

Usually because it is not saturated: the base current is too small for the load, so the transistor limits the current and drops volts across itself. Reduce the base resistor, or use a transistor with more gain or a logic-level MOSFET.

Can I drive an NPN transistor from a 3.3 V board?

Yes. The base only needs about 0.8 V. With a 1 k resistor the base current is (3.3 - 0.8) / 1 k = 2.5 mA, so halve the resistor if you need the same current you would get from 5 V.

Do I need a diode across the motor?

On real hardware, yes. A motor is a coil, and when the transistor switches it off the coil drives a voltage spike into the collector. The diode gives that current a path round the motor instead. The flyback diode page shows the spike on a scope.

Build this for real

Open the editor, change a value and watch the number move with it. Nothing to install, and no account needed.