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

Help with switch for servos!


Are you sure you copied the entire script, including the definition of the wait_for_button_press subroutine? I recommend that you try getting the example script working first before you modify it. This means you will have to move your button to channel 0 and put one servo on channel 1.



how do I include the definition? I will try from the beginning though thanks.


ok iv started from the beginning… and now its saying it cant find the main loop… or the button…


ok… got it!!! finally lol… thanks for that. now for adding another servo on channel 2 to do the same movement at the same time as servo 1… while another servo on channel 3 does another movement… if that makes sense. not sure if it can be done??


I am glad to hear that your script is working. It is possible to do that, but you would need to include a few extra lines in the “frame” subroutine to get your other servos moving. For example:

sub frame
  3 servo
  2 servo 
  1 servo

You would also need to set the positions you want your other servos to move to under the “main_loop”. For example, the line:

will set all three servos to position “4000”. You could then modify that line to set one of your servos to a position different than the other two. Good luck!



I was about to try this, but when I come back to it and set everything back up to test it as just 1 servo, now when ever I press the button it disconnects from the programme and flashes a red light 4 times?!?!?!


Hello. The Maestro user’s guide documents what a blinking LED at startup means:

[quote]When the Maestro is reset in some other way than being initially powered up, the red and/or yellow LEDs blink four times to indicate the reset condition:

  • Yellow off, red blinking: A brownout reset. This occurs when the Maestro’s 5 V line drops below about 3.0 V, usually due to low batteries or an inadequate power supply.[/quote]

This makes me think that you are having a power problem that only manifests itself when the servo draws a lot of current as it tries to move. If you are using batteries, please make sure they are freshly charged. Also, I bet you have your batteries connected to the Maestro’s VIN; it would help to disconnect VIN because then the Maestro’s processor can just be powered from USB.

If you continue to have trouble, please provide all the details about your setup, including pictures.



I need it to be powered without usb so it can be stand alone. also I have changed the battery to a 9v. the servo comes on an just keeps turning round in a 360 motion and will only stop when I disconnect the power.

I have the 9v powering the servo channels and also the processor. I cant figure out why it wont work because the setup hasn’t changed.


I run the script, and it only disconnects an cuts off when I press the button.


Unfortunately, powering servos with a 9V battery is not a good idea. Most servos are not built to tolerate voltages that high, and a 9V battery cannot provide the current needed to run motors. I strongly recommend that you switch to something better, such as four AA batteries. What were you using for power earlier?

Unless your servo is a continuous rotation servo, the behavior you describe makes it sound like the servo has probably been damaged.



I was using 3 as batterys. But was going to switch to 4. It needs to power 3 servos you see.


ok so I added a second servo. im now using 4 x AA batteries powering the servo’s and the switch. could this be the reason that when I run the script and press the button it moves both servos a little but then disconnects from the programme?


also when I disconnect the usb cable, a red light flashes 3 times when I press the button. do you think I should have 2 power supplies, 1 for the servo channels and one for the processor?


You should be able to use one power supply for the whole system. I suspect that when you are pushing the button to control your servos, your batteries’ voltage drops, which causes a “brownout reset”. The Maestro indicates that there was a brownout reset by blinking the red LED briefly. More information about this can be found in the “Indicator LEDs” section of the Maestro’s user’s guide.

What kind of AA batteries are you using? Are they freshly charged? How did you connect the batteries? A picture of your setup showing all the connections would be helpful. Also, please save a settings file using the Maestro Control Center and post it here so we can see your settings.



I have 4 AA batteries connected to the servo channels, but I want to be able to power the whole thing without having to use usb. any ideas?



The “Powering the Maestro” section of the Maestro’s user’s guide has a good explanation of how to wire the Maestro for one power supply.

- Grant


ok I have sorted all that, thanks for all your help.

is there a way to put a code in that will shut off the servo’s if 1 of them is out of time slightly with the other…

eg: both servos move from 2000 - 6000, but servo A reaches its maximum at 5900. so servo B keeps trying to move to its final point.

can I put a code in to shut off servo B after a slight delay of it trying to move. (realising it cant finish so shuts off)

iv tried fine tuning each servo (servo A 5993, servo B 5897) for example. but cant seem to get it right. they are prob mounted in slightly different places and not square to each other, so could do with this kind of ‘cut off’ code


To make the servos respond based on their position, you would need some sort of feedback system. This can not be accomplished with just standard hobby RC servos and a Maestro.

- Grant


thanks guys. really helped me out a lot. just need to get my led’s to blink few times after a short delay.

so… press button… slight delay… blinking leds’s, then stay on until button is pressed again.
iv looked at a couple of examples that I could find but no good. HELP ME PLEASE !


I see you posted a new thread on this; I will continue the discussion there.

- Grant