(noob) 2 servos for robot (head & chest) movement at different speeds at once I have an Arduino Uno and two Hi-tec Servos HS-40 &amp; 5055 digital that I'm using for a basic robot build. I'm trying to have 1 servo(HS-40) turn the head back and forth (left to right) slightly faster than other servo (HS-5055) controlling the upper torso. I would like to have each servo working at the same time but not at the same speed without waiting for 1 servo to complete it's movement. I tried a sketch with a delay of 45-50 which seems to work fine for the movement speed and 0-75 degrees is ideal for the head travel and 0-65 degrees for the torso travel. I would like to have this movement to be repeated continuously so the robot mimics like his is looking side to side or left to right naturally. Please help as I tried many sketches but can't find one that works like this. I tried modifying other codes but can't get them work. Any help will be greatly appreciated.
How do modify this code so just the second servo runs at 40 which will slow down just enough? Also this is not my code, but it's one that seems to be close to what I'm trying to do.
#include &lt;Servo.h&gt;

Servo servo1; 
Servo servo2;

int i = 0;

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

void loop() {
  for (i = 0; i &lt; 70; i++) { 
    servo1.write(i);              
    servo2.write(i);     
    delay(50);                      
  }
  for (i = 70; i &gt; 0; i--) { 
    servo1.write(i);                
    servo2.write(i);     
    delay(50);                      
  }

}
Heres a little sketch you can try.  It uses timing to accomplish the different servo speeds.  It won't give you the exact servo travel each loop but it sounds like you might not mind if it randomly is off by a few degrees each loop.
#include &lt;Servo.h&gt;
Servo servo1;
Servo servo2;
int i = 0;
void setup() {
  Serial.begin(9600);
  servo1.attach(8); 
  servo2.attach(9); 
} 

int sweep_time = 3500; // 70 * 50ms = 3500

int head_degrees = 75; // sweep degrees for the head to move
int body_degrees = 65; // sweep degrees for the body to move

int millis_per_head_move = sweep_time / head_degrees;
int millis_per_body_move = sweep_time / body_degrees;

void loop() {
  int i = 0; int j = 0;
  unsigned long now_millis = 0;
  unsigned long start_sweep = millis(); // mark the time when we start the first sweep
  
  while ( millis() - start_sweep &lt; sweep_time ) {  // keep moving first sweep until sweep time has elapsed
    now_millis = millis() - start_sweep;
    if (now_millis % millis_per_head_move == 0 ) servo1.write(i++);
    if (now_millis % millis_per_body_move == 0 ) servo2.write(j++);
    delay(1);
  }
  Serial.print(i); Serial.print(&quot; &quot;); Serial.println(j);
  
  start_sweep = millis();  // mark the time when we start the second/back sweep
  while ( millis() - start_sweep &lt; sweep_time ) {  // keep moving second sweep until sweep time has elapsed
    now_millis = millis() - start_sweep;
    if (now_millis % millis_per_head_move == 0) servo1.write(i--);
    if (now_millis % millis_per_body_move == 0) servo2.write(j--);
    delay(1);
  }
  Serial.print(i); Serial.print(&quot; &quot;); Serial.println(j);
}