# Controlling the speed of a DC motor

I'm trying to control the speed of a DC motor using the circuit which i have attached along with this code: -

``````int motorSpeed = 30;

int motorPin = 9;

void setup(){

}
void loop(){
analogWrite(motorPin, motorSpeed);
delay(2);
}
``````

The motor runs but I cannot change the speed by adjusting 'motorSpeed' Can anyone see what I'm doing wrong here? Thanks

You seem to be attempting to power the motor from the Arduino.

You need to read up on this.

I tried it by powering it with a 9v dc mains adapter as well but got the same problem.

So are you saying that I can't power it with the arduino? If so what is this guy on about? - http://www.dummies.com/how-to/content/how-to-control-the-speed-of-a-dc-motor-with-the-ar.html

You can only control the speed of a DC motor with PWM if the motor has a significant mechanical load. A unloaded motor will just keep running unaffected during the off parts of the PWM cycle.

Attach a pot to control the PWM value and pinch the motor spindle between your fingers. Then you will feel the speed change.

what is this guy on about?

Making a very poor project probably designed only as an illustration but crap never the less.

thanks. i'll give it a go.

I actually need the motor to spin REALLY slow. Like one revolution every half an hour.

So am i right in thinking a DC motor is not the best option for this?

i think you there is some mistakes in your program... you need to use PWM or use a while loop to control the speed of the motor...in while loop adjust the ON and OFF time of the pin 9.. if you increase the ON period then the speed of the motor will increase....

ecworks:
i think you there is some mistakes in your program… you need to use PWM or use a while loop to control the speed of the motor…in while loop adjust the ON and OFF time of the pin 9… if you increase the ON period then the speed of the motor will increase…

analogWrite() does PWM, pin 9 is one of the PWM pins - I don’t get what you are trying to say? loop() is
called in a while loop for you (well an infinite for loop to be precise).

liamorourke: thanks. i'll give it a go.

I actually need the motor to spin REALLY slow. Like one revolution every half an hour.

So am i right in thinking a DC motor is not the best option for this?

You mean you need a geared down motor?

Can you explain your requirements more fully (with actual numbers, that means)?

I actually need the motor to spin REALLY slow. Like one revolution every half an hour.

So am i right in thinking a DC motor is not the best option for this?

A DC motor is not any sort of option for this requirement. It is not possible to slow down a DC motor that much.

I think the problem here is that you don't understand the physics or the behavior of dc motors. All dc motors have a rated voltage, current and rpm. If you take a motor rated for an rpm of 1200 at 12V and pwm it with 9 V with a 3.5% duty cycle , it is likely not going to turn at all. If it does turn it is going to try to turn at 42 rpm, if it moves at all. One revolution /half hour = 0.03 rpm. There is nothing you can do with any motor that you are likely to run across in your travels that is going to get you 0.03 rpm. This is a very specialized motor with a very high gear ratio.

1_rpm_gear_motor

Do the math. 1 REV/0.5HOURS = 2 REVS/HOUR 2 REVS /PER HOUR = 0.03 RPM

I have no idea what the rated rpm is for your motor because you have not posted any information about it. The above is just an example.

hi raschemel,as you said we can you pulse width modulation in ardunio controlling the speed of dc motors we can use the potentiometer ,we can control the speed ,how much speed we want we can make it

Yes , you can use a pot with the Map function to control a PWM output.

liamorourke: I actually need the motor to spin REALLY slow. Like one revolution every half an hour.

So am i right in thinking a DC motor is not the best option for this?

Why not try a stepper motor? It's more complicated to control, but since each step is a very precise angle, you can control how quickly/slowly it spins. You'll be able to get down to one rev/30 minutes, but it wouldn't be a completely smooth motion. You can't get a standard brushed DC motor to spin that slowly.

Tell us what you are really doing! This is beginning to sound http://xyproblem.info/ to me...

When you say 1 rev / half hour, do you mean continuously spinning* but very slowly, or could it work if it was stationary for 29m 59s and then did a single turn to do what ever it's supposed to achieve?

(* if such a speed could be described as "spinning")

As MarkT points out, if you explain the actual problem, not the problem with your solution, you'll probably get better help.

1 rev/0.5 hours = 2 revs /per hour = 0.033 rpm

This would have to be a geared motor.