// Define pin numbers const int dirPin = 1; // direction const int stepPin = 2; // step const int enaPin = 3; // enable void setup() { // Define all pins at output pinMode(stepPin, OUTPUT); pinMode(dirPin, OUTPUT); pinMode(enaPin, OUTPUT); // Enable the motor driver digitalWrite(enaPin, LOW); } void loop() { digitalWrite(dirPin, HIGH); // Set the rotation to one particular direction // Perform 2000 steps for (int x = 0; x < 2000; x++) { // Generate a pulse digitalWrite(stepPin, HIGH); delayMicroseconds(700); digitalWrite(stepPin, LOW); delayMicroseconds(700); } delay(1000); // Wait for a second digitalWrite(dirPin, LOW); // Set the rotation to the other direction // Perform 2000 steps for (int x = 0; x < 2000; x++) { // Generate a pulse digitalWrite(stepPin, HIGH); delayMicroseconds(700); digitalWrite(stepPin, LOW); delayMicroseconds(700); } delay(1000); // Wait for a second }