Stepper motor is moves clockwise during startup

Hi everyone, do you have any idea why stepper motor randomly rotates a little upon startup?

Thanks in advance. Any idea will be appreciated.

#include <AccelStepper.h>
#include <MultiStepper.h>

AccelStepper stepper(AccelStepper::DRIVER, 2, 3); // StepPin 2 and DirPin 3

void setup() {
  // Code to run once:
  stepper.setMaxSpeed(3000);
  stepper.setAcceleration(3000);
}
void loop() {
  // put your main code here, to run repeatedly:
int POT1VAL = analogRead(A0);
int SMP = map(POT1VAL, 0, 1023, 0, 255);
stepper.moveTo(SMP);
stepper.runSpeedToPosition();
}
1 Like

Yes. Please post schematics.

2 Likes

Rotates how much? It's normal for the motor to move slightly when power is applied as the rotor aligns with the magnetic field, but that's typically only a few degrees at most.

Have your stepper seek home at startup.

I have several. connect the purple wire to the pink one and the black one to the red one. If that does not work follow @Railroader suggestion and post an annotated schematic. From where I am I cannot see your project and explaining it in the language of electronics (schematics) helps us help you.

1 Like

Hello good day sir, to be honest I don't know how to create schematic. But I am using a stepper motor easy driver A3967 and arduino uno r4. Digital Pin 2 of arduino is connected to STEP pin of easy driver and digital pin 3 is connected to the DIR pin of easy driver. Potentiometer's wiper is connected to Analog Pin (A0). This only happens when easy driver is already powered up and the potentiometer is not in its lowest position before I power on the arduino. But if I power on the arduino before I power on the easy driver even the position is not in it lowest position, it works so well. Thank you for your help in advance.

Honestly I dont know how to calculate how much it moves, but what I want to happen is when I power on the arduino and the easy driver, the motor will not move. I don't know if it is possible, or is there a way to do it. Thank you in advance sir

I already tried to do that sir. But when it reached the home position it still moves clockwise a little. Thank you.

Hello good day sir, to be honest I don't know how to create schematic. But I am using a stepper motor easy driver A3967 and arduino uno r4. Digital Pin 2 of arduino is connected to STEP pin of easy driver and digital pin 3 is connected to the DIR pin of easy driver. Potentiometer's wiper is connected to Analog Pin (A0). This only happens when easy driver is already powered up and the potentiometer is not in its lowest position before I power on the arduino. But if I power on the arduino before I power on the easy driver even the position is not in it lowest position, it works so well. Thank you for your help in advance.

Hi, @szipra96

Where is the rest of your code?

Please post your complete code.

It sounds like the stepper driver is powering the UNO through its output pins connected to the driver when the UNO is not connected to its own power supply.

No is the time for you to learn how to draw circuit diagrams.
Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Can you please post some images of your project?
So we can see your component layout.

Tom.... :smiley: :+1: :coffee: :australia:

What power supplies are you using and how have you got the grounds connected.
What are all the connections to the potentiometer?

Tom.... :smiley: :+1: :coffee: :australia:

Hello sir, I am using a type C cable that is connected from my computer to arduino uno r4. I am using a external power supply to power the easy driver, I just dont know what is the exact model. The potentiometer is connected to 5v pin and ground pin of arduino, and the wiper of potentiometer is connected to the analog pin (A0).

You can use pen and paper. Take a photo of it and post it. Use the Search Forum function in this window and search for "schematics" to se examples of what the pen work needs to tell.

1 Like

If the the Arduino is unpowered but the EasyDriver is, any noise on the STEP pin could cause the stepper to move. A simple way to avoid this is to place a 10k resistor between STEP and GND.

Since you've chosen not to provide even a basic sketch of your setup, as requested by @Railroader, @TomGeorge, and others, I’ll step back from this thread. I wish you the best of luck, but I’m going to focus my time on helping others who are willing to help themselves.

1 Like

Your code does not compile. I did some fiddling with it.

// #include AccelStepper.h
// #include MultiStepper.h
#include <AccelStepper.h> // added missing waka waka
#include <MultiStepper.h> // added missing waka waka

// AccelStepper stepper(AccelStepperDRIVER, 2, 3);
AccelStepper stepper(2, 2, 3); // changed first parameter for two-wire

void setup() {
  stepper.setMaxSpeed(4000);
  stepper.setAcceleration(4000);
}

// void FCD() { // WTF no loop()?
void loop() {
  int POT1VAL = analogRead(A0);
  int SMP = map(POT1VAL, 0, 450, 0, 4150);
  stepper.moveTo(SMP);
  stepper.runSpeedToPosition();
}

Compiles. Not tested.

I respect your opinion sir and I understand that your time is very important and maybe you are bit disappointed. I am still figuring out how schematic works because to be honest its all brand new to me. But thank you for wishing me good luck and I appreciate your time explaining things the best as you can. all love

hi sir, my bad. The first code that I provided here is wrong. Here is the copy of the code im using right now. It works well when controlling the position of stepper motor using a pot. the only issue now is the motor moves clockwise a little when the pot is not in its lowest position/value. Thank you for your correction.



#include <AccelStepper.h>
#include <MultiStepper.h>

AccelStepper stepper(AccelStepper::DRIVER, 2, 3); // StepPin 2 and DirPin 3

void setup() {
  // Code to run once:
  stepper.setMaxSpeed(3000);
  stepper.setAcceleration(3000);
}
void loop() {
  // put your main code here, to run repeatedly:
int POT1VAL = analogRead(A0);
int SMP = map(POT1VAL, 0, 1023, 0, 255);
stepper.moveTo(SMP);
stepper.runSpeedToPosition();
}

hello sir, Im still figuring out how that works, thank you.

I know. I "fixed" it.

I also know you have not posted a wiring diagram.

You want help fixing something without supplying any correct information?

It works.

You have a bad connections or bad potentiometer or power supply noise is effecting your potentiometer reading. You also posted no wiring drawings.

You figure the rest out.

1 Like