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
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); //CLOCKWISE
for(int x=0;x<100;x++){ // 100 * 1.8 = 180
digitalWrite(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.