0

I'm relatively new to Arduino thus need your help to figure out why my stepper motor doesn't rotate clockwise and counterclockwise. All I could do was to make it rotate only in one direction.

I am using AccelStepper Library

Here is my code:

#include <AccelStepper.h>
//Define stepper motor connections
#define dirPin 4
#define stepPin 14
//Create stepper object
AccelStepper stepper(1,stepPin,dirPin); //motor interface type must be set to 1 when using a driver.
void setup()
{
 stepper.setMaxSpeed(1200); //maximum steps per second
}
void loop()
{
 stepper.setSpeed(1200); //steps per second
 stepper.runSpeed(); //step the motor with constant speed as set by setSpeed()
}

I have tried to add delay and counterclockwise code but its not working.

#include <AccelStepper.h>
//Define stepper motor connections
#define dirPin 4
#define stepPin 14
//Create stepper object
AccelStepper stepper(1,stepPin,dirPin); //motor interface type must be set to 1 when using a driver.
void setup()
{
 stepper.setMaxSpeed(1200); //maximum steps per second
}
void loop()
{
 Serial.println("clockwise");
 stepper.setSpeed(1200); //steps per second
 stepper.runSpeed(); //step the motor with constant speed as set by setSpeed()
 delay(1000);
 Serial.println("counterclockwise");
 stepper.setSpeed(-1200); //steps per second
 stepper.runSpeed(); //step the motor with constant speed as set by setSpeed()
 delay(1000);
}
asked May 30, 2019 at 7:49
5
  • Try to use lower values for spinning, let's say 150. Some drivers are easy overheating when using higher speeds. Commented May 30, 2019 at 11:03
  • it rotate only in one direction ... which direction is that? Commented May 30, 2019 at 17:33
  • No its not about heating or higher speed If i put 1200 it move perfectly clockwise if i put value to -1200 it move perfectly counter-clockwise But if i try to use both it creates problem Commented May 30, 2019 at 18:09
  • What hardware do you use? I mean, what is the stepper motor driver? There are some drivers which overheat easily and (due to built-in overheat protection) stop operation. Commented May 31, 2019 at 8:18
  • @smajli its not about heating i am missing something with code if i rotate in 1 direction only with default code it works fine. Motor - NEMA17 5.5Kgcm Stepper Motor Commented May 31, 2019 at 14:38

2 Answers 2

2

Hi here it the reference to the library functions that are available in accelstepper library.

Go through the link, it will provide you the issues with your code and example for your application like @smajli said steps more than 1000 is unreliabe, here you can see setSpeed(float) function where setting negative or positive sign selects the direction and value set the speed of rotation.

answered May 30, 2019 at 12:14
3
  • than you for your input but i am still struggling to understand functions :( i have changed speed to 1000 and behavior is still same Commented May 30, 2019 at 15:15
  • did you tried -500 and 500 ? Commented May 31, 2019 at 16:13
  • yes buddy seems i can't use delay function in loop but i am not getting how to use other function of this library or use millis function Commented May 31, 2019 at 18:55
0

From the AccelStepper website: link

Speeds of more than 1000 steps per second are unreliable

Try to change the speed to lower value, and let us know what is the outcome.

answered May 30, 2019 at 11:36
1
  • thank you for pointing out but still same behavior Commented May 30, 2019 at 15:14

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.