#define STEP_PIN 9 // Pin connected to STEP
#define DIR_PIN 10 // Pin connected to DIR
#define ENABLE_PIN 2 // Pin connected to ENABLE
void setup() {
pinMode(STEP_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
pinMode(ENABLE_PIN, OUTPUT);
// Enable the motor driver
digitalWrite(ENABLE_PIN, LOW); // LOW = enabled
}
void loop() {
// Rotate clockwise
digitalWrite(DIR_PIN, HIGH); // Set direction to clockwise
for (int i = 0; i < 400; i++) { // 200 steps for one full rotation (depends on your motor)
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(20000); // Adjust speed: lower delay = faster speed
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(20000);
}
delay(1000); // Wait 1 second
// Rotate counterclockwise
digitalWrite(DIR_PIN, LOW); // Set direction to counterclockwise
for (int i = 0; i < 200; i++) {
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(800);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(800);
}
delay(1000); // Wait 1 second
}