// Stepper motor on Wokwi!
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
int button1 = 2;
int button2 = 4;
int button3 = 3;
int button4 = 5;
int stepCount = 0;
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
pinMode (button1, INPUT_PULLUP);
pinMode (button2, INPUT_PULLUP);
pinMode (button3, INPUT_PULLUP);
pinMode (button4, INPUT_PULLUP);
// set the speed at 60 rpm:
myStepper.setSpeed(30);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
if (digitalRead (button3) == LOW)
{
myStepper.step(1);
Serial.print("steps:");
Serial.println(stepCount);
stepCount++;
delay(1);
}
if (digitalRead (button4) == LOW)
{
myStepper.step(-1);
Serial.print("steps:");
Serial.println(stepCount);
stepCount++;
delay(1);
}
if (digitalRead (button1) == LOW)
{
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(10);
}
if (digitalRead (button2) == LOW)
{
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(10);
}
}