Motor speed control using PWM

This article shows how to control the speed of a motor using a technique called Pulse Width Modulation (PWM). There is another simpler way of controlling the speed of a motor and that is by using a variable resistor and control the speed by decreasing power input to the motor, but this is a very rude way , wastes all the power, very difficult to be accurate and there is no way for a Micro controller to vary a pot. So keeping these things in mind PWM technique is found to be more practical and efficient.

I am using a Arduino housing an Atmega328, but literally almost anything can be used. Parts used in this tutorial are listed below:

1. Arduino board

2. L293D Motor diver

3. DC motor

4. 12 Volts, 1 Amp DC source

5. Bread board and connecting wires

Hook up your circuit as shown in the below image:

This is the first time I drew such a diagram so be nice :)

Down here I posted a couple of videos which show the effect of PWM:

Motor without PWM:

If you observe the above one carefully you will notice that the motor changes its direction with a sudden moment while the chance in direction in the below one is pretty smooth.

MOtor with PWM:

So what exactly is PWM:

As the name indicates its changing the width of the pulse. But how is changing the width of some pulse be used in changing the speed of a motor?? Well it all depends on how you use that pulse. In the above circuit the PWM pin is connected to the enable pin of the motor driver. So as long as the pulse is high the motor is enabled and when the pulse is low the power to the motor is disabled and the motor will be running due to its inertia.. So if we repeat this at a high speed with a square pulse the motor will be enabled half of the time and disabled during the other half. So the motor will be running at half of its sped.

Now lets make some changes, decrease the duty cycle of the pulse. This leaves the motor disabled for longer period than it is enabled so the over at speed of the motor will be quiet less. Similar thing will happen when we increase the duty cycle but now the motor is enabled for longer time than its disabled so its speed will increase. I used the analog write function to generate desired pulse widths.

Note:  PWM technique can only reduce the speed of the motor. No matter what (Keeping the fact aside that we can increase power) the full speed of the motor will never be crossed.

Here is some code(sketch) which I used to display PWM of the above videos:

Hope this tutorial helps you in your PWM needs, any comments and questions are welcome in the form below.

This entry was posted in Actuators, Brains, I wanna make a robot, PWM, Tutorials. Bookmark the permalink.

Leave a Reply