// Define pin connections
const int dirPin = 2;
const int stepPin = 3;
const int stepsPerRevolution = 200; // Adjust if using microstepping
void setup() {
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
}
void loop() {
// Rotate clockwise
digitalWrite(dirPin, HIGH);
for(int i = 0; i < stepsPerRevolution; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(800); // Speed control
digitalWrite(stepPin, LOW);
delayMicroseconds(800);
}
delay(1000); // Wait a second
// Rotate counter-clockwise
digitalWrite(dirPin, LOW);
for(int i = 0; i < stepsPerRevolution; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(800);
digitalWrite(stepPin, LOW);
delayMicroseconds(800);
}
delay(1000); // Wait a second
}