/*
Arduino | coding-help
koyo — 10/3/25 8:03 PM
Mt stepper motor is moving so weirdly and slow can someone check my code?
*/
// Include the AccelStepper Library
#include <AccelStepper.h>
// Define pin connections
const int dirPin = 6;
const int stepPin = 5;
const int sleepPin = 7;
const int resetPin = 8;
// Define motor interface type
#define motorInterfaceType 1
// Creates an instance
AccelStepper myStepper(motorInterfaceType, stepPin, dirPin);
void setup() {
// set the maximum speed, acceleration factor,
// initial speed and the target position
digitalWrite(resetPin, HIGH);
digitalWrite(sleepPin, HIGH);
myStepper.setMaxSpeed(1000);
myStepper.setAcceleration(50);
myStepper.setSpeed(200);
myStepper.moveTo(200);
}
void loop() {
// Change direction once the motor reaches target position
if (myStepper.distanceToGo() == 0)
myStepper.moveTo(-myStepper.currentPosition());
// Move the motor one step
myStepper.run();
}