Arduino Forum

Using Arduino => General Electronics => Topic started by: liamorourke on Mar 31, 2016, 11:26 am

Title: Controlling the speed of a DC motor
Post by: liamorourke on Mar 31, 2016, 11:26 am
I'm trying to control the speed of a DC motor using the circuit which i have attached along with this code: -
Code: [Select]

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
Title: Re: Controlling the speed of a DC motor
Post by: Paul__B on Mar 31, 2016, 11:42 am
(http://forum.arduino.cc/index.php?action=dlattach;topic=390379.0;attach=161155)


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

You need to read up on this.
Title: Re: Controlling the speed of a DC motor
Post by: liamorourke on Mar 31, 2016, 12:06 pm
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
Title: Re: Controlling the speed of a DC motor
Post by: Grumpy_Mike on Mar 31, 2016, 12:49 pm
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.

Quote
what is this guy on about?
Making a very poor project probably designed only as an illustration but crap never the less.
Title: Re: Controlling the speed of a DC motor
Post by: liamorourke on Mar 31, 2016, 12:56 pm
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?
Title: Re: Controlling the speed of a DC motor
Post by: ecworks on Mar 31, 2016, 01:14 pm
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....
Title: Re: Controlling the speed of a DC motor
Post by: MarkT on Mar 31, 2016, 02:29 pm
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).
Title: Re: Controlling the speed of a DC motor
Post by: MarkT on Mar 31, 2016, 02:30 pm
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)?
Title: Re: Controlling the speed of a DC motor
Post by: Grumpy_Mike on Mar 31, 2016, 03:35 pm
Quote
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.
Title: Re: Controlling the speed of a DC motor
Post by: raschemmel on Mar 31, 2016, 08:54 pm
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 (https://www.servocity.com/html/1_rpm_gear_motor.html)

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.
Title: Re: Controlling the speed of a DC motor
Post by: dhiraj421 on Mar 31, 2016, 09:22 pm
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
Title: Re: Controlling the speed of a DC motor
Post by: raschemmel on Mar 31, 2016, 10:24 pm
@dhiraj421,
This is not your thread. I'll answer your question this time but in the future start your own post if your question is not related to the OP's post.

Yes , you can use a pot with the Map function to control a PWM output.
Title: Re: Controlling the speed of a DC motor
Post by: anarchy_1024 on Apr 01, 2016, 09:30 am
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.
Title: Re: Controlling the speed of a DC motor
Post by: MarkT on Apr 01, 2016, 07:55 pm
Tell us what you are really doing!  This is beginning to sound http://xyproblem.info/ (http://xyproblem.info/) to me...
Title: Re: Controlling the speed of a DC motor
Post by: pwillard on Apr 01, 2016, 08:18 pm
(https://pptcrafter.files.wordpress.com/2013/01/gears-3.png)
Title: Re: Controlling the speed of a DC motor
Post by: JimboZA on Apr 02, 2016, 05:47 am
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.


Title: Re: Controlling the speed of a DC motor
Post by: raschemmel on Apr 02, 2016, 07:18 am
1 rev/0.5 hours = 2 revs /per hour = 0.033 rpm

This would have to be a geared motor.