Using two servos but only one will work??

I am trying to get the basics of using a servo. I have done the single servo examples and they all work fine. I tried writing some sketches to use two servos but only one would ever work.

This is simple 2 servo sketch I got online. Which ever servo is assigned a pin first works, but not the second servo assigned. Same results on any pin I try.

I also tried the softwareservo library and some examples that use the SoftwareServo::refresh(); statement to keep multiple servo ports refreshed but I keep getting a error.

Here is the sample sketch.

#include <Servo.h>

Servo myservo;
Servo mysecondservo;

void setup()
{

myservo.attach(3); // attaches a servo connected to pin 3

mysecondservo.attach(15); // attaches a servo connected to pin 15
}

void loop()
{

myservo.write(180); // sets the servo position at 180 degrees

mysecondservo.write(65); // sets the servo position at 65 degrees
}

Any help would be appreciated.

What Arduino are you using?

...R

Simple servo test code for two servos. Note that servos need e3xternal power supplies.

//zoomkat 10-09-14 serial servo test
//type servo position 0 to 180 in serial monitor
//opposite side servos rotate together
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservo1;  // create servo object to control a servo 
Servo myservo2;

void setup() {
  Serial.begin(9600);
  myservo1.attach(8);
  myservo2.attach(9);
  Serial.println("servo-test"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the String readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured String 
    int n = readString.toInt();  //convert readString into a number
    myservo1.write(n);
    myservo2.write(180-n); //turns opposide servo in desired direction
    readString="";
  } 
}

I am using Arduino nano and I am powering the servos with a external supply.

Zoomkat--

I just tried your code and it mostly worked. The two servos moved but had a lot of jitter. They are MKS high voltage servos I took out of a plane because of the jitter. I will try two simple 9 gram servos and see what happens.

Thanks!

I tried two 9 gram analog servos and they worked fine.

Thanks for the help!

I still don't understand why in my sketch only the first servo assigned to a pin works????

I still don't understand why in my sketch only the first servo assigned to a pin works?

My standard arduino does not indicate a pin 15, so what is that equivalent to on a standard arduino?

I didn’t really pay attention in that sketch that it was pin 15. When I actually compiled the sketches I always tried pins 7 thru 10.

I just tried this sketch from you and it now also works with analog servos.

//zoomkat 10-09-14 serial servo test
//type servo position 0 to 180 in serial monitor
//opposite side servos rotate together
// Powering a servo from the arduino usually DOES NOT WORK.

String readString;
#include <Servo.h>
Servo myservo1; // create servo object to control a servo
Servo myservo2;

void setup() {
Serial.begin(9600);
myservo1.attach(7);
myservo2.attach(9);
Serial.println(“servo-test”); // so I can keep track of what is loaded
}

void loop() {

while (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the String readString
delay(2); //slow looping to allow buffer to fill with next character
}

if (readString.length() >0) {
Serial.println(readString); //so you can see the captured String
int n = readString.toInt(); //convert readString into a number
myservo1.write(n);
myservo2.write(180-n); //turns opposide servo in desired direction
readString="";
}
}

Do you have a link to your high voltage servos? Are you supplying the recommended voltage? Also Please read #7 below concerning posting code.:

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

http://www.mksservosusa.com/product.php?productid=145&cat=&page=3

They do have a operating frequency above 50hz.

I took them out of a giant scale plane and replaced them with Hitec servos. Looks like the next place they will get mounted is on a swap meet table.

Operating Voltage 6.0 ~7.4 V DC Volts

Those are large servos, so most likely you may have a power supply issue.

I was using a 2s lipo for the MKS servos. I think they are just crappy servos. That's why I took them out of my plane.

Here is video of my plane before and after I changed the servos.