r/ArduinoHelp • • Aug 26 '25

Stepper Motor not working

I have been following online lessons, but I am really struggling with this stepper motor. At first, I thought it was the battery because I hear these things eat through it but I bought more 9V and it didn't fix the problem. The lights on the driver turn on but nothing moves. My code should simply move the motor in one direction then change it when the switch is pressed. Any ideas?

#include <Stepper.h>
int dt = 100;
int stepsPerRev=2048; //GET THIS OFF THE SPEC SHEET FOR THE STEPPER
int motSpeed=10; //believe this is in RPM 
int switchPin=4;
int switchValNew;
int switchValOld=1;
int motDir=1;
Stepper myStepper(stepsPerRev,8,9,10,11);

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
myStepper.setSpeed(motSpeed); //in RPM i think 
pinMode(switchPin,INPUT);
digitalWrite(switchPin,HIGH);
}

void loop() {
  // put your main code here, to run repeatedly:
switchValNew=digitalRead(switchPin);
if (switchValOld==1 && switchValNew==0){
  motDir=motDir*(-1);
}
switchValOld=switchValNew;

myStepper.step(1*motDir);
delay(dt);
//Serial.println(motDir);


}
12 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/Mice_Lody Aug 26 '25

But if it’s set to 10 rpm I should be able to see it move in real time? So I don’t think that’s the issue. Everything is wired up properly at least from what I see

1

u/tipppo Aug 26 '25

You set it to 10RPM, but then you tell it to move only 1 step and to delay 100ms. "myStepper.step(1*motDir);" If you instead tell it "myStepper.step(2048*motDir);" it would presumably rotate on full turn over 6 seconds.