Changing speed when running two motors

Hi everybody,
I have a circuit which has two optical sensors, and two stepper motors connected to 8825 drivers each.
The way it works is as follows, when the system is turned on, both motors rotate to advance a roll connected to each of them, and when something on the roll(opaque label) goes inside the optical sensor, the motor stops.
In the current way the program is written, when both motors work they are rotating at a slow speed, but when only one of them works(i.e sensor 1 already has a label inside it, but the motor of sensor 2 keeps pulling) the speed is much higher.

how can i make the speeds of both modes be the same?

I’ve attached the part in the code where it happens:

void calibrate(){
  while(!(((potVal>=550) && (potVal2>=550)))){  
    potVal = analogRead(potPin); // read the value of the sensor
    potVal2 = analogRead(potPin2); // read the value of the sensor
    if(potVal<550){// calibrate position of Active labels. bring space between labels into sensor
        digitalWrite(stepPin2,HIGH);
        delayMicroseconds(600);
        digitalWrite(stepPin2,LOW);
        delayMicroseconds(600);
      }
    if(potVal2<550){
        digitalWrite(stepPin,HIGH);
        delayMicroseconds(600);
        digitalWrite(stepPin,LOW);
        delayMicroseconds(600);
      }
  }
}

The speed of a stepper motor is determined by the interval between steps. If the interval is always the same then the speed will be the same.

You need to post a complete program.

...R
Stepper Motor Basics
Simple Stepper Code

Rather than re-invent the wheel, the AccelStepper library will do this sort of thing for you.

You have two lots of delays in the same loop, so of course they are interacting.

You could rework your logic to have a single set of delays in the loop, and indepedently
test each motor for whether it should step.

    if(potVal<550){// calibrate position of Active labels. bring space between labels into sensor
        digitalWrite(stepPin2,HIGH);
    }
    if(potVal2<550){
        digitalWrite(stepPin,HIGH);
    }
    delayMicroseconds(600);
    if(potVal<550){// calibrate position of Active labels. bring space between labels into sensor
        digitalWrite(stepPin2,LOW);
    }
    if(potVal2<550){
        digitalWrite(stepPin,LOW);
    }
    delayMicroseconds(600);

sorry for the delay,
here is the full program:

int const potPin = A1; // analog pin used to connect to sensor1
int potVal;
int const potPin2 = A3; // analog pin used to connect to sensor2
int potVal2;
const int stepPin = 3;
const int dirPin = 4;
const int stepPin2 = 8;
const int dirPin2 = 9;
int firstrun; 
int const buttonPin = A5; 
int button;
 
 void setup() {
 // set the two pins as outputs
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
  pinMode(buttonPin,INPUT);
  Serial.begin(9600); // open a serial connection to your computer
  pinMode(potPin, INPUT);
  pinMode(potPin2, INPUT);
  firstrun=1;
  button=0;
}

void loop() {
  calibrate();
  delay(50);
  TTI();
}

void calibrate(){
  while(!(((potVal>=550) && (potVal2>=550)))){  
    potVal = analogRead(potPin); // read the value of the sensor
    potVal2 = analogRead(potPin2); // read the value of the sensor
    if(potVal<550){// calibrate position of Active labels. bring space between labels into sensor
        digitalWrite(stepPin2,HIGH);
        delayMicroseconds(600);
        digitalWrite(stepPin2,LOW);
        delayMicroseconds(600);
      }
    if(potVal2<550){
        digitalWrite(stepPin,HIGH);
        delayMicroseconds(600);
        digitalWrite(stepPin,LOW);
        delayMicroseconds(600);
      }
    firstrun=0;
  }
}
void TTI(){
  button=analogRead(buttonPin);
  if(button>800)
  {
    while(1)
    {
      potVal = analogRead(potPin); // read the value of the sensor
      potVal2 = analogRead(potPin2); // read the value of the sensor
     
          if(potVal>500)// calibrate position of Active labels. bring start of label into sensor
          {
            digitalWrite(stepPin2,HIGH);
            delayMicroseconds(600);
            digitalWrite(stepPin2,LOW);
            delayMicroseconds(600);
          }
          if(potVal2>550)// calibrate position of Base labels. bring start of label into sensor
          {
            digitalWrite(stepPin,HIGH);
            delayMicroseconds(600);
            digitalWrite(stepPin,LOW);
            delayMicroseconds(600);
          }
          if(((potVal<500) && (potVal2<550))==HIGH)
          {
            break; 
          }
    }
  }
    
}

Try my suggestion with the delayMicrosecond calls?

OK i used your suggestion and it helped with the changing speeds, great!

now i have another issue to deal with,
in the current way the program is written, the motors get very hot, probably they are not really in "idle" mode.
how can i make a real idle state while they are not working?

when i load the arduino with a program that's not controlling the motors at all(lets say the example led blinking program), the motors are not heating at all, of course with the same circuit. thats telling me that somehow the motors keep getting current while not moving.

any tips?

What do you mean by "idle state"? Do you mean not moving, but holding the current position? Or do you mean not moving and being able to freely turn by hand? Either can be done. Stepper motors have to get hot because of the current going through the coils.

Paul

If its possible to keep the motor holding it's position with holding torque and not keep getting hot, i'd like that.
If the alternative of being able to freely turn the motor is the only solution for heating, than that's the one to try first.

gania13:
If its possible to keep the motor holding it's position with holding torque and not keep getting hot, i'd like that.
If the alternative of being able to freely turn the motor is the only solution for heating, than that's the one to try first.

Your controller boards will have an "enable" pin that can be set to "not enable" and that will stop the holding current. Be sure to "enable" before moving the motor.

Paul

gania13:
If its possible to keep the motor holding it's position with holding torque and not keep getting hot, i'd like that.

They can only hold position if there is current flowing in the coils and if there is current flowing they will be hot. They are designed to work while hot. Don't worry about it.

...R

A good stepper driver board will have a reduced current mode that automatically kicks in after a short period
of inaction - typically dropping the current to 30 to 50% of normal - this greatly(*) reduces heating and
since stationary torque is much higher than dynamic torque for a stepper there is usually no issue with
reduce torque at stationary causing missed steps.

Alas most cheap hobby modules for stepper driving don't support this useful feature.

(*) 50% current means a 4-fold reduction in motor heating, power = I-squared-R.