#include <Stepper.h>
const int stepsPerRevolution = 200;
const int stepsPer90Degrees = 50;
Stepper stepper(stepsPerRevolution, 8 ,9 , 10, 11);
const int switch1 = 2;
const int switch2 = 3;
void setup() {
pinMode(switch1, INPUT);
pinMode(switch2, INPUT);
stepper.setSpeed(60);
Serial.begin(9600);
Serial.println("Stepper Motor Control with Switches");
}
void loop() {
if (digitalRead(switch1) == HIGH) {
Serial.println("Switch 1 pressed: Rotating clockwise...");
for (int i = 0; i < 4; i++) {
stepper.step(stepsPer90Degrees);
delay(500);
}
}
if (digitalRead(switch2) == HIGH) {
Serial.println("Switch 2 pressed: Rotating counterclockwise...");
for (int i = 0; i < 4; i++) {
stepper.step(-stepsPer90Degrees);
delay(500);
}
}
}