Servo control

Hello

I am new to ardupilot and arduino and just wanted to ask a quick question about servo control. I have tried as a start using software control for servos via the code below with the mux pin set high for testing. However the servos do not seem to respond regularly or reliably. Is there any reason someone can tell me why this does not work?

if(input_servo == 0) {
for(int i = 0; i <= 180; i++) {
servo.write(i);
delay(50);
servoVal1 = servo.read();
Serial.print(servoVal1);
Serial.print(" ");
}
}

Thanks
Sirk

Two things:

First, the delay(50) might be too short. Servos are mechanical devices and take time to move.

Second, how do you have the servo powered? If you're powering it directly from the Arduino then electrical noise and/or load might be affecting the processor. I have personally seen this happen. Powering the servo from an independent power supply solved the problem (make sure to connect the grounds between the Arduino and servo power supply).