3

I currently have a servo wired to my Arduino and have imported the Servo.h. Here is my sketch:

#include <Servo.h>

Servo s1;
Servo s2;

void setup()
{
  Serial.begin(9600);

  s1.attach(8);
  s2.attach(9);
}
int pos = 0;
void loop()
{
  pos = 0;
  if(s1.read() != pos)
    s1.write(pos);
  if(s2.read() != pos)
    s2.write(pos);

  delay(1000);
}

The problem is that even when my servos are at the position 0 it still tries to turn and I hear it trying. What do I have to do to tell it to stop turning once it is already at the desired position?

So this is my second bit of code:

s1.write(0);
  delay(5000);
  s1.write(100);
  delay(5000);
  s1.write(180);
  delay(5000);

When I write them to 100/180 (or any number) they are silent after the turn, but when I write them to 0 I hear them keep trying to turn...

migrated from electronics.stackexchange.com May 16 '14 at 21:42

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

  • Can you command your servo to different positions and have it go there? Some cheap servos simply do not "settle" well. You can try making a little program to exercise them by cycling them between extremes at a moderate rate, you can even try taking them apart to clean. But the ultimate solution - assuming your PWM signal itself is reasonable and stable - may be to buy better quality servos. – Chris Stratton May 16 '14 at 20:18
  • I can turn them just fine, they work well. The real problem is that when I turn them to 100 they turn and stop, but when I turn them to 0 they dont... – Jister13 May 16 '14 at 20:19
  • I have edited my post with better info... – Jister13 May 16 '14 at 20:21
  • 1
    0 may not be within their mechanical range. How about you start at 100, and decrement that by 10 every couple of seconds, doing a serial print of the set value - and then see what they can get to without growling. Or better yet make a sketch where you can type a value on the serial and it will command that to the servo, letting you manually experiment. You can also print out a protractor scale and put a pointer on them and see where they stop moving. – Chris Stratton May 16 '14 at 20:24
  • 1
    Cheap servo. If 0 wont work, make 1 your center. – Passerby May 16 '14 at 20:43
2

The reason they keep trying to turn is mechanical. The physical stop in the gears is hit before the encoder/potentiometer reaches its end point.

You can make the servo stop fidgeting by completely relaxing it if you want. just use

s1.detach();
s2.detach();

and your arduino will stop sending any signal.

Bear in mind that "reading" the value of a servo in arduino gives you the servo's current set point, not its current location. Your code in unfortunately unaware of a servo's actual location. With that in mind, setting your servo to go to 0, waiting for it to get there with a delay, and then detaching it will have the desired effect, but since it will not maintain position and you will need to reattach it to function again, using 1 or 2 as your far left endpoint is likely the better option.

0

A common reason is could be because your servo cannot operate at a PWM signal of 0ms. For conservative limits, you should stay between 100ms and 2800ms even for very high quality servos. With lower quality servos that do not specify maximum and minimum values, conservative limits are 700ms to 2400ms.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.