How to Drive a DC Motor with a BJT Transistor

How to Drive a DC Motor with a BJT Transistor

DC motors grant electronic devices the force to move, push, pull, block or repel other objects around or even themselves. Fortunately, DC motors aren't difficult to understand or to control. All you need is a transistor capable of switching its current, a few components and some math. Let's take a look.

Water vector created by macrovector – www.freepik.com

This post is about using a small DC motor, usually meant for robotics hobbyists, with a BJT transistor, both NPN and PNP. Different voltage are used: 12V for the DC motor and 5V for the transistor control circuit. This allow us to control it later with a microcontroller, such as a PIC or a Arduino.

If you haven't used a transistor before, I recommend that you go to the basic tutorial on how to switch a LED with a BJT transistor.

Requirements to drive a DC Motor

Components and Devices

In this tutorial, all the components are Through Hole.

  • 2N3904, BJT NPN transistor with TO-92 package: 1 unit.
  • 2N3906, BJT PNP transistor with TO-92 package: 1 unit.
  • DC Motor, rated up to 12V: 1 unit.
  • Push button, type SPST: 1 unit.
  • Resistors, 1/2 or 1/4W, 5% tolerance:
    • 1KΩ, : 1 unit.
  • TO-92 package
  • SPST Push Button

Check out the commercial values of resistors and capacitors here.

Tools and Machinery

  • Breadboard: 1 unit.
  • AC/DC Power Adapter to 5V DC, with at least 500mA: 1 unit.
  • AC/DC Power Adapter to 12V DC (or the rated voltage for the motor), with at least 1000mA: 1 unit.
  • Jumper or UTP Wires: various.
  • Multimeter: 1 unit.

Measuring the values to drive the DC Motor

DC Motors have multiple voltage and current ratings, so let's find out how the values of it.

Voltage

Take a look on the case of the motor. There is a high chance that the rated voltage is displayed on a label. If not, ask in the store where you bought it.

12V DC Motor

The motor pictured above is rated for 12V, hence the power supply chosen is 12Vdc.

Current

Important Notice: The motor hasn't any load on the shaft, so the current passing through the transistor is at it lowest value (at the rated voltage). You must include the mechanical load when doing this measures or you won't have an accurate model to begin with. I chose for this post to do it without any load to make it quick and simple.

If you don't know yet which load it will have, then block the rotor of the motor with your hands or with a plier. This technique is called the blocked rotor condition and the motor will draw the highest peak of current.

How to measure current? The probes of the multimeter must be inserted in the circuit, so the current passes through it. Take a look to the picture below.

Current Measurement Scheme

Grab the multimeter and select the ampmeter mode: select ‘A', DC mode and select the 200mA range and follow this steps:

  1. Connect the red probe to the positive terminal of the power source.
  2. Connect the black probe to one terminal of the motor.
  3. Connect the other terminal of the motor to the negative terminal of the power source.

As you can see, the measures varies from 19.1mA to 159.9mA. For the calculation, let's leave it at 20mA as midpoint but feel free to use any value between both measures.

Final Values

After the tests, here are the results that we have interest in.

Voltage Rating (V)12
Current midpoint (ma)20

The Circuit to drive a DC Motor

Switching Schematic of the Transistor

In the previous post, we used a transistor to switch a LED. The schematic is very similar except that for this circuit two power sources are used.

The NPN is switched on when (enough) current is flowing into the base of the transistor, while the PNP is switched on when (enough) current is drawn from its base.

In both cases, the collector is connected to the circuit that we actually want to switch, where more current flows. The emitter (for this switching model schematic) should be connected either to the ground (NPN) nor to the power source (PNP).

Depending on the quantity of the base current, regulated by the base resistor Rb, the collector will allow a proportional amount of current to flow from the collector to the emitter (NPN) or vice versa (PNP) .

How to Drive the DC Motor with the NPN Schematic

When the switch is turned on, (enough) current flows from the 5V power source from the base to the emitter. Then, the transistor is switched on and the motor begins to rotate.

How to Drive the DC Motor with the PNP Schematic

The equivalent schematic is displayed below and it requires an additional transistor to work.

Since PNP transistors are polarized oppositely, it requires a clear path to ground. When using two different power supplies and PNP transistors, it could happen that the transistor is still on, even if you already have turned it off! It's very common when using microcontrollers.

Why does this happens? Because there is still a differential voltage in the PNP transistor, between the emitter and the base. In our case, it looks like this:

  • When the switch is connected to ground (on), the emitter-base voltage equals 12V. The motor is running.
  • When the switch is connected to the 5V power source (off), the emitter-base voltage equals the 12V (main power source) minus 5V (secondary power source) equals 7V. The motor is still running.

The solution is to deploy a NPN transistor in series with the base of the PNP, as shown below. The switch works the same as the NPN transistor.

Calculating the Drive of the DC Motor to use with a Transistor

How much current should flow through the base? It will depend of every transistor since each transistor model has different characteristics.

Let's look at the datasheet at 2 common general purpose BJT transistors: the NPN 2n3904 and the PNP 2n3906. Both will be used here.

Voltage

Since the maximum voltage is going to be 12V, the circuit doesn't reach any of the maximums of Collector−Emitter Voltage or Collector−Base Voltage.

Current

The Collector Current − Continuous is 200mA, which is more than enough current to switch the LED (20mA).

Gain

The ratio between the collector current ‘Ic‘ and the base current ‘Ib‘ is called HFE gain (sometimes called β). The more current that flows through Ib, the more current will flow through Ic, theoretically. The current Ic is proportionately dependent on the value of Ib; it's translated to the following formula:

Ic = Ib * HFE

How much gain does the transistor has? It depends. It's not a one constant number. It varies on conditions such as temperature, collector current, etc. A few results under certain conditions can be found on the datasheet.

But let's use the HFE measurement tool from the multimeter to find out an approximately value. Connect the transistor to the collector, emitter and base sockets of the HFE measurement. If it's the 2n3904, then insert in the NPN socket and select the ‘NPN' mode. If it's the 2n3906, then in the PNP socket and select the ‘PNP' mode. (The mode selector will vary from multimeter to multimeter).

After measuring it, we will use 150 as the value of HFE for the calculation.

Base Resistor for NPN Schematic

The gain HFE between the Ic and Ib are required to calculate the resistor in the base Rb. In order to secure a good switching mode of the transistor. Multiply the Ib by 5 times. Let's find it out:

Ib=5*(Ic/HFE)=5*(20mA/150)=0,66mA

How big should be resistor Rb to allow just 0,66mA to flow? Bear in mind that you have to consider the 0,7V voltage drop across the diode (from base to emitter). Let's find out Rb:

Rb=(Vcc-Vd)/Ib=(5V-0,7)/0,66mA=6,51KΩ

The closest commercial value for this resistor is 6,8KΩ, so this will be the resistor base Rb.

Base Resistors for the PNP schematic

The principle remains the same. First let's find out Ib:

Ib=5*(Ic/HFE)=5*(20mA/150)=0,66mA

How big should be resistor Rb to allow just 0,66mA to flow? Bear in mind that you have to consider the 0,7V voltage drop across the diode (from emitter to base). Let's find out Rb:

Rb=(Vcc-Vd)/Ib=(12V-0,7)/0,66mA=17,12KΩ

Let's leave it at 15KΩ, so this will be the resistor base Rb.

Now let's calculate Rd, the base resistor of the NPN transistor:

Id=5*(Ib/HFE)=5*(0,66mA/150)=0,022mA

How big should be resistor Rd to allow just 0,022mA to flow? Bear in mind that you have to consider the 0,7V voltage drop across the diode (from base to emitter). Let's find out Rd:

Rd=(Vcc-Vd)/Ib=(5V-0,7)/0,022mA=195,45KΩ

Let's leave it at 200KΩ, so this will be the resistor base Rd.

Testing the Drive of the DC Motor

It works!

How do we test the drive of the DC motor is correctly switched? Let's check what is the voltage drop in the motor and the transistor for every configuration.

Using the Drive with the NPN Transistor

Power Source (V)12,09
Motor Voltage (V)11,82
Collector-Emitter Voltage (V)0,18

The table above indicates that there is the transistor is only taking 0,18V of the voltage available. Great news! Almost all the voltage available is being transferred to the motor.

Using the Drive with the PNP Transistor

Power Source (V)12,09
Motor Voltage (V)11,91
Collector-Emitter Voltage (V)0,1

The table above indicates that there is the transistor is only taking 0,1V of the voltage available. Compared to the previous circuit, this is less voltage drop but very close.

Next Chapter

But how do we control the speed of the DC motor? In the next post, a PIC microcontroller and a Arduino will be used to control and vary the speed of the motor. The PWM technique is used.

techZorro's Index of Content

Keep Reading!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.