#include <Stepper.h>
// Define the number of steps per revolution for your stepper motor
const int STEPS_PER_REVOLUTION = 200; // Change this according to your motor
// Define the connections to the A4988 motor driver
const int STEP_PIN = 8;
const int DIR_PIN = 7;
// Initialize the stepper motor object
Stepper stepper(STEPS_PER_REVOLUTION, STEP_PIN, DIR_PIN);
// Define the desired angle to turn the stepper motor
const float DESIRED_ANGLE = 90.0; // Change this to your desired angle
void setup() {
// Set the speed of the stepper motor
stepper.setSpeed(300); // Adjust this according to your motor
}
void loop() {
// Calculate the number of steps needed to reach the desired angle
int stepsToTake = (DESIRED_ANGLE / 360.0) * STEPS_PER_REVOLUTION;
// Move the stepper motor to the desired position
stepper.step(stepsToTake);
DESIRED_ANGLE =0;
// Wait for a moment before moving to the next angle
delay(1000); // Adjust this delay as needed
}