Controlling 2 servos at the same time

Hi there,

I am making an animatronic Wheatley from portal 2 and I am working on the eye lid movement at the moment. I have to eye lids which are about 8 cm across and are made out of foam. I am going to use two servos to move the eyelids.

I want to be able to control the servos at the same time, I will be using a 2 axis joystick to control the servos, but I will only use the up down motion to control the servos. I am very ignorant when it comes to this sort of thing. I am not sure what code I would need to write to control the servos using the joystick, could anyone help me with this? Any advice would be greatly appreciated :)

Many thanks

Rushmoore

The joystick produces a variable voltage which can be detected using analogRead()

You can use the value to cause a servo to move to a position determined by the voltage. Something like this crude example

void loop() {
   xaxisVal = analogRead(A0);
   servoPos = xaxisVal / 4; // to convert 0 to 1023 to 0 to 255 approximately
   myServo.write(servoPos);
   delay(100); // to allow time for servo to move - 50 might be enough
}

I don’t know how you want to control the second servo - should it be controlled separately ?

…R

I want to be able to control the servos at the same time, I will be using a 2 axis joystick to control the servos, but I will only use the up down motion to control the servos.

look at the servo "knob" example in the arduino IDE examples. You can connect both servo signal wires to the single arduino pin.