Go Down

Topic: Running a DC motor with PWM (Read 3 times) previous topic - next topic

Jason2548

Hello. I am really new to this and just trying to figure out some things so that I can have some fun.  I have been messing around with the PWM and have been wanting to get a DC motor to ramp up slowly and stay at Full speed until I tell it to Slow down.  Kinda like a soft start up.  I can get it to ramp up but then when it goes through the loop again it starts at 0 and comes back up to 255 over and over.  I want it to stop at 255 until I tell it to slow down. 

LarryD

You can do a digital write from 0 to 255 with some add delay() then repeat.
EX:

loop()
for (int x=1; x<256;x++)
{
// look at the digital write code & place here
// add some delay for the motor to move
}
// maybe some more delay to stop at 255 for a bit
The way you have it in your schematic isn't the same as how you have it wired up!

Jason2548

I don't want it do go down on its own.  I want it to go up and then stay up

LarryD

Quote
loop()
for (int x=1; x<256;x++)
{
// look at the digital write code & place here
// add some delay for the motor to move
}

Place the above in setup()
In loop() look at a digital i/p switch use an 'if' statement, then run a 'for' loop to slow down your motor.
The way you have it in your schematic isn't the same as how you have it wired up!

MAS3

Hi Jason2548.

The for.. loop will count until a set value.
If you are in a loop (like void loop), you will always start at the initial value (here 1) and end up with the final value (255), and do that over and over again.

So to get rid of that, you can set the initial value for X in void setup.
In void loop you will increase X every time, until you reach your end value.
In that case you will not increase, because increasing will get to 0 again (an overflow will occur).

By the way:
You'll see that your motor will not start running immediatly.
It might start at 20 % or later.
And it might also reach its maximum speed before it's at 255, but that will be hard to find out.
So it would be nice for your experiment to keep track of where you are when the motor starts running.
You can do that using a display or using serial and a terminal to see the output.
You would also need to slow down the update rate of your PWM, because else you will hardly see the speed ramping up.
Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html

Go Up