Arduino bumper robot and accelstepper

Hi,

I’m working on vacuum bumper robot and there are few things i dont catch with the accellstepper library.

Code is include below.

1-In the main loop, why the robot turn when the right bumper is on but dont do the same thing with the left bumper??

2-How acceleration could be effective??

Thank you.

#include <AccelStepper.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define FULLSTEP 4
#define HALFSTEP 8
// motor pins
#define motorPin1  4     // Blue   - 28BYJ48 pin 1
#define motorPin2  5     // Pink   - 28BYJ48 pin 2
#define motorPin3  6     // Yellow - 28BYJ48 pin 3
#define motorPin4  7     // Orange - 28BYJ48 pin 4
                        // Red    - 28BYJ48 pin 5 (VCC)
                        
#define motorPin5  8     // Blue   - 28BYJ48 pin 1
#define motorPin6  9     // Pink   - 28BYJ48 pin 2
#define motorPin7  10    // Yellow - 28BYJ48 pin 3
#define motorPin8  11    // Orange - 28BYJ48 pin 4
                        // Red    - 28BYJ48 pin 5 (VCC)
                        
/*-----( Declare objects )-----*/
// NOTE: The sequence 1-3-2-4 is required for proper sequencing of 28BYJ48
AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
AccelStepper stepper2(HALFSTEP, motorPin5, motorPin7, motorPin6, motorPin8);

/*-----( Declare Variables )-----*/
int pushButtonleft = 2; //switch bumper left
int pushButtonright = 12; //switch bumper right

void setup()   /****** SETUP: RUNS ONCE ******/
{
  stepper1.setMaxSpeed(2000.0);
  stepper1.setAcceleration(20.0);
  stepper1.setSpeed(1000);

  
  stepper2.setMaxSpeed(2000.0);
  stepper2.setAcceleration(20.0);
  stepper2.setSpeed(1000);

  pinMode(pushButtonleft, INPUT);
  pinMode(pushButtonright, INPUT);
}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{

  
  stepper1.runSpeed();
  stepper2.runSpeed();

  int bumperstateleft = digitalRead(pushButtonleft);
  int bumperstateright = digitalRead(pushButtonright);
  
  if (bumperstateleft == HIGH) {

     stepper1.setSpeed(-1000);
     stepper2.setSpeed(-500);
  }
  
  if (bumperstateright == HIGH) {

     stepper1.setSpeed(-500);
     stepper2.setSpeed(-1000);
  }
  
  else {
   
     stepper1.setSpeed(1000);
     stepper2.setSpeed(1000);
  }
}//--(end main loop )---

1-In the main loop, why the robot turn when the right bumper is on but dont do the same thing with the left bumper??

Possibly because of the way your switches are wired.

Changing the speed of a stepper, if it has no steps to do doesn't seem useful. Using a stepper motor as a variable speed electric motor is simply wasting its capabilities. Regular electric motors are far cheaper, and easier to use, than steppers. Why ARE you using steppers this way?

In the main loop, why the robot turn when the right bumper is on but dont do the same thing with the left bumper??

It does turn left, but only for a very short time.

PaulS, i used those motor cause i have many of them and it seem easy to make straight line.

Thank you AWOL, i figured it out.