How to make two servos move at the same time

Hello, I have a robot dog leg and I have the inverse kinematics set up. The only problem is that one servo might move the end quicker than the other servo causing it not to be in a straight line. So how should i make the two servos reach the endpoint at the same exact time?

summary: i want two servos to move at different angles but take the same amount of time.

Move the servos in little steps (single degrees or microseconds) and calculate how long between steps. Use micros() to schedule the steps.

// Move all servos, each at their own speed, until they 
// have all reached their destinations.
bool StillMoving()
  bool moving = false;

   for (int i=0; i < ServoCount; i++)
    if (servo[i].position != servo[i].targetPosition)
      moving = true;
      if (micros() - servo[i].lastStepTime >= servo[i].stepInterval)
        servo[i].lastStepTime += servo[i].stepInterval;
        servo[i].position += servo[i].step;
  return moving;

It is indeed math, you have to calculate it.

Often the servo position is updated every 10ms or every 20ms. That makes it possible to control each servo motor independent. If the speed is set faster than the servo motor can do, then it will be behind a little and nothing bad happens.
Do you know the maximum speed of your servo motors ?

I made an example a few weeks ago (click on the start button in the middle-upper of the screen):

i do not know the maximum speed of the servo. I bought some cheap ones off of amazon

Command the servo to move 60 degrees, and use your stopwatch to time it.

I found the seller on amazon. It says that at 4.8 v it rotates 60 degrees in .18s without load

Cheap hobby servos rarely perform EXACTLY to specification. You need to test it yourself and you need to test each servo because they may not behave identically.


As has been stated move the servos a little bit at a time but, before the servos are moved do some math. You'll want to move the servos in proportional increments.

Say you want to move one servo 30 degrees and the other servo 60 degrees; 30:60. 30/60. 3/6. 1/2. So one servo will move 1 degree to the other servo moving 2 degrees per torque commend; to get the servos to arrive at the same time.


First, check your both servo should be the same. and here I am going to share the code and the tutorial in which I have used two servos. and both servo in synchronized.

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
Servo myservo1;

int pos = 0; // variable to store the servo position

void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object

void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 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 = 180; pos >= 0; pos -= 1) { // goes from 180 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

two servos with Arduino.

Ignore all the advice saying check if the servos move the same speed - if loaded differently they will not move at the same speed even if identical, so this is not useful.

#2 and #8 are definitely the correct approach - command them frequently in small steps so they are never allowed to be far from the desired position - you have to ensure you don't try to move them faster than their natural speed under load as they can only follow commands within their physical limitations.

In other words do position control on a frequent basis, not rely on any inbuilt speed control (which doesn't exist in normal servos).

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.