// Motor 1 pins
const int dirPin1 = 2;
const int stepPin1 = 3;
// Motor 2 pins
const int dirPin2 = 4;
const int stepPin2 = 5;
const int stepsPerRevolution = 200;
void setup() {
// Set pin modes for motor 1
pinMode(stepPin1, OUTPUT);
pinMode(dirPin1, OUTPUT);
// Set pin modes for motor 2
pinMode(stepPin2, OUTPUT);
pinMode(dirPin2, OUTPUT);
}
void loop() {
// Both motors forward
digitalWrite(dirPin1, HIGH);
digitalWrite(dirPin2, HIGH);
for (int i = 0; i < stepsPerRevolution; i++) {
digitalWrite(stepPin1, HIGH);
digitalWrite(stepPin2, HIGH);
delayMicroseconds(800);
digitalWrite(stepPin1, LOW);
digitalWrite(stepPin2, LOW);
delayMicroseconds(800);
}
delay(1000);
// Both motors backward
digitalWrite(dirPin1, LOW);
digitalWrite(dirPin2, LOW);
for (int i = 0; i < stepsPerRevolution; i++) {
digitalWrite(stepPin1, HIGH);
digitalWrite(stepPin2, HIGH);
delayMicroseconds(800);
digitalWrite(stepPin1, LOW);
digitalWrite(stepPin2, LOW);
delayMicroseconds(800);
}
delay(1000);
}