Stepper motor not moving and fluctuations in current drawn

Hey everyone,

My goal is to run the stepper motor that is mounted on 1200 mm linear stage at its maximum speed (3.5 rps = 210 rpm) in room temperature for at least an hour without the stepper motor getting stuck. The goal after that is to do the same at -20 degrees Celcius.

The problem is that when the stepper motor is mounted on the linear stage, it won’t start moving when I try to run it at 210 rpm at room temperature. However

  • previously stepper motor has been able to run at 210 rpm at room temperature while mounted on the linear stage
  • it does run at 210 rpm now when not mounted on the stage
  • in both cases my 12V, 4.2A power supply shows that current drawn is fluctuating between maximum (0.5-0.8A depending on the stepper motor driver’s potentiometer setting) and 0.1A.

Details of the setup:
I have a 400steps/rev bi-polar stepper motor (datasheet), A4988 driver (datasheet) with heatsink installed, 12V motor power supply and 100uF capacitor with voltage rating 25V. I’m using Arduino Uno as my microcontroller. My electronics set up is equivalent to the one in the attached picture.

I have adjusted the potentiometer on A4988 according to the formula Vref = (8 × R)Imax = 80.050*2 = 0.8V from Makerguide website.

Things that I have tried to solve the problem:

  • swapping the stepper motor with another one of the same type
  • swapping the motor driver with another one of the same type
  • swapping the capacitor with another one of the same type
  • readjusting all the wires by plugging them out and in again to eliminate loose connections
  • swapping all the jumper wires with another ones of the same type
  • swapping all the jumper wires with thicker wires (0.25 mm2) which tips I tinned
  • using a different power supply (12 V, 16.5A)
  • readjusting the location of the wires by moving power wires away from signal wires to eliminate electromagnetic interference
  • using AccelStepper library for running the motor continuously instead of the code attached

The timeline up until now:

  • Stepper motor not moving at 210 rpm at room temperature while mounted on the linear stage. The current drawn is fluctuating.
  • Problem was caused by bad connection and was solved by readjusting the wires.
  • Stepper motor not moving at 210 rpm at -20 degrees Celcius while mounted on the linear stage. The current drawn is fluctuating.
  • Stepper motor not moving at 210 rpm at room temperature while mounted on the linear stage. The current drawn is fluctuating.
  • I tried all the possible solutions listed above none of which helped to solve the problem.

Here is my code:

#define stp 5 // step
#define dir 6 // direction: LOW -> step forward, HIGH -> step in reverse

unsigned long t_spd = 0; // stepper timing
int spd = 350; // microseconds --> corresponds to speed 3.5 rps = 210 rpm.
bool stp_finished = true;

long pos_steps = 0; // position
long steps = 0; // distance
bool dir_forward; //direction

void setup() {
  pinMode(stp, OUTPUT);
  pinMode(dir, OUTPUT);

void loop() {
  if (steps == 0){
    if (Serial.available() > 0) {
      long steps = Serial.parseInt();
      if (steps > 0){
        digitalWrite(dir, LOW);
        dir_forward = true;
        digitalWrite(dir, HIGH);
        dir_forward = false;
    if ((unsigned long)(micros() - t_spd) >  spd){
      if (stp_finished == true){
          digitalWrite(stp, HIGH);
          stp_finished = false;
          digitalWrite(stp, LOW);
          stp_finished = true;
          if (dir_forward == true){
      t_spd = micros();

void resetEDPins()
  digitalWrite(stp, LOW);
  digitalWrite(dir, LOW);

Do you have any ideas what the problem could be or/and what else to try out?


motor_control_minimal_py.txt (376 Bytes)

It looks like your code is not accelerating the motor up to speed. Stepper motors (like any other motor) cannot jump instantly from stationary to full speed.

Consider using the AccelStepper library or, if you prefer not to use a library have a look at this Simple acceleration code.

Stepper Motor Basics
Simple Stepper Code

You need to post the AccelStepper variant that you tried - speed ramping is essential with all but the
lowest speeds or smallest motors.

Is there any mechanical damping in the mechanical assembly? IE is it a leadscrew (little damping) or
belt drive (usually good damping).

Are you using microstepping, if so, how much? Microstepping is almost essential for practical use
of a stepper at anything but very slow speeds, as it greatly reduces resonance as the speed passes
through the natural torsional resonant frequency of the motor/load combination.

No useful information can be gleaned from the current consumption, BTW.

Thank you both for your help. (:

I used Robin2’s Simple acceleration code and I succeeded in running my motor at 210 rpm. I also noticed that when using acceleration at lower speeds (107 rpm), the motor runs smoother (less noise) when using the acceleration compared to running it with no acceleration.

I use a ball screw in my mechanical assembly and what I noticed is that near 210 rpm I hit the resonance and the platform (that my motor is moving) starts vibrating. Previously I had only used full steps, but following MarkT’s suggestion I tried out half steps and the vibration was not muffled completely, but it was reduced.
I don’t know if the resonance came from the motor or perhaps my ball screw has been bent a little and that contributes to the resonance at 210 rpm.

The current drawn didn’t fluctuate anymore once I reduced the current limit using the potentiometer on the driver. When testing last week I noticed this problem that the stepper is not moving continuously at low speeds (15 rpm) which was also solved by reducing the current limit.

The AccelStepper code that I tried while testing:

/*Example sketch to control a stepper motor with A4988 stepper motor driver, AccelStepper library and Arduino: continuous rotation. More info: */
#include <AccelStepper.h>

#define dirPin 6
#define stepPin 5
#define motorInterfaceType 1 //Motor interface type must be set to 1 when using a driver:

// Create a new instance of the AccelStepper class:
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);

void setup() {
  stepper.setMaxSpeed(1800); // Set the maximum speed in steps per second:

void loop() {
  stepper.setSpeed(-100); // Set the speed in steps per second:
  stepper.runSpeed(); // Step the motor with a constant speed as set by setSpeed():

Resonance is due to the motor acting as a very stiff torsional magnetic spring, coupled to the moment
of inertia of the rotor and whatever is fixed to the shaft. The frequency of the resonance depends on
both the motor, the current, and the total moment of inertia.

Without any damping this is a very resonant system, and highly likely to skip and stall.

half-steps aren't going to do a lot compared to a decent level of microstepping, say x8 to x32.
Each time the motor moves, the resonant system is sent into oscillation about the new set-point.

Microstepping makes each move smaller, so the oscillation is less severe.

Without microstepping the noise and vibration are usually pretty objectionable too.

As I said before with a stepper motor that's larger than a cm or so in size you have to use
acceleration to get to top speed, there's just too much moment of inertia to change speed that