Why Nema-17 Stepper Motor with DRV8225 vibrates randomly at idle?

Hello there,
I am working with a NEMA-17 Motor (17PM-K310-32VS) with motor driver DRV8225 for which I am following this guide with the exact same circuit they have given but with a addition of one push button programmed to start and stop the motor. I am using AccelStepper and EzButton library for driver and button respectively.

Arduino IDE Code

#include <AccelStepper.h>
#include <ezButton.h>

#define MOTOR_SPEED 200
#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1

AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
ezButton motor_switch(4); 

void setup() 
{
  stepper.setMaxSpeed(200);
  stepper.setSpeed(0);
}

void loop() 
{  
  motor_switch.loop();
  if(motor_switch.isPressed())
  {
    stepper.speed()==0 ? stepper.setSpeed(MOTOR_SPEED) : stepper.setSpeed(0);
  }
  
  if(stepper.speed()==0)
  {
    stepper.stop();
    //stepper.disableInputs();
  }
  else
  {
    //stepper.enableInputs();
    stepper.runSpeed();
  }
}

Problem: Circuit and Code works as intended as I am able to start and stop the motor with the push button but I am facing one problem. My NEMA-17 Motor vibrates randomly at idle. Frequency of vibration is also random that is sometimes it vibrates for a very short time (less than a second) but other times it vibrates for 5-10 seconds. Also I observed that motor is getting hot even at idle.

Why is this happening and how to fix this?

Things I have done so far: In order to troubleshoot this, I tried many things:

  1. Changing Arduino, I have tried with UNO, NANO and MEGA.
  2. Changing driver Library and even uploading an empty sketch.
    (I tried Accelstepper's disableInputs functions as well)
  3. Reviewing connections.
  4. Changing motors.
  5. Replacing Motor driver with another DRV8225 module.
  6. Changing driver's current limit using its potentiometer.

Please help me fix this problem,
Thank you.

UPDATE
I have been able to fix the problem. Thing I found was motor was not sleeping, I read about SLP and reset pins in DRV8225's manual and found out that SLEEP mode can be controlled using the SLP pin. SLP must be HIGH to disable SLEEP mode and LOW to enable it.

Original guide and many other guides online I found shows direct connection with SLP and RST pins of DRV8825 for easy connections probably targeting beginners. But none of them mentioned the consequences this direct connection and at best few of them just mentioned the default state for these pins.

So I connected the sleep pin to Arduino digital pins and now I can control the sleep through sketch and have to make sure to enable the SLEEP mode every time I want my motor to STOP and remain idle. So updated code is as follows.

#include <AccelStepper.h>
#include <ezButton.h>

#define MOTOR_SPEED 200
#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1
#define SLEEP_PIN 5

AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
ezButton motor_switch(4); 

void setup() 
{
  pinMode(SLEEP_PIN,OUTPUT);
  digitalWrite(SLEEP_PIN,LOW);
  delay(2);
  motor_switch.setDebounceTime(50);
  stepper.setMaxSpeed(200);
  stepper.setSpeed(0);
}

void loop() 
{  
  motor_switch.loop();
  if(motor_switch.isPressed())
  {
    if(stepper.speed()==0)  
    {
      digitalWrite(SLEEP_PIN,HIGH);
      delay(2);
      stepper.setSpeed(MOTOR_SPEED) 
    } 
    else
    {
      digitalWrite(SLEEP_PIN,LOW);
      delay(2);
      stepper.setSpeed(0);
    }
  }
  
  if(stepper.speed()==0)
  {
    stepper.stop();
  }
  else
  {
    stepper.runSpeed();
  }
}

Since motor is now sleeping, both vibrations and heat dissipation at idle motor has been gone. I don't know if this heat was the exact reason for vibrations but its fixed as of now.

I guess that you should have more distinct states and do not change state arbitrarily. Actually if the button is pressed and the motor runs, it will be stopped. When stopped and the button is still pressed then it will be run again.

I'd use the StateChange button example instead of ezButton.

That's as descriptive as "my green car". The NEMA value indicates the faceplate size, not any indication of the power or torque of the motor.

Thanks for reply,

I am working with a NEMA-17 Motor (17PM-K310-32VS)

I have mentioned the complete model number. I got these motors from my college lab that's what model number is written on the motor. I couldn't find any proper spec sheet for this exact model except for its amazon listing.

As for this, I have used ezButton before and it has served me well, thing you mentioned can be resolved by adding debounce time but my button doesn't have much debounce time and is working well as i intended. My main issue is random vibrations at idle. Even if remove the button and just set motor speed at 0, those vibrations still occur.

You used a completely different motor than that specified in the tutorial.
It may or may not work correctly with a different motor.

No, that's something very different. A state change occurs only once when the button is pressed, and once again when it is released. Your motor control should react only on the off-to-on button state change.

ok I checked. Dont worry ezButton library handles isPressed and isReleased events as different events. There is no problem with the button. Please explain by is it vibrating at idle state.

see post 5

I know that. Motor is working. My problem is random vibrations at idle state i.e when motor is not running.

So even though it's vibrating, you consider it working OK?

So what do you propose? I obviously can't get the exact same motor as mentioned in that guide.

You don't know voltage or current requirements for the motor so I would just be guessing as to what to suggest.

I suspect that your motor uses a lot more current than the one used in the tutorial. You can't use a breadboard for high currents so you can try connecting the motor directly to the power supply and to the driver with jumper wires.

Also, you should probably have a 24V power supply capable of supplying at least 5A
I can't guarantee that this will work.

according to amazon listing, current rating for this model is 750mA.
I am not using breadboard. Its all soldered in pcb.

:sunny: Coil Resistance: 4.2 Ohms ~ 7.4 Ohms
:sunny: Current Rating (Amps): 750mA ~ 2A
:sunny: Voltage - Rated: 2.4V ~ 24VDC

What are they saying here?

The resistance can be anything between 4.2 and 7.4 and the current anything between .75 and 2A, voltage 2.4 to 24V.

So how do you know which motor they gave you? Is it a 2.4V motor, a 24V motor or something inbetween?

Your code demonstrated a problem with a bounce enabled button on Wokwi. Are you sure there's a pullup resistor or the motor switch pin has pullup enabled?

Anyways, I'm quite familiar with the Toggle library, so here's your code on Wokwi, completely debounced ...

I have been able to fix the problem. Check post#1 Update. Thanks for everyone's feedback.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.