#include /* A 4 wire bipolar, or 5 or 6 wire unipolar stepper motor drives a 1mm pitch threaded rod that rotates a camera mount arm, approximating the siderial rate (15.0401 deg/hour), for extended exposures of the night sky. Forward, Reverse and Stop are controlled by a 3 position switch. Reverse returns the camera arm to it's starting point at 60RPM until contacting a kill switch: The Forward function overrides the kill switch. If intending to use a unipolar motor, uncomment #define motorPin1 8 through 11, and comment the lines #define motorPin1 4 through 7. It is also possible to drive a unipolar motor without the centre tap. Identify the coils and connect as a bipolar. Note: it may be necessary to change the motorSteps line to suit your stepper; e.g., if your stepper has 200 steps, set the line to #define motorSteps 200 An LED flashes while reversing and is steady while the drive is stopped. Selecting Serial Monitor will print out the time that the program has run. */ // global int pinval2; // pin2 value HIGH or LOW int pinval3; // pin3 value HIGH or LOW int Pin2 = 2; // Pin2 INPUT, HIGH, pull-up resistors int Pin3 = 3; // Pin3 INPUT, pull-up resistors int ledPin = 13; #define motorSteps 400 #define motorPin1 4 #define motorPin2 5 #define motorPin3 6 #define motorPin4 7 /* Uncomment to use unipolar motor #define motorPin1 8 #define motorPin2 9 #define motorPin3 10 #define motorPin4 11 */ // initialize Stepper library: Stepper Stepper1(motorSteps, motorPin1,motorPin2,motorPin3,motorPin4); void setup(){ pinMode(Pin2, INPUT); // define as input pinMode(Pin3, INPUT); digitalWrite(Pin2, HIGH); // activate pull-up resistors digitalWrite(Pin3, HIGH); pinMode(ledPin, OUTPUT); } void loop(){ { // forward digitalWrite(ledPin, LOW); // turn LED off pinval2 = digitalRead(Pin2); // read Pin value pinval3 = digitalRead(Pin3); if (pinval2 == HIGH && pinval3 == HIGH) // check Pin values { Stepper1.setSpeed(1.0); Stepper1.step(1); } else { // stop pinval2 = digitalRead(Pin2); pinval3 = digitalRead(Pin3); if (pinval2 == HIGH && pinval3 == LOW) { digitalWrite(ledPin, HIGH); // turn LED on Stepper1.setSpeed(0); Stepper1.step(0); } else { // reverse pinval2 = digitalRead(Pin2); pinval3 = digitalRead(Pin3); if (pinval2 == LOW && pinval3 == LOW) { digitalWrite(ledPin, HIGH); Stepper1.setSpeed(60); Stepper1.step(-1); } } } } }