Pololu Robotics & Electronics
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

One button to control two servos


Thanks for your help to get me this far.

I think I’m almost there but have got myself into a mess, as usual.
All buttons control each servo independently and all works fine.

My last task is this:
button_a controls one servo -1
button_b to control servo 3 and 5 clockwise
button_c to control servo 3 and 5 anticlockwise


button_a if 100
else 4000

button_b if 100
else 4000

button_c if 8000
else 4000


sub button_a
0 get_position 1 less_than

sub button_b
2 get_position 1 less_than

sub button_c
4 get_position 1 less_than

sub sequence_a

1 servo 10 delay


sub sequence_b
3 servo 10 delay

sub sequence_c

5 servo 10 delay

I can get the individual servos to go clockwise or anticlockwise but can’t seem to get the two working together.
I even put both servos on a y lead and put on channel 5 but that didn’t seem to work.

Is there a way to do this please?





It is not entirely clear to me how you want those servos to interact with the buttons. In your original thread, it sounded like you wanted the servos to be in one position when a button is pressed and another when that is released; is that still the case? If you are trying to move multiple servos when the buttons are pressed and released, it might be easier to have separate subroutines for each case. Can you give an example of how you want servo 3 and 5 to react to each button being held and released?

By the way, it looks like you are using a target position of 100 when button_a and button_b are pressed; please note that this is not a valid target position, since it is outside of the possible range of values, so the Maestro is using the minimum position you have configured for each of those channels.



Hi Brandon,

Thanks for the reply.

I’m making an animatronic head!
So when I press button b I would like servo 3 & 5 to move to the left and when I press button c they look to the right. When I release the button they go back to the mid, or looking straight ahead, position.

I’ve also been playing with the values to see what the maximum and minimum values were to get the full range of movement.

I’m still very new at this and I’m learning through your help and experimenting!

Thanks again,



Thanks for the clarification. In that case, one way you could get that kind of behavior would be to use nested IF statements. Since you are moving the same 2 servos in both cases, you can also use the same (modified) subroutine to move them. For example:

button_b if			            #if button_b is pressed
  4000 8000 sequence_b	        #move servos in one direction
  else button_c if			    #if button_b is not pressed and button_c is
    8000 4000 sequence_b  	    #move servos in the other direction
    else				        #if neither button is pressed
      6000 6000 sequence_b  	#move servos to center

#with this modified sequence_b subroutine
sub sequence_b
  5 servo
  3 servo
  10 delay

Note that this subroutine needs to be passed 2 servo positions when it is called. In this example the first number will be for servo 3 and the second number for servo 5 (e.g. 4000 8000 sequence_b should apply the 4000 to servo 3 and the 8000 to servo 5).

By the way, if you are trying to find the range of your servos, you might find the answer to the “How do I use my Maestro servo controller to get the maximum possible range of motion from my servo?” question in the FAQs tab of the Maestro product page helpful.



That has worked perfectly, unfortunately when using on the eyes, on eye goes one way and the other in the opposite direction once button_b is pressed and the reverse happens once button_c is pressed :slight_smile:
I know I can get a piece of hard ware to reverse that servo but I was wondering whether there was a way to reverse one servo through code.




Done it :slight_smile:
Thanks anyway for your amazing help, it s REALLY appreciated!