Image of eBits Academy inputmotion illustration

An H-Bridge and a DC Motor – A Great Duo!

  • March 22, 2023
  • |
  • Jonas Rothausen

Introduction

We can drive a DC motor using a transistor... In one direction. But what if we want to drive it in two directions—both forwards AND backwards? What do we do then? Let me introduce the H-bridge — current range; check compatibility!

To drive in both directions, we take our DC motor and connect it to our H-bridge — current range; check compatibility so current can flow through the module in both directions. Perhaps easier said than done, but this is the concept that lets the DC motor operate in both directions.

This blog will explain how an H-bridge — current range; check compatibility works, then demonstrate the circuit setup and provide a reference to the code used. If you are only interested in implementation and not the theory of an H-bridge, click here!

The H-bridge — current range; check compatibility is therefore a very useful tool used in many technologies. But what is an H-bridge and how does it work? An H-bridge can consist of a set of transistors working together in a network. This network typically contains four transistors. The direction of current through the network depends on the logic values (HIGH/LOW or 1 and 0) of its different pins. These logic values are determined by the voltage at the transistor bases. We discussed logic values, HIGH/LOW or 1 and 0, in the blog about Digital Circuits.

H-bridge — current range; check compatibility example – BJT

Let’s look at an example of an H-bridge — current range; check compatibility circuit built with two PNP and two NPN transistors; see Figure 1.





Figure 1: Illustration of an H-bridge circuit. The H-bridge contains 4 BJT transistors—two PNP transistors (blue) and two NPN transistors (purple)—with the DC motor in the middle.


Figure 1 shows the H-bridge built from two PNP transistors (blue) and two NPN transistors (purple). BJT transistors are used here because we already have a blog about Analogue Circuits, explaining a little about how BJT transistors work. As we also mention in the analogue circuits blog, BJT and MOSFET transistors perform similar functions. Both MOSFETs and BJTs can therefore be used in H-bridges, and the choice depends on the specific application requirements.

Choosing between MOSFET and BJT depends on voltage, current, switching frequency, drive circuitry and the datasheet safe operating area. For a MOSFET, consider RDS(on), gate charge and switching losses (see the blog on power electronics for an introduction).
For a BJT, consider VCE(sat), base current and charge storage.
Neither type is universally guaranteed to be faster or more tolerant of overvoltage; selection requires actual datasheet values and appropriate protection. BJTs are used here as a teaching example.

Figure 1 shows the bases of the two transistors to the left of the motor connected to point A, and the other two bases connected to point B. At the bottom of Figure 1, the NPN transistor emitters connect to ground. At the top, the PNP transistors connect to Vin, our positive voltage. The trick is that changing the voltages at A and B to HIGH/LOW or 1 and 0 changes the direction of current through the motor. There are four different voltage combinations at A and B; see Figure 2.



Figure 2: Illustration of the four voltage combinations at A and B.

If we take a deep breath and a sip of coffee, we may notice that when A and B are 0, their associated PNP transistors turn on and allow current through them; see Figure 3.



Figure 3: Illustration of the case where A and B are 0.


When A and B are 1, the NPN transistors turn on; see Figure 4.



Figure 4
: Illustration of the case where A and B are 1.

Why is this useful to know? This concept is important because the ideal switching states are intended to avoid direct supply-to-ground current, as illustrated in Figure 5. The simplified diagram does not itself guarantee protection against shoot-through during switching. 



Figure 5: Illustration of an unwanted direct current path through the network.


Such a current path would be a short circuit that could damage the transistors, and the DC motor would then be unable to operate in either direction.
That is a current path we do not want. Which paths do we want? In the ideal steady states, when A and B are both 0, the NPN transistors are off and the PNP transistors are on. When A and B are both 1, the NPN transistors are on and the PNP transistors are off. Both motor terminals then have the same potential. A rotating motor can still produce braking current; “no drive voltage” does not guarantee zero current. 
These cases therefore do not actively drive the motor in either direction. Only two cases in Figure 2 drive the DC motor; see Figure 6.


Figure 6: Motor-driving cases for the network in Figure 1.


These two cases inside the green circle are the ones of interest, and each drives the motor in the opposite direction to the other.

In the first case inside the green circle, A is 1 and B is 0. Current flows from Vin through the PNP transistor on the right at B, through the motor, then towards the output through the NPN transistor at A, as shown in Figure 7.


Figure 7: The case where A is 1 and B is 0.


In the second case inside the green circle, A is 0 and B is 1. This allows current through the motor in the opposite direction to the previous case in Figure 7.
Current then flows from Vin through the PNP transistor on the left at A, through the motor, then towards the output through the NPN transistor at B, as shown in Figure 8.



Figure 8: The case where A is 0 and B is 1.


This is how H-bridges change the direction and amount of current through the motor—by changing the polarity across the DC motor’s terminals.  

One of the most common uses of H-bridges is controlling robots and other automated systems where motors must move in different directions and at different speeds. H-bridges can also be used in other applications, such as solar power systems, to regulate current and voltage from solar panels.

In addition, H-bridges — current range; check compatibility have become popular in DIY electronics and hobby projects for controlling different electronic devices and motors!

Now we understand how an H-bridge — current range; check compatibility works, so let’s demonstrate how to use the MX1508 — current range; check compatibility H-bridge in practice with a microcontroller.


Demonstration – MX1508 — current range; check compatibility

The following circuit shows how to connect an Arduino UNO to the MX1508 — current range; check compatibility H-bridge. Connect the wires as shown in Figure 9.


Figure 9: Circuit for the MX1508 — current range; check compatibility H-bridge and a DC motor.

Upload the code shown in Figure 10 through Arduino IDE. You can download Arduino IDE here: Link.


Figure 10: Arduino IDE code for driving a DC motor in both directions. Find and copy the code from this GitHub Link.

As the code shows, the motor first runs forwards for 3 seconds and backwards for 3 seconds. It then stops, and the forward PWM duty cycle ramps from 0 to 100%; the sequence is then repeated in reverse. A linear PWM ramp does not guarantee constant mechanical acceleration.

Required Components

To build this project, you need the components below. Most are available here at eBits.dk.

Quantity Image Components
1   Arduino UNO
1 MX1508 H-bridge — current range; check compatibility
7 Dupont cables

(male/male)
1 9 V battery
1 DC motor

Note that microcontrollers other than Arduino UNO can be used.
Leave a comment

Please note, comments need to be approved before they are published.