Controlling stepper speed

I am using two 28BJY-48 stepper motors and ULN2003 driver with library AccelStepper.h in Arduino Nano. I have set them up and are working as expected at a fixed speed. Can anyone please point me to an example sketch that changes stepper speed on the fly. eg. Calling a function that changes the speed from the main loop..

What you need to do is to set the maximum speed and acceleration rate in the setup function.

#include <AccelStepper.h>
#define EN 10
#define RST 11
#define STEP 12
#define DIR 13
#define INTERFACE_TYPE 1


// Create a new instance of the AccelStepper class:
AccelStepper stepper = AccelStepper(INTERFACE_TYPE, STEP, DIR);

void setup(){
// Set the maximum speed and acceleration for calibration:
  stepper.setCurrentPosition(0); // set this point as zero
  stepper.setMaxSpeed(700); // note 1000 is the fastest speed for this library
  stepper.setAcceleration(500);
}
void loop(){
stepper.moveTo(400);
delay(2000);
stepper.moveTo(0);
delay(2000);
}

Play with the number in the stepper.setAcceleration call to change the amount of acceleration.

Thank you. In order to change speed on the fly I need to add:-
stepper.setSpeed(newSpeed)
and
runSpeed() or should it be stepper.run() at bottom of loop?

Not sure sorry, try both.

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