// Define pin numbers
const int buttonPin = 2; // Connect your push button to this pin
const int stepPin = 3; // Connect A4988 driver STEP pin to this pin
const int dirPin = 4; // Connect A4988 driver DIR pin to this pin
// Variables for stepper motor control
int stepsPerRevolution = 10; // Change this according to your motor's specifications
int steps = 0;
int stepDelay = 250; // Adjust this for your desired speed
void setup() {
pinMode(buttonPin, INPUT);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
}
void loop() {
int buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
// Button is pressed, turn one revolution
digitalWrite(dirPin, HIGH); // Set direction to clockwise
for (int i = 0; i < stepsPerRevolution; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(stepDelay);
digitalWrite(stepPin, LOW);
delayMicroseconds(stepDelay);
}
delay(10); // Pause for a moment before allowing another revolution
}
}