# DC Motor speed control

Hello

I need information about controlling the speed of a DC motor by using Arduino. I searched for examples on Internet and even tried some of them, but they didn`t work, so I would like if any of you can give me some concrete and working examples.

What I need is to create a circuit where I can control the speed of a DC motor from computer. I need this control to be as precise as possible, so some motor types which are very precise would help me too.

Until now, I tried to build a circuit using a H-Bridge (SN754410 H-bridge) and I made my motor to move forward and backward. But this is not enough, as I need to program its moves from my computer. I have seen that PWM might be a solution, but I don`t really understand it, so maybe some of you can give me some accurate links on it (which are in connection to the DC motor and Arduino, of course).

Have you looked in the Playground?

Here is an example of PWMing an h-bridge to change the speed. (Edit: it uses a pot as input to set the speed; that could easily be changed to be a command from your PC via Serial.)

All PWM is, is a very very fast off-ing and on-ing of a pin. It switches the pin between 0-5-0 very fast, and gives the "illusion" of a voltage between 0 and 5. The quasi-voltage depends on the amount of on-time, so if it's switched so that it's off half the time and off half the time, it will be as if it had 2.5V. On for say 90% of the time will be 0.9 x 5V = 4.5V. It's NOT 4.5V of course, it's actually 0 or 5, but the proportion of on-time gives the illusion of a voltage between 0 and 5.

For Arduino, an analogWrite(pin, value) will do that on PWM-enabled pins (not all digital pins do PWM: look for the ~ symbol). The value is 0 to 255 where 0 is "0V" and 255 is "5V".

Hi jimboZA
Can you please tell us more about replacing the pot with commands?
Du you have any references ?