Inconsistent stepper motor -- tried everything

I am using a Nema 17 Planetary Geared Stepper Motor with 1.8 degree steps. Below is the simple code I have for it to rotate. It is programmed to go clockwise almost 180 degrees and pause, then slightly more clockwise and pause, then return to its original position by turning counterclockwise.

#include <Stepper.h>

const int stepsPerRevolution = 200;
const double gearRatio = 99.0506;

//initialize stepper
Stepper myStepper(stepsPerRevolution, 8,9,10,11);

void setup() {
  //set stepper speed
  myStepper.setSpeed(240); // 240 rpm

  myStepper.step(stepsPerRevolution*gearRatio / 100);



void loop() {

  //turn clockwise
  myStepper.step(stepsPerRevolution*gearRatio / 2); //2
  myStepper.step(stepsPerRevolution*gearRatio / 10); //10


  //turn counterclockwise
  myStepper.step(-stepsPerRevolution*gearRatio / 1.82); //1.82


This was the only configuration I set up where the motor would be consistent. Any other change and the motor would vary its rotation for no reason. I even just changed the length of the second delay (underlined above) to delay(5000) and the rotation was different each time. I changed boards, I rewired several times, I played with the rotation values, and nothing has worked.

Please post links to the data sheets or product pages for the stepper motor and motor driver you are using, and post a hand drawn wiring diagram.

What is the voltage and current rating of the motor power supply you are using?

If using a current limiting motor driver, to what value did you adjust the current limit?

Attached to this reply is an image of the motor specifications sheet.

EDIT: here is a link to the data sheet

This was the only configuration I set up where the motor would be consistent. Any other change and the motor would vary its rotation for no reason

As well as what @jremington said, you need to post the program that does not work properly - no point fixing a working program :slight_smile:


Image from Reply #2 so we don't have to download it. See this Simple Image Guide


Hey. c'mon. Give us a break - don't post a picture of a crumpled piece of paper. Just post the relevant data. Better still, post a link to the website with the datasheet.

Also answer @jremington's other questions.


Attached to this reply is an image of the circuit diagram. From what I have seen online, all of the wiring is correct.

I don't know who ordered the motor so I am unsure where to find it online. I think this is the same product:

Also the program works but the motor operates inconsistently. That's my problem. I wish everything would work how it should, but I can't understand what is going wrong. Sometimes the motor will overstep at an increasing rate, so each cycle gets more and more off course.

The power supply is rated as 12V and 2.0A which should be plenty for the motor (2.8V and 1.68A).

If you can't take a moment tell us what motor driver you have, and to what value you have set the current limit, please don't bother to post again.

L298 motor drivers WILL NOT WORK with that motor.

jremington please do not be angry with me. I am trying to figure out my problems. I was just looking for some help. Since posting this I found out that the motor driver is L298N, which seems to be the source of my problem. Thank you

I was just looking for some help.

When people are willing to help, it is just plain stupid not to answer their questions.

If you had provided a link to the motor driver in response to my question in reply #1, we would not have wasted this back and forth.

The motor in the link in Reply #7 draws 1.68 amps. A Pololu DRV8825 stepper motor driver should be suitable - but make sure to set the current limit correctly so as to protect the motor.

Stepper Motor Basics
Simple Stepper Code

And use the AccelStepper library, not the Stepper library, you get step/direction interface support and
acceleration/deceleration which is essential except for very low speeds only.

Robin thanks for the help. I read through your stepper motor basics and purchased a Pololu a4988 motor driver before I saw your most recent reply. Is this fine? Do you foresee any issues with this driver over the DRV8825?

The A4988 will probably struggle to deliver 1.7 amps - the DRV8825 has greater capacity.

Try the A4988 - you should certainly be able to get the motor working - maybe with the current limit set to 1.3 or 1.5 amps - but with less than full motor torque. If you have a heat sink for the A4988 you may be able to get more current through it.