I just bought the following stepper motor and im running the following code for it. It seems like by adjusting the delaymicroseconds on lines 12/14 adjusts the speed of the stepper motor. Is this the proper way of adjusting the speed of the stepper motor?
How would i go about making the stepper motor rotate 1.60463 RPM? Not sure how accurate you can make the stepper motor but from from calculations thats the speed i need it to be for what i need it for.
Also, the distance on line 18 i have set at 1600 for 1 full rotation for the stepper motor. But that is just to the eye what seems to be one full rotation. How do i know what value to input into there for an accurate 1 full rotation?
Thanks,
int Distance = 0; // Record the number of steps we've taken
void setup() {
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
}
void loop() {
digitalWrite(9, HIGH);
delayMicroseconds(70); //70 minimal
digitalWrite(9, LOW);
delayMicroseconds(70); //70 minimal
Distance = Distance + 1; // record this step
// Check to see if we are at the end of our move
if (Distance == 32000)
{
// We are! Reverse direction (invert DIR signal)
if (digitalRead(8) == LOW)
{
digitalWrite(8, HIGH);
}
else
{
digitalWrite(8, LOW);
}
// Reset our distance back to zero since we're
// starting a new move
Distance = 0;
// Now pause for half a second
delay(500);
}
}