// Sketch by R. Jordan Kreindler, written September 2016, to rotate // a stepper motor using the Half Step Method in a counter-clockwise // direction, i.e., opposite from that in the previous sketch // To do this, the order of the pin assignments is reversed. int aPin = 5; //IN1: first end of the blue and yellow stator coil int bPin = 4; //IN2: first end of the pink and orange stator coil int aPrimePin = 3; //IN3: second end of the blue and yellow stator coil int bPrimePin = 2; //IN4: second end of the pink and orange stator coil // We do not connect IN5, IN6, or IN7 int delay1 = 3; void setup() { // Set all pins as output to send output signals from the Arduino // UNO to the coil windings of the stator pinMode(aPin, OUTPUT); pinMode(bPin, OUTPUT); pinMode(aPrimePin, OUTPUT); pinMode(bPrimePin, OUTPUT); // Start with all coils off digitalWrite(aPin, LOW); digitalWrite(bPin, LOW); digitalWrite(aPrimePin, LOW); digitalWrite(bPrimePin, LOW); } void loop() { // Send current to // 1. The aPin // 2. The aPin, and the bPin // 3. The bPin // 4. Then to the bPin and the aPrimePin // 5. Then to the aPrimePin // 6. Then to the aPrimePin and the bPrime Pin // 7. Then to the bPrimePin // 8. Then the bPrimePin and the aPin. // Thus producing steps using the half step method // 1. Set the aPin High digitalWrite(aPin, HIGH); digitalWrite(bPin, LOW); digitalWrite(aPrimePin, LOW); digitalWrite(bPrimePin, LOW); // Allow some delay between energizing the coils to allow // the stepper rotor time to respond. delay(delay1); // So, delay1 microseconds // 2. Energize aPin and bPin to HIGH digitalWrite(aPin, HIGH); digitalWrite(bPin, HIGH); digitalWrite(aPrimePin, LOW); digitalWrite(bPrimePin, LOW); // Allow some delay between energizing the coils to allow // the stepper rotor time to respond. delay(delay1); // So, delay1 microseconds // 3. Set the bPin to High digitalWrite(aPin, LOW); digitalWrite(bPin, HIGH); digitalWrite(aPrimePin, LOW); digitalWrite(bPrimePin, LOW); // Allow some delay between energizing the coils to allow // the stepper rotor time to respond. delay(delay1); // So, delay1 microseconds // 4. Set the bPin and the aPrimePin to HIGH digitalWrite(aPin, LOW); digitalWrite(bPin, HIGH); digitalWrite(aPrimePin, HIGH); digitalWrite(bPrimePin, LOW); // Allow some delay between energizing the coils to allow // the stepper rotor time to respond. delay(delay1); // So, delay1 microseconds // 5. Set the aPrime Pin to high digitalWrite(aPin, LOW); digitalWrite(bPin, LOW); digitalWrite(aPrimePin, HIGH); digitalWrite(bPrimePin, LOW); // Allow some delay between energizing the coils to allow // the stepper rotor time to respond. delay(delay1); // So, delay1 microseconds // 6. Set the aPrimePin and the bPrime Pin to HIGH digitalWrite(aPin, LOW); digitalWrite(bPin, LOW); digitalWrite(aPrimePin, HIGH); digitalWrite(bPrimePin, HIGH); // Allow some delay between energizing the coils to allow // the stepper rotor time to respond. delay(delay1); // So, delay1 microseconds // 7. Set the bPrimePin to HIGH digitalWrite(aPin, LOW); digitalWrite(bPin, LOW); digitalWrite(aPrimePin, LOW); digitalWrite(bPrimePin, HIGH); // Allow some delay between energizing the coils to allow // the stepper rotor time to respond. delay(delay1); // So, delay1 microseconds // 8. Set the bPrimePin and the aPin to HIGH digitalWrite(aPin, HIGH); digitalWrite(bPin, LOW); digitalWrite(aPrimePin, LOW); digitalWrite(bPrimePin, HIGH); // Allow some delay between energizing the coils to allow // the stepper rotor time to respond. delay(delay1); // So, delay1 microseconds }