Servos act like the have Parkinsons Disease

After I change position of my servos the twitch back and forth for a few seconds. It seems to happen more often when the position is closer to 0 or 180. Does anyone know why? I’m using Tiankong RC 180 degree servos and a standard 10k pot. Here’s some code. I noticed when I include code to use an additional pot and servo connected to A1 and pin 10, they never stop twitching. The problem also happened when I tested with other servos. Thanks for any help.

#include <Servo.h>
Servo myservo;
int potpin = 0;
int val;
void setup()
{
myservo.attach(9);
}
void loop()
{
val = analogRead(potpin);  
         
         
val = map(val, 0, 1023, 0, 179); 
         
         
myservo.write(val);    
         
delay(15);      
}

Parkinson's disease is not funny.

It sounds like the pot is giving inconsistent readings. What do you see if you print val ?

How are the servos powered ?
Not from an Arduino 5V pin I hope

I keep getting a value of 17974, no clue why and yes, theyre powered from the arduino 5V pin right now but I was getting the same result last week when I had a separate 6v source.

Post code, post a schematic.

I’m now using this code and it seems to get even worse. Only difference is that I added a pot for A2 and output to pin 10.

//This is a sketch to control two potentiometers

//The map value may need to be adjusted depending on the roataion of the servos


#include <Servo.h>

Servo myServo1;                     //create servo1 object
Servo myServo2;                     //create servo2 object

int potPin1 = 0;                   //potPin1 is connected to analog pin 0
int potPin2 = 1;                   //potPin2 is connected to analog pin 1
int val1;                          //variable to read value for potPin1
int val2;                          //variable to read value for potPin2

void setup() {
  myServo1.attach(9);               //attach servo on pin 9 to servo1 object
  myServo2.attach(10);              //attach servo on pin 10 to servo2 object
}

void loop() {
  val1 = analogRead(potPin1);                   //reads the value from potPin1
  val1 = map(val1, 0, 1023, 0, 180);            //scale val1 to use with myServo1
  myServo1.write(val1);                         //set position of servo1
  delay(15);                                    //wait for the servo to get there

  val2 = analogRead(potPin2);                   //read the value from potPin2
  val2 = map(val2, 0, 1023, 0, 180);            //scale val2 to use with myServo2
  myServo2.write(val2);                         //setPosition of servo2
  delay(15);                                    //wait for servo to get there

}

knob_bb.png

Bluenick2100:
I keep getting a value of 17974

Where is this code?

I didnt save it when I closed and reopened the sketch

Well, include something like Serial.println(val1); and Serial.println(val2); and lengthen the delay to 500 so you can see what is being sent to the servos in the serial monitor.

Bluenick2100:
I didnt save it when I closed and reopened the sketch

Each time you upload or compile your code it is automatically saved to your sketchbook area.
It is still on your HD.
Look at File, Open Recent.
Where did you get the "value of 17974" from?
Ops circuit.
knob_bb.png
When you used an external 6V supply, did you keep the gnd of the UNO and the gnd of the servo connected?
Thanks.. Tom.. :slight_smile:

Each time you upload or compile your code it is automatically saved to your sketchbook area

Not quite true as that behavior can be turned off in File->Preferences

I turned it off to stop the IDE overwriting a previous version when a change is made and compiled. I would rather have file versions under my control by saving with a new name when I decide having made changes

theyre powered from the arduino 5V pin right now

That is the problem.

Use a separate power supply, capable of at least 1 Ampere per servo. Don’t forget to connect the grounds.