Hi all, I'm confusing on the push button control stepper motor. My requirement is to control a stepper motor to turn CW or CCW using a push button. So that, when the push button is pressed, the stepper motor will turn CW or CCW until the button is released. Then after the stepper motor was move to the required position, another push button is press to execute the code below. Please advise me to do so. Thanks.
// Define stepper motor connections and steps per revolution:
#define enaPin 10
#define dirPin 11
#define stepPin 12
void setup() {
// Declare pins as output:
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
}
void loop() {
// Set the spinning direction clockwise:
digitalWrite(dirPin, HIGH);
// Spin the stepper motor 1 revolution slowly:
for (int i = 0; i < 200; i++) {
// These four lines result in 1 step:
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
}
delay(300);
// Set the spinning direction counterclockwise:
digitalWrite(dirPin, LOW);
// Spin the stepper motor 1 revolution quickly:
for (int i = 0; i < 200; i++) {
// These four lines result in 1 step:
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
}
delay(300);
}
Hi,
Can you please post a circuit diagram?
Show power supplies.
You are using microsecond delays, make the pulse bigger, give you stepper a chance to respond to commands.
100us is very very small. = 5Mhz for a 200us period.
Try;
delay(100);
100ms it will let you see if the stepper is being activated or not.
Can you please post a link to stepper data/specs?
Could u just give an example on how to write the coding so that when the power is on. The stepper is remain in offstate until I press and hold the button, then it move. After released, it stop. Thanks