Monday , January 23 2017
Home / Embedded Systems / Basics / Basics of DC Motor Drive and Speed Control for Robots

Basics of DC Motor Drive and Speed Control for Robots

dc motorDC motors are really cheap and can be found very easily. In this post we will discuss the basic theory behind the DC motor drive system and its speed control. Having some basic understanding of how your motor driver works will play a key role in building your own circuits debugging them.

The main advantage is that, they are really easy to interface. Hook the wires on to the battery terminals and they will work just fine. The direction of rotation is based on the direction of current flow in the armature (polarity of the battery). The below image illustrates the direction on the motor with respect to the direction of the current flow.

DC Motor Drive principle

Okay, if you flip the wires connected to the battery terminals, the direction of rotation will change! But that is not gonna help much if you want the car to be remote controlled. So there has to be a way to flip the wires without having to touch it… That’s when an H-Bridge network comes into action.


An H-bridge is nothing but a connection of the motor that resembles the letter ‘H’ in the English language.

DC Motor Drive Mechanical arrangement

S1, S4 – ON and S2, S3 – OFF

Now if we were to turn on the switch S1 and S4 we will observe that the current flows from Battery positive to S1 and then to the motor and reached the negative terminal of the battery through S4.

Switches S1 and S4 are ON

S2, S3 – ON and S1, S4 – OFF

Similarly, if we were to turn on the switch S2 and S3 we will observe that the current flows from Battery positive to S2 and then to the motor and reached the negative terminal of the battery through S3.

Switches S2 and S3 are ON

From the above cases you can see that the direction of current flow is reversed. Hence the direction of rotation of the motor is also reversed. This way we are able to drive the motor in both the directions without having to manually flipping the wires.

Electronically speaking,

Yes, we do have to speak electronics! Switches S1 through S4 are replaced with transistors Q1 through Q4. Here is what it will look like once we are done replacing the mechanical stuff with electronics,

DC Motor Drive H Bridge 1

The 1k ohm resistors connected to the base of all the transistors are meant for current limiting. The diodes connected parallel to the transistors are called free-wheeling diodes and are used to prevent the transistors from getting damaged due the back currents (inductive) during switching.

In the above circuit, all the transistors are NPN so they turn on if logic 1 is given to them and are OFF when no logic or logic 0 is given. The drawbacks of this network is that there are 4 IO pins required to drive one motor. A slight variant of this connection is shown below,

DC Motor Drive H Bridge 2

Here two transistor are paired and then used with a single IO pin. Here one of two transistors is PNP so, it need logic 0 to turn ON. So if we were to give Logic one to one pair, then only the lower transistors (NPN) are turned. Similarly a logic 0 will turn on only the upper transistors (PNP). This way we are able to reduce the number of microcontroller pins required to the control the motor. This is the sort of circuit our L293d drivers use.

There is yet another configuration that uses only one pin to control the motor.

DC Motor Drive H Bridge 3

This is nothing but the previous connection with a NOT gate connected in between both the inputs. So if logic 0 is given then one pair will get logic 0 and the other will get logic 1. Hence the motor will rotate in one direction for logic 0 and another direction for logic 1.

The obvious disadvantage is that there is no way to stop the motors. All you can do is change the direction of rotation.

L293 Motor Driver

Fortunately for you don’t have to worry about all the circuits discusses above. There is a discrete IC (L293) that will handle all the electronics internally. The L293 is the most commonly used motor driver in robotics.DC Motor Drive l293

The IC is divided into two channels, one channel contains one motor and its control signals. So one side of the IC (pin 1 to 8) is channel 1 and the other side (pin 9 to 16) is channel 2. You can see that each side have an enable pin (pins 1 and 9) they are used to turn ON/OFF the control for that channel.

The pins labelled as Motor +ve and Motor -ve (pins 3,6,11, and 14) is where the motor has to be connected and the Logic A and Logic B (pins 2,7,10, and 15) are where the control signal to that particular motor has to be given.

Vcc1 (pin16) is the supply for the IC and should not exceed 5V. Vcc2 (pin 8) is the supply for the motors (high voltage high current supply). The two Vcc are internally isolated. The ground (-ve terminal) of both the supplies (Eg., 5v for IC and 12v for motors) should be connected to the ground pins (pins 4,5,12, and 13).

Choosing the right motor driver

As your robot size increases, you will find that you need bulkier motors which draw more current from the supply to carry the payload. L293 can supply up to 1A per channel if your motors draws more current then there is the L298 which can supply upto 2A per channel.

If your motor still needs more current (thats got to be one hell of a motor) then you have to build your own motor driver like the one shown in the circuits above. You might need to replace the transistors in the circuits with suitable (current ratting) MOSFETs.

Speed Control Techniques

The speed control of a DC motor is always done by controlling the input supply voltage. There are various methods used to vary the speed of the input voltage such as the potential divider method and the variable resistance method. But those methods a lossy as they linearly cut the current. An effective way to achieve voltage control (thereby speed control) is to use Pulse Width Modulation (PWM).

Pulse Width Modulation (PWM) Techniques

In this method, the width of the pulse is varied while the frequency of the pulse train is kept constant. In other words, the ON time of a pulse is varied while a total time period T is maintained constant.pulse width modulation technique

As the figure illustrates, the width of the pulse has been changed from the first pulse train to the next pulse train. The ration of the ON time to the total time T is called as the duty cycle. Duty cycle is always expressed in percentage or as fraction.

Now that you know what PWM is, lets discuss why we need it and how it can be used to vary the voltage and hence vary the speed of the motor.

Speed Control with PWM

When such PWM signals are given to the motors, they are turned ON for some time and turned OFF for some time. By varying the ON time, we are varying the time of exposure of the supply to the motors. Hence the average voltage supplied is varied.pulse width modulation duty cycle

So if we give 75% duty cycle, we are giving 75% of the supply to the load (motor). Similarly, when we give 20% duty, we will be giving only 20% of the total supply to load.

This signal is given to the enable pin of the L293 to control its speed. In case of a MOSFET based drive, this signal is given to the gate terminal of the MOSFET.

In a future post I will explain the generation of PWM with PIC microcontroller and the calculation for producing the desired duty cycle.

About Siddharth

Siddharth is a Firmware Engineer, techie, and a movie-buff. His interests include, Programming, Embedded Systems, Linux, Robotics, CV, Carpentry and a lot more. At times, you could see some of his sunday projects converge on release quality. You get to know him on the following social channels.

Check Also


Are you reading the datasheet? What to look for and how to find them!

Did you know that experienced engineers spend up to an hour on every major component …

  • Colin Richardson

    Sorry, this is only my first day at trying to use NPNs and PNPs so please help me understand.. In Diagram 2 and 3 of the “Electronically speaking” section, Does the PNP (Q3) not need to be facing down? So the current can flow that way? Because to me this looks like is blocking the current no matter if it is active or not active. Or have I just completely missed the point of how PNPs and NPNs work?

    • Hi Colin, you are correct. The transistor has to be pointing downwards. The tool I was using then did not have an option to mirror swap the components so I had to rotate it 180 degrees. Sorry about that. But the logic still holds good.

      • Colin Richardson

        Thank you for getting back to me. Your page helped me greatly in understanding the lower levels of what is going on here, but I decided to bite the bullet and purchase a Speed controller. I don’t think I could build one at the scale that I keep finding myself wanting to do (eg, going OTT with things like always). But one day I would like to come back to this and build a nice little H bridge for a cheap £1 motor which doesn’t matter if I accidental blow something up.

Keep in touch with the current trends!
Did you like this article? Sign up and get our latest posts delivered to your inbox!
  We hate spam and never share your details.