Go Down

Topic: Start and stop of bipolar stepper motor (Read 12124 times)previous topic - next topic

snapshots

Jan 15, 2012, 02:01 amLast Edit: Jan 15, 2012, 05:57 am by snapshots Reason: 1
Hi i am controlling a stepper motor with a driver... how can i stop a stepper motor from spinning when it reach my desired position.. e.g when i say go to 180 degrees it will turn to 180 degrees and stop der.. stepper is controlled with clock and direction pin. my stepper is a 1.8 degree bipolar stepper motor so 200 steps for 1 rev.

sample code

Code: [Select]
`int dirPin = 3;int clkPin = 2;void setup(){  pinMode(dirPin,OUTPUT);pinMode(clkPin,OUTPUT);digitalWrite(dirPin,HIGH);digitalWrite(clkPin,LOW);}void loop(){digitalWrite(dirPin,HIGH);   //CLOCKWISEfor(int x=0;x<100;x++){ // 100 * 1.8 = 180digitalWrite(clkPin,HIGH);delayMicroseconds(1000);digitalWrite(clkPin,LOW);delayMicroseconds(1000);}}`

say after executing the loop the stepper must stop to that position. how will i do it?.. because it just keeps on spinning.

I just need to know how to stop it when it reach my desired position because i'll be adding buttons to control it but first i need how stop it.

Thanks a lot.

kf2qd

#1
Jan 15, 2012, 04:21 am
Your stepper keeps spinning because you are continuing to send it step pulses.

Loop continues to run because its a loop. Outside of the program is a main() that calls loop repeatedly.

What signal are you using to start the step sequence?

Suggestion - the motor control sequence should be in a function of its own. To move the motor you call that function and the motor would move.

You might have 2 buttons for forward and reverse - you set direction to 0 or 1 and then call the move function.

You might consider making your function take an argument for the number of steps. makes it a bit more universal.

For now you could call your motor function from setup and it will run just once.

snapshots

#2
Jan 15, 2012, 05:55 am
wow thanks didn't know that .. it's working now.. now i want to move the stepper in 5 different position using 5 buttons.. 1 - 90 degrees, 2 - 180 degrees, 3 - 270 degrees, 4 - 360 degrees, 5 - random angle from the ff. angle.. 90,180,270,360..

can i use this setup so i can save arduino pins?.. http://tronixstuff.wordpress.com/2011/01/11/tutorial-using-analog-input-for-multiple-buttons/

And how will i know the absolute position of my motor so every press of a button it will return to it's initial position and go to the position of the pressed button?.

Let's say i want the initial position to be on top always.. so it's 0 degrees.

sample code.

Code: [Select]
`if(button1=HIGH){go to 0 degrees then turn 90 degrees}if(button2=HIGH){go to 0 degrees then turn 180 degrees}`

kf2qd

#3
Jan 16, 2012, 03:14 am
Unless you have some sort of homing switch you have no way of knowing where the motor is other than looking at it. As far as keeping track of position, you will have to have a counter that you can use to monitor the current position. For a 200 step motor - 50 full steps = 90 degrees.

Sounds like button 1 - go to 0 degrees, then move to 90 degrees?
button 2 go to 0 degrees then move to 180 degrees

and such?

You can use the step routines, or create your own. Not very hard to do.

Go Up