// Stepper motor on Wokwi!
#include <Stepper.h>
const int stepsPerRevolution = 200; // Change this to fit the number of steps per revolution for your motor
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
myStepper.setSpeed(60);
Serial.begin(9600);
}
void loop() {
// Start or stop at 0 degrees with a pause for 1 second
Serial.println("Pause at 0 degrees");
delay(1000);
// Rotate to 180 degrees clockwise
Serial.println("Clockwise 180 degrees");
myStepper.step(stepsPerRevolution / 2); // 180 degrees is half of a full revolution
delay(500);
// Rotate another 90 degrees clockwise (total 270 degrees)
Serial.println("Clockwise 90 degrees");
myStepper.step(stepsPerRevolution / 4); // 90 degrees is one-fourth of a full revolution
delay(500);
// Pause for 0.5 seconds
Serial.println("Pause for 0.5 seconds");
delay(500);
// Rotate 270 degrees counter-clockwise to return to 0 degrees
Serial.println("Counter-clockwise 270 degrees");
myStepper.step(-stepsPerRevolution * 3 / 4); // 270 degrees is 3/4 of a full revolution
delay(500);
}