2 microservos running simultaneously on Arduino Micro

Hi, new to Arduino, this forum, and to motors in general.
I have searched but could not find anything that answered my particular question. Using two microservos, specifically the Tower Pro Micro Servo 9g SG90. Both connected to the same Arduino micro on pins 9 and 10. I edited the general Sweep program in the servo library to accommodate 2 servos and then ran it. One servo will sweep fully and then the other, and so they continue one after the other. I am trying to get them both to sweep at the same time at the same positions. Code is below:

void loop() {
  for (pos = 0; pos <= 90; pos += 1) { // goes from 0 degrees to 90 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 90; pos >= 0; pos -= 1) { // goes from 90 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 0; pos <= 90; pos += 1) { // goes from 0 degrees to 90 degrees
    // in steps of 1 degree
    myservo2.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 90; pos >= 0; pos -= 1) { // goes from 90 degrees to 0 degrees
    myservo2.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

Note that this code is just the loop, as that is where I am pretty sure the problem lies. This is not the complete sketch.

Any help very much appreciated!

You need to interleave the code. Something like this

  for (pos = 0; pos <= 90; pos += 1) { // goes from 0 degrees to 90 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    myservo2.write(pos); 
    delay(15);                       // waits 15ms for the servo to reach the position
  }

However this may not be suitable if the two servos re required to do different things. In that case you should not use a FOR loop - you should rely on the repetition of loop() and count the positions separately. Look at how the servo is controlled in the demo Planning and Implementing a Program

…R

Works perfectly, thanks so much for the help!!