make multiple servo motors move in parallel

I am trying to make multiple servo motors in parallel.

I am adjusting the speed of servo motors slow, so that I am using sketch like “for(int i=0; i<=180; i++)”.

The complete sketch is follows.

#include<Servo.h>

Servo servo1;
Servo servo2;
Servo servo3;

int val = 0;

void setup() {
servo1.attach(7);
servo2.attach(8);
servo3.attach(9);
}

void loop() {

for(int i=0; i<=180; i++){
val = i;
servo1.write(val);
delay(2);
}
for(int i=180; i>=0; i–){
val = i;
servo1.write(val);
delay(2);
}

for(int i=0; i<=180; i++){
val = i;
servo2.write(val);
delay(5);
}
for(int i=180; i>=0; i–){
val = i;
servo2.write(val);
delay(5);
}

for(int i=0; i<=180; i++){
val = i;
servo3.write(val);
delay(5);
}
for(int i=180; i>=0; i–){
val = i;
servo3.write(val);
delay(5);
}

}

With my sketch above, servo2 starts moving after finishing movement of servo1.

What I want to do is make servo2 move while servo1 is moving.

Or, I want to make servo1 and servo2 at once.

Please somebody teach me how to make it using “for(int i=0; i<=180; i++)”.

Thank a lot for your support.

Put all the writes inside the same loop

The val = i; assignment is pointless; just write "i" to the servo object.

I am trying to make multiple servo motors in parallel.

Connect all the servo control lines to the single servo control pin on the arduino. Also, #7 below:

http://forum.arduino.cc/index.php/topic,148850.0.html

Hi,

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Tom… :slight_smile: