Hi all, I'm new to Arduino and need some advice regarding my project. I'm trying to use a stepper motor to perform very specific set of movements (rotate CW 90, CCW 180, etc etc), it's not precise to the point of 3d printing, but it needs to be as fast as possible (fastest acceleration/deceleration the motor can provide).
I've included my schematic and very simple code below. I'm running 5V through a Nema17HS4023 (1A, 4.1V).
Right now I just want my code to rotate the motor accurately and quickly from 0-90, and then 90-0. Such that for every loop, the motor should've returned back to the same starting position.
On start up, the motor starts sweeping correctly, but quickly ends up going to a non-0 position, because it stops turning the full 90 degrees. Sometimes it also makes whining noises and stop alternating movements completed. Is this code, or misstep, or vRef issue?
Any guidance much appreciated.
#include <MobaTools.h>
const int stepPin = 9;
const int dirPin = 8;
const int stepsPerRev = 200;
MoToStepper stepper( stepsPerRev, STEPDIR );
void setup()
{
stepper.attach( stepPin, dirPin );
stepper.setSpeed(2500);
stepper.setRampLen( stepsPerRev / 2);
Serial.begin(9600);
stepper.setZero();
}
void loop()
{
Serial.println("clockwise");
stepper.write(90);
while ( stepper.moving() ); // wait
delay(500);
Serial.println("Counter clockwise");
stepper.write(-90);
while ( stepper.moving() ); // wait
delay(500);
}