Hi everyone, I have 2 step motors (28BYJ-48) that I have moving clockwise and counter clockwise 180 degrees. They are at the perfect speed, and the arc looks great. my problem is that they are not running simultaneously. Is there a way to do this in my current code? Thank you!
#include <Stepper.h>
const int stepsPerMotorRevolution = 32; //No of steps per internal revolution of motor,
//4-step mode as used in Arduino Stepper library
const int stepsPerOutputRevolution = 32*64; //no of steps per revolution of the output shaft
const int motorpin1 = 8; //Assign motor (ie board) pins to Arduino pins
const int motorpin2 = 9; //
const int motorpin3 = 10; //
const int motorpin4 = 11; //
const int motorpin5 = 4; //Assign motor (ie board) pins to Arduino pins
const int motorpin6 = 5; //
const int motorpin7 = 6; //
const int motorpin8 = 7; //
// initialize the stepper library on pins 8 through 11, Motor rev steps, "Firing" sequence 1-3-2-4,
Stepper myStepper1(stepsPerMotorRevolution, motorpin1,motorpin3,motorpin2,motorpin4);
Stepper myStepper2(stepsPerMotorRevolution, motorpin5,motorpin7,motorpin6,motorpin8);
void setup() {
// Stepper library sets pins as output
myStepper1.setSpeed(600); //Set the speed
Serial.begin(9600); // initialize the serial port:
myStepper2.setSpeed(600);
Serial.begin(9600);
}
// MAIN LOOP +++++++++++++++++++
void loop() {
// Half revolution clockwise
Serial.println("clockwise 1/2 rev");
myStepper1.step(stepsPerOutputRevolution/2);
delay(10);
// Half revolution counterclockwise
Serial.println("counterclockwise clockwise 1/2 rev");
myStepper1.step(-stepsPerOutputRevolution/2);
delay(10);
// Half revolution clockwise
Serial.println("counterclockwise 1/2 rev");
myStepper2.step(-stepsPerOutputRevolution/2);
delay(10);
// Half revolution counterclockwise
Serial.println("clockwise 1/2 rev");
myStepper2.step(stepsPerOutputRevolution/2);
delay(10);
}