Controlling the speed of 4 servos

Hi, I'm relatively new to arduino and programming but I'm working on this project now and I want to move 4 servos simultaneously and also to set the speed of the servo motors . I've managed to make the servos move simultaneously but I can't figure out now how to set the speed . This is the code I've written so far :

#include <Servo.h>

Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;

unsigned int pos[]={0,140,0};

const int servo1Pin=10;
const int servo2Pin=9;
const int servo3Pin=6;
const int servo4Pin=3;

void setup() {



void loop() {

for(int i=0;i<3;i++){

_ servo2.write(pos*);_
_ servo3.write(pos);

And prior to this I've managed to also set the speed of the servo with this algoritm, but couldn't make the servos move simultaneously :
#include <VarSpeedServo.h>
VarSpeedServo servo1;
const int servo1Pin=10;
void setup() {
void loop() {
* servo1.write(0,120,true);*
* delay(1000);*
* servo1.write(150,120,true);*
* delay(1000);*

If you have any idea how i could make them servos move simultaneously and also set their speed that would be awesome. Thank's !

I know nothing about the VarSpeedServo library and it is not necessary.

Look at how the servo is controlled in the servo sweep example and in planning and implementing a program. Basically the servo is moved a little piece at a time with a suitable interval (to govern the speed) between each small movement.

You can use the same technique with several servos. You can use the same interval for all servos if they are all to move at the same speed, or different intervals for each of them.


I can't figure out now how to set the speed . This is the code I've written so far :

#7 below for how to post code. What problems do you have with your code? Using delays in your code will affect timing for all the servos.,148850.0.html

Are all four servos going to the same destination at the same rate? If so, hook them all to the same output pin and use the ServoSweep example to control the speed.

If they are moving different amounts, did you want them to all use the same speed or all finish at the same time? Is the time or the maximum speed fixed? Fixed time would mean a short move would be slower than a long move. Fixed maximum speed would mean the time would depend on the longest move.

Start with some tips.

First use code tags!!!

Second, use arrays to hold multiple similar things. Like the servo's and the pins etc.

Varspeed library is a simple way to do it. But to make it work you have to drop the delay(). (Delay() is stupid anyway :p) See Blink without delay on how to do it without.