#define Step_pin 16
#define Dir_pin 17
#define speed 5000
const int stepsPerRevolutions = 200;
void setup() {
// put your setup code here, to run once:
pinMode(Step_pin,OUTPUT);
pinMode(Dir_pin, OUTPUT);
digitalWrite(Dir_pin, HIGH); //set initial direction to clockwise
}
void loop() {
// put your main code here, to run repeatedly:
for (int i = 0; i < stepsPerRevolutions; i++) {
digitalWrite(Step_pin, HIGH);
delayMicroseconds(speed); //adjust this to control motor speed
digitalWrite(Step_pin, LOW);
delayMicroseconds(speed);
}
delay(1000); //wait for 1 second
digitalWrite(Dir_pin, LOW); //change direction to anti-clockwise
for (int i = 0; i < stepsPerRevolutions; i++) {
digitalWrite(Step_pin, HIGH);
delayMicroseconds(speed); //adjust this to control motor speed
digitalWrite(Step_pin, LOW);
delayMicroseconds(speed);
}
delay(1000); //wait for 1 second before loop
digitalWrite(Dir_pin, HIGH);
}