// Define pin connections & motor's steps per revolution const int dirPin = 5; const int stepPin = 2; const int enPin = 8; const int stepsPerRevolution = 80; //(400 --> 5mm) void setup() { // Declare pins as Outputs pinMode(stepPin, OUTPUT); pinMode(dirPin, OUTPUT); pinMode(enPin, OUTPUT); delay(200); // Wait digitalWrite(enPin, LOW); // Set motor direction clockwise digitalWrite(dirPin, HIGH); } void loop() { // Spin motor slowly for(int x = 0; x < stepsPerRevolution; x++) { digitalWrite(stepPin, HIGH); delayMicroseconds(250); digitalWrite(stepPin, LOW); delayMicroseconds(250); } delay(1000); // Wait a second /* // Set motor direction counterclockwise digitalWrite(dirPin, LOW); // Spin motor slowly for(int x = 0; x < stepsPerRevolution; x++) { digitalWrite(stepPin, HIGH); delayMicroseconds(2000); digitalWrite(stepPin, LOW); delayMicroseconds(2000); } // Spin motor quickly for(int x = 0; x < stepsPerRevolution; x++) { digitalWrite(stepPin, HIGH); delayMicroseconds(1000); digitalWrite(stepPin, LOW); delayMicroseconds(1000); } delay(1000); // Wait a second */ }