Using transistors as switches

I think all popular computerized DIY devices like Arduino, Raspberry Pi or any other microprocessor/microcontroller based boards has one common drawback: low output current. Few miliamps per pin. While this is enough to light a single LED or provide input to other electronics device, it is far from enough to run a motor or power a LED strip. It’s all about current.

Good thing this problem can be solved with two additional devices: resistor and bipolar transistor. Together they can act as a switch. Idea is simple: low current (and voltage if you wish) applied to transistor base causes bigger current (and voltage) to be passed between collector and emmiter. We have two choices: NPN or PNP bipolar transistor. Switch that uses NPN transistor is open/enabled when positive voltage is applied to base. In other words, base is connected to plus.

NPN transistor as switchSwitch that is using PNP transistor is open when base is connected to ground (minus or 0V) and closed when positive voltage is applied. So it works like a signal inverter: device is turned when LOW state is applied.
PNP transistor as switch

Is both cases, driven devices are connected to collector and there is current limiting resistor connected to base of a transistor.

Now, which transistors to use? Usually my first choice is BD193 or compatible. It is NPN (so no inversion) and can safely pass up to 1.5A and up to 80V. So it’s more than enough for lights, LEDs, relays and small motors. For bigger currents and on/off appliances, MOSFETs should be used.

Separate problem is size of resistor attached to transistor’s base. Its size depends on transistor type, voltage, and max current that transistor is switching. If you want to do it right, you should compute it. How? For example using this tutorial and included calculator. If its TL;DR here is a quick rule of thumb for BD139: on 5V input you need 220Ohm to switch up to 500mA, and 1kOhm for anything below 100mA.

Lower resistor value gives higher output current transistor can handle without voltage drop. But you can not lower it indefinitely. It also limits current that is taken from low current source. For example Arduino or any other micro controller or transistor. And max current that can be drawn is always limited. In case of Arduino and most AVRs it’s 40mA.

R = U / I

That means, at 5V and 40mA you can not use smaller resistor than 125mA.

Leave a Reply

Your email address will not be published.