How to use transistor as a switch

A transistor is an electronics component that is also used as a digital switch.  Although, it works similarly to a mere mechanical switch. But a digital high logic signal controls this switch as compared to traditional push buttons. We control traditional switches manually by applying a mechanical force.

Transistor Introduction

We design this digital switch by connecting P-type and N-Type semiconductor materials with each other. When we combine a P-type and N-Type semiconductor materials with each other, a junction is formed between them. This junction is also known as a PN junction or a transistor. This PN junction controls the flow of current across the junction. But this junction breaks by applying a proper biasing voltage across transistor pins.

transistor pinout npn

Transistors have two types such as NPN and PNP. It is a three-terminal device. These terminals are:

  • Base ( When using as a switch, we apply control logic this terminal)
  • Collector
  • Emitter

When we apply a biasing voltage to the base terminal, the PN junction breaks down. After that current can flow between collector and emitter terminals. Otherwise, forward current can not flow through the device.

tansistor saturation and cut off mode

you can check these practical transistors:  2N2222, MPSA42, 2N3906

 Using transistor as a switch

Now we will learn:

  • How to use a transistor as a switch in electronics circuits
  • how to use it as a switch in microcontroller projects.

Where to use?

In any application, we need to interface a transistor with a microcontrollerBut the question that may come to your mind, Why do we need to interface transistor with a microcontroller? Because microcontroller pins can not provide output current more than 3mA and voltage more than 5V. If we want to connect a load that requires a higher operating current demand more than 3mA, it will burn microcontroller. Many output devices will require a transistor switching circuit to operate a high current requirement load such as relays, solenoids, and motors.

How to use it?

This diagram depicts the three operating regions of the transistor such as saturation region, active region and, cut off region.  In the saturation region, it remains fully ON. In cut off region, it remains fully off.  For switching purposes, we only need this device to operate either in fully-on or fully off region. Therefore,  we can ignore the Q – Point and switch it between saturation and cut off areas.

transistor operating regions to use as switch

How do transistors as a switch work?

As we see earlier, we can use two regions only. Now, we will see how a transistor works in these regions.

Cut off region is also known as fully OFF mode. In this mode, it acts as an open switch. To operate the device in cut off mode,  We should connect reverse biasing voltage to both junctions.  Therefore, in this operating condition, the current can not flow between the collector and emitter terminal due to open circuit between these terminals.

tansistor cut off mode

In the saturation region, the transistor remains in full-on mode. The maximum current can flow through the collector to emitter according to the rating capacity of the transistor.  We provide forward biased voltage between base and emitter terminal. It works like a short-circuit between collector and emitter.  The biasing voltage is usually greater than 0.7 volt.

tansistor saturation mode

Example of digital logic switches

This PN junction based device has many applications such as high current load interfacing, relay interfacing, and motors interfacing through microcontrollers. But in all these applications, the basic purpose is switching.

This diagram provides an example to control high power loads such as motors, lamps, and heater.

  • In this circuit, we want to control 12 volts load from a digital logic AND gate. But the output of the AND gate is only 5 volts
  • By using a transistor as a switch, we can drive 12v or even high voltage loads with a 5-volt digital logic signal
  • We can also use these devices for faster switching and pulse width modulation control unlike traditional mechanical switches
transistor as a digital switch example

Motor Controlling Example

In this example, we use dc motor control through a switch. A semiconductor device acts as a switch. In this diagram, we can provide a control signal with any microcontroller such as Arduino, STM32F4 development boards.

A resistor with a base terminal is a current limiting resistor. Because GPIO pins of any microcontroller can provide base driving current less than 20mA. Furthermore, D1 is a freewheeling diode that controls back emf from the motor. It bypasses the back emf effect. We can use any transistor according to power rating of the motor.

In conclusion, if a control signal at the base input is 0 volts. It will provide an ON signal. Because we use a PNP switch in this example circuit. Similarly, it will remain off, its control signal is logic HIGH.

Transistor as a swith motor control example off condition

Transistor as switch with Arduino Example

This diagram shows the interfacing of an Arduino with an NPN transistor and a motor. This circuit is just for a demonstration purpose. Because we provide power to a load through Arduino supply. We can only operate a 5-volt dc motor through this example. If you need to drive a large power motor, you should use a special power transistor and a separate power supply.

Transistor as a swith interfacing with Arduino

Transistor as a switch Proteus simulation Example

This example is an exact replication of the prior circuit. But NPN transistor is used instead. Therefore, controlling signals will operate the opposite.

Transistor interfacing with microcontroller

Transistor as a switch Examples

In this section, we will see various examples to use transistor as a switch.

Two transistors as Switch Example

In this circuit, there are two transistors. In the first transistor, the base is grounded and no current can flow into it. As a result, the transistor is “off” and no current can flow through the bulb. In another case, there is current flowing into the base and so the transistor is “on” and the current can flow through it resulting in the light bulb being on.

Transistor as a switch example

In this example, the two resistors are set so that the base of the transistor is at a sufficiently high voltage for current to flow into it and as a consequence, the transistor is on. As a result, the current flows through the light bulb which is therefore emitting light.

Transistor as a switch example 2

Controlling Transistor Base Current with Potentiometer

In this case the current flowing into the base can be varied. If the current is large, the transistor is on and the light bulb is lit. If the pointer on the potentiometer is moved downwards, the current into the base drops until the transistor is off and no current flows through the light bulb.

Controlling Transistor with Potentiometer

Controlling Relay with transistor as a switch

In this example, the principle is the same as the last circuit example except that instead of a light bulb being switched on and off a relay coil is activated and this in turn switches on the light bulbs in the secondary circuit.

Controlling Relay with transistor as a switch example circuit

Controlling Transistor Switch Operation with a Capacitor

This example circuit uses a capacitor to control the current flow to the base terminal of a trannsistor. Initially the capacitor is charged up via the resistor above it. Eventually the upper plate of the capacitor reaches such a potential that a current begins to flow into the base of the transistor, switching the transistor on and causing the bulb to shine.

Controlling Transistor Switch Operation with a Capacitor

You should also noted that the lamp remains off untill enough charge stores inside the capacitor that can provide turn-on current to base terminal of transistor.

In this example circuit, the capacitor charges up until its lower plate is at such a low potential that no current can flow into the base of the transistor. The result is that the transistor is initially on, but then after a period of time is switched off. In this and last circuits, there is a timing effect. After a certain period of time, which can be determined by the choice of resistor and capacitor, the transistor is either switched on or off.

Controlling Transistor Switch Operation with a Capacitor example 2

This example circuit of transistor as a switch is similar to circuit of last example except that by varying the value of the variable resistor it is possible to vary the time it takes before the transistor is switched on.

Controlling Transistor Switch Operation with a Capacitor example 3

Video lecture

In the above circuit, a logic probe is used as input from microcontroller and diode D1 is used as a freewheeling diode to allow the current to flow when the device is in an off state. Remember that we have used 3904 just for a demonstration. While selecting transistors, you should take care of the maximum current that can flow through the transistor in ON state. Microcontroller input is just used to operate transistor in on state or off state as shown in the figure below.
Transistor interfacing with microcontroller

Note that it is usual to connect a back emf suppression diode across the output device. This is essential with devices such as relays, solenoids, and motors which create a back emf when power remain to switch off.

Practically we used mostly relays for high current demanding loads. In that case, the transistor used to operate relay and load is connected with a relay.

Transistor as switch Applications

  • Contol high voltage lamps, motors, and heaters
  • Pulse width modulation high-frequency switching
  • Acts as an amplifier

Related Articles:

2 thoughts on “How to use transistor as a switch”

  1. Just a thought, your PNP example has an error. 0V will be on, but 5V will also be on.
    It needs to be 12V to be off.
    It may be worth fixing I think as, to some folk, it may throw doubt on the validity of your info, and that is unfortunate as your site looks to be a great resource.

    Reply

Leave a Comment

one × two =