Using 3 servomotor one by one(one after the other)

Hi,
I got some problem with my arduino code.
Actually I want my servomotor turns one after other.
But at the beginning, the three turns in the same time, and after turn one by one.
If you know how solve this problem.
I use Tinkercad.

Here the code I using:

#include <Servo.h>

Servo myservo1; // create servo object to control a servo
Servo myservo2;
Servo myservo3;

int pos1 = 0; // variable to store the servo’s starting position
int pos2 = 0;
int pos3 = 90;

void setup()
{
Serial.begin(9600);
myservo1.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(10); // attaches the servo on pin 10 to servo object
myservo3.attach(11); // attaches the servo on pin 11 to servo object
}

void loop(){

for (int position = 0; position <= 90; position++) {
myservo1.write(position);
delay(15);
}

for (int position = 90; position >= 0; position--) {
myservo1.write(position);
delay(20);
}

for (int position = 0; position <= 90; position++) {
myservo2.write(position);
delay(25);
}

for (int position = 90; position >= 0; position--) {
myservo2.write(position);
delay(25);
}

for (int position = 90; position <= 180; position++) {
myservo3.write(position);
delay(25);
}
for (int position = 180; position >= 90; position--) {
myservo3.write(position);
delay(50);
}
}

It's from another site, I don't remember who
Thanks for your answers

When you attach a servo it moves to it's default position of 90 degrees. You can do a write before the attach to change that, but depending on the actual position of the servo at startup, you may still get some movement.

The only way to avoid servo movement when the power is on is to do the following:

  • Attach the servo
  • Set a known start position
  • Switch on the power (e.g. 5V) for the servo.
    This is only possible with your own hardware that can switch the servo supply.

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