How to avoid jerks between steps when starting and stopping

Hello,

I am a newbie and have made a hanging rotation gadget with Nema17, an Arduino uno and an easy driver 4988 for photographing jewelry products such as a necklace with pendant. I have never written code before, however just wrote one after reading and experimenting.

The issue -

  1. The rotation needs to be very slow, so the hanging necklace does not swing too much between wait states

The motor needs to stop every 10 degrees moving clockwise (more or less depending the number of photographs needed each 360 degree turn)

The motor does it with the current code below, but I have an issue with jerks at start and stop between each step.

I will appreciate some help as I don't seem to be getting anywhere.

Thanks in advance!

Burt

here's the code -

// defines pins numbers
const int stepPin = 3; 
const int dirPin = 4; 
 
void setup() {
  // Sets the two pins as Outputs
  pinMode(stepPin,OUTPUT); 
  pinMode(dirPin,OUTPUT);
}
void loop() {
  digitalWrite(dirPin,LOW); // Enables the motor to move in a particular direction
  // Makes pulses for making one full cycle rotation
  for(int x = 0; x < 6; x++) 
  {
    analogWrite(stepPin,HIGH); 
    delayMicroseconds(500); 
    digitalWrite(stepPin,LOW); 
    delayMicroseconds(500); 
  }
  delay(5000); // five second delay
}

Have you tried micostepping the motor? Steps can be much smaller, that might reduce the swinging.

Thanks. it is the motion between steps. Starts with a jerk that makes the product swing too much and photo becomes blurry

The AccelStepper library can use acceleration. So the motion from start to speed and speed to stop is much smoother. Not so much jerking.

From the Original Post ...

analogWrite(stepPin,HIGH);

That should be digitalWrite()

...R

You almost certainly want acceleration/ramping with a NEMA17 motor, you always do with larger
steppers, I'd advise learning the AccelStepper library, its pretty flexible and does the tedious stuff
for you.