How can stop the stepper motor for a second with setSpeed() and rotate then wait for a second and rotate then wait for a second, continuously

stepper.setSpeed(500);
delay(1000);

I tried this but it didn't help!

Do you have a question?

Your code doesn't compile.

I want to run the stepper motor for one second and stop for a second and it continues. But I am not to do with setSpeed()

Please show your sketch ( Don't forget the code tags ).

#include <AccelStepper.h> //accelstepper library

const byte limitSwitch_1 = 2; //pin for the microswitch using attachInterrupt()
const byte limitSwitch_2 = 3; //pin for the microswitch using attachInterrupt()
 
int newSpeed;

// direction Digital 9 (CCW), pulses Digital 8 (CLK)
AccelStepper stepper(1, 8, 9);


void setup()
{
  //Limit Switches
  pinMode(limitSwitch_1, INPUT_PULLUP); // internal pullup resistor (debouncing)
  pinMode(limitSwitch_2, INPUT_PULLUP); // internal pullup resistor (debouncing) 

  Serial.begin(9600); //defining some baud rate
  Serial.println("Motor Start");

  //setting up some default values for maximum speed and maximum acceleration
  stepper.setMaxSpeed(5000); //SPEED = Steps / second  
//  stepper.setAcceleration(1000); //ACCELERATION = Steps /(second)^2    
//  stepper.setSpeed(2000); //intial starting
//if(digitalRead(limitSwitch_2) == HIGH && digitalRead(limitSwitch_1) == HIGH){

// delay(1000);
//Serial.println("delay");

  stepper.setSpeed(2000);
delay(1000);
  Serial.println("delay");

}
//flipCheck();

void loop()
{  
  stepper.runSpeed(); //step the motor (this will step the motor by 1 step at each loop indefinitely)
  
              if(digitalRead(limitSwitch_1) == LOW)
  {  
    stepper.setSpeed(0);
     Serial.println("Stop");
  }

  if(digitalRead(limitSwitch_2) == LOW)
  {  
    stepper.setSpeed(-1000); 
    Serial.println("anticlockwise");
  }
  // mlli second delay
}

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