3
\$\begingroup\$

I'm using the sparkfun inventor's kit. I'm using the code listed at the end fo this post, to controll a servo with a potientiometer using the arduino.

Unfortunately, the servo behaves very jumpy. Even if the value written to the servo does not change, it keeps jumping forward and backwads very fast by ~5-10°.

I also tried the same thing but using a soft potentiometer instead of the bend mesure and the 10kO resistor. The servo was jumping in the same way.

Any ideas how to fix that?

Circuit overlay:

enter image description here

#include <Servo.h> 

Servo myservo;  // create servo object to control a servo 

int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin 

void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 

void loop() 
{ 
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023) 
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
  myservo.write(val);                  // sets the servo position according to the scaled value 
  delay(15);                           // waits for the servo to get there 
} 
\$\endgroup\$
12
  • 1
    \$\begingroup\$ Does the jumping get better/slower when you increase the delay(15) to eg. delay(500)? \$\endgroup\$
    – jippie
    Commented Dec 16, 2012 at 21:33
  • \$\begingroup\$ And does the servo respond to changing potentiometer setting? \$\endgroup\$
    – jippie
    Commented Dec 16, 2012 at 21:52
  • \$\begingroup\$ What do the servo pulses look like on a scope? If they're rock-solid, then the problem is in the servo itself. If they're jumping around too, then something on the Arduino (an interrupt?) is interfering with the execution of the Servo library. If you're debugging servos without even a rudimentary scope, you're probably in the wrong line of business. \$\endgroup\$
    – Dave Tweed
    Commented Dec 17, 2012 at 0:38
  • 1
    \$\begingroup\$ Hard code a value for the servo in the program. Change val = map(val, 0, 1023, 0, 179); to val = 500; and see if the servo stabilizes. If it is still jumpy it must be the servo or your powersupply. If it is not jumpy it is the input circuitry. \$\endgroup\$
    – jippie
    Commented Dec 17, 2012 at 19:08
  • 1
    \$\begingroup\$ I can reproduce the nervous servo with the soft pot, I can only make it steady when I hold my finger steady on the softpot. If I don't, the servo starts to wiggle. Adding a small capacitor (I added 220nF) between ground and pot output (middle pin) stops the wiggling. Your simply picking up static. \$\endgroup\$
    – jippie
    Commented Dec 21, 2012 at 20:39

1 Answer 1

5
\$\begingroup\$

I can reproduce the nervous servo with the soft pot and flex sensor. In case of the soft pot I can only make it steady when I hold my finger steady on the soft pot. If I don't, the servo starts to wiggle.

Adding a small capacitor (I added 100nF or 220nF) between ground and pot output (middle pin) stops the wiggling. Your simply picking up static.

Keep wires to the soft pot close to each other, don't make big loops in between them. You could braid them together for example. This and the small cap will reduce the picked up static and with that stop the wiggling.

The soft pot has an extremely high impedance on its middle pin when it is not touched. I guess it is only makes contact to the resistor when actually being touched. This explains why the servo gets nervous when the soft pot is not used. The middle connection is basically a loose wire → antenna and the analog input of the microcontroller is very sensitive / high impedance.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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