// Define pin connections & motor's steps per revolution const int dirPin = 7; const int stepPin = 4; const int enPin = 8; const int stepsPerRevolution = 400; const int endPin = 11; void setup() { // Declare pins as Outputs pinMode(stepPin, OUTPUT); pinMode(dirPin, OUTPUT); pinMode(enPin, OUTPUT); pinMode(endPin, INPUT_PULLUP); delay(200); // Wait digitalWrite(enPin, LOW); // Set motor direction clockwise digitalWrite(dirPin, LOW); } void loop() { while (digitalRead(endPin) == HIGH) { digitalWrite(stepPin, HIGH); delayMicroseconds(250); digitalWrite(stepPin, LOW); delayMicroseconds(250); } // 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*/ }