DC Motor Control: H-Bridge and L293D chip

My OWI-535 robotic arm (link) has DC motors, which are controlled by mechanical switches. Here’s what the schematic looks like for each motor in the robotic arm:

Since there are five motors, there are five switches like this.

This type of switch is called an SPDT, or ‘single pole double throw’ switch. Meaning that it can be flipped in two directions. For this circuit, flipping the switch changes the direction of the current flowing through the motor. In one position, the current flows from +3v to ground. In the other position, the current flows from ground to -3v. This matters because when the current changes direction, the motor will spin in the opposite direction. If it was spinning clockwise before, it will spin counter-clockwise after. And if it was spinning counter-clockwise, it will now spin clockwise.

What I’d like to do is control the motor electronically through a microcontroller. I have a project in mind where I’ll need to do this. I’ll discuss that project in a future post.

If you’re reading this blog post, perhaps you too have a project for which you’d like a DC motor to be controlled by a microcontroller. So just how do we go about that?

###

Direct microcontroller control

The direct and simplest way to control a DC motor with a microcontroller is to attach the motor leads to the microcontroller pins. You can then program one pin to go HIGH while the other one goes LOW. The current will flow from HIGH to LOW through the motor accordingly. If you switch the voltage values on the pins, the current will flow in the opposite direction. In the schematic, the motor appears not to be grounded, but in fact whichever pin is set to LOW will function as its ground.

There are a couple issues with this. First issue involves the voltage: what if your motor runs on 3v and your microcontroller runs on 5v, or vice versa? Not going to work.

The second issue is with regard to the current. Microcontroller pins typically provide only a fraction of the current required to run a motor. Thus, this circuit will be adequate only for very small motors, like microservos or — maybe — those tiny motors that cause smartphones to vibrate.

The motors for my OWI-535, alas, will need more current than a microcontroller can provide. I’ll need some way to boost the control signal from the microcontroller to the motor. That requires transistors.

###

The H-Bridge

Transistors enable us to use a smaller current to control a larger current. Thus, we can send a signal from the microcontroller to a transistor, and the transistor will act as a switch to withhold or send current into the motor. Here is a diagram of a circuit that utilizes transistors so that a microcontroller can control a motor. This circuit is called an “H-Bridge.”

As you can see from the diagram, you need four transistors to control the motor. Only two microcontroller pins, however, are needed to control the motor. Each pin controls two transistors.

(NOTE: For simplification purposes, I’m not showing base resistors, but if you were making the circuit in real life, you’d need to put them there. ALSO NOTE: the microcontroller wires are shown attached to ‘pins #1 and #2’ but any pair of digital pins on your microcontroller will do.)

The microcontroller drives the circuit by supplying current from its pins to the transistor bases. When a pin goes HIGH, a transistor on each side of the motor will ‘open’ and allow current to flow from the motor power supply through the motor. One pair of transistors allows current to flow in a direction that causes the motor to turn clockwise, while the other pair causes current to flow the other way, causing the motor to turn clockwise.

The question of which pin controls which spin direction depends on the physical configuration of the motor. The easiest way to find out the answer is to build the circuit and send a HIGH signal through one of the control pins and see what happens.

The circuit configuration of a motor and four transistors is commonly drawn in the shape of an ‘H’ and as you’ve probably guessed already, that’s why the circuit is called an ‘H-bridge.’

Note that the H-bridge grounds to the same ground as the microcontroller. There is a GND pin on the microcontroller for this purpose.

H-bridges work fine, but they’re also kind of a bother because there are so many discrete components that you have to install. With the OWI-535, you’ve got five motors, which means if you decide the go the component route, you’ll need five H-bridges with twenty transistors, twenty resistors, and lots of connecting wires inbetween. Assembling all this is costly, time-consuming, and prone to error.

We can save ourselves some trouble by using motor-control microchips instead.

###

The L293D: H-bridges in a chip

H-bridges are in such demand in the electronics world that some clever people have designed and fabricated microchips that function as H-bridges. No need for teeming multitudes of transistors and wires — just connect a single chip to the microcontroller and motor.

One such popular chip is the L293D. It serves the purpose of not just one but two H-bridges. See the diagram below for how the pins connect. Each side of the chip controls a motor. Note: For simplification purposes, I’ve drawn only the left side of the pinout.

The pinout for the right side is identical, except that (a) you’ll be connecting to a different motor, (b) you’ll be connecting to different digital pins on the microcontroller, and (c) the bottom pin on the right side of the L293D connects to the microcontroller voltage instead of the motor power voltage.

(As in the previous schematic, the control pin numbers #1 and #2 are just a convention for this drawing and you can substitute with any digital pins on your microcontroller.)

I think it’s kind of weird that microcontroller voltage is supplied through three pins but the voltage that powers both motors is supplied through just one pin. Since the motors draw a lot more current than the microcontroller, it seems like the power voltage should have more pins. ‘More pins for more current’ seems intuitive. But I think the fact that it’s the other way in reality has something to do with the microcontroller voltage being a reference voltage. If you know the true answer, please leave a comment.

Since the OWI-535 has five motors and since each L293D chip can control two motors, it would seem that I only need three chips and I’m good to go. Yay! That’s what I thought last week, and so I went to the local electronics store and bought three L293D chips. Then I took a closer look at the specs for the chip, and recognized that the motor supply voltage has a requirement to be above 4.5 volts.

This creates a problem for me in that the OWI-535 motors appear to be rated for a maximum voltage of only 3 volts. I don’t want to burn out the motors, so the L293D is not the right chip for my project.

However, Good Reader, if you’re working on a project where the motors run at above 4.5 volts, the L293D could be the motor controller chip that’s right for you.

The L293D datasheet links here.

###

The L9110 motor controller chip

Is there a motor-control chip for those of us with DC motors that operate in the <= 3v range? Yes! It’s called the L9110 (which I pronounce “L Ninety-One Ten”).

For low-voltage DC motors, the L9110 appears to be the chip of choice. However, unlike the L293D, the L9110 serves to replace only one H-bridge.

I’ve ordered some L9110 chips online and they’re on their way. My next blog post will be about the L9110 and my experiences connecting the L9110s to the DC motors of my OWI-535 robot arm.

###

What’s Next?

The OWI-535 isn’t programmable because there are no arm-segment position tracking mechanisms — that is, other than the user’s eyeballs. I don’t intend to make position tracking mechanisms for the arm at this time. This is acceptable for my purposes in that I intend to experiment with the robot arm in ‘human mode’ — first with more user-friendly interfaces and eventually to control the arm over the internet.

Comments and corrections are welcome, and please subscribe to my blog if you want to keep track of my progress.

About engineerzero

Once and future engineer.
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s