Trembling/Shaking Servo

 Hello Guys I'm really new in working with Arduino and I have a question to you. 

 So I actually made a more or less nice project for my knowledge and just have one little but annoying
 problem. I wanted to do 2 little "robot-arms" one with two potmeters which are connected with two 
 servos 
 on the other arm.The servos should move to the same position as the pots are. But strangely the more 
 the 
 pots move, the more the servos begin to tremble/shake. I would like to know if I could change this and 
 how. 

 this is my code btw. 


/*
  Controlling two servo positions using two pots (variable resistors)
  by Fernando Meier
*/
#include <Servo.h>

Servo myservo;  
Servo myservo2;   //crate two servo object to control two servos

int potpin = 0;
int potpin2 = 2;    // analog pins used to connect the potentiometers
int val;  
int val2;    // variables to read the values from the analog pins

void setup() {
  myservo.attach(9);    // attaches the servo on pin 9 to the servo object
  myservo.attach(10);   // attaches the servo on pin 10 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, 180);     // 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

  val2 = analogRead(potpin2);          // reads the value of the potentiometer (value between 0 and 1023)
  val2 = map(val2, 0, 1023, 0, 180);   // scale it to use it with the servo (value between 0 and 180)
  myservo2.write(val2);                // sets the servo position according to the scaled value
  delay(15)                            // waits for the servo to get there
}

2Servos_pots.ino (1.31 KB)

Why don’t try this bit of code and share what you see on serial? Could be the pot values are not steady… and of course there is some level of ‘bounce’ as you move the pot knobs

/*
  Controlling two servo positions using two pots (variable resistors)
  by Fernando Meier
*/
#include <Servo.h>

Servo myservo; 
Servo myservo2;   //crate two servo object to control two servos

int potpin = 0;
int potpin2 = 2;    // analog pins used to connect the potentiometers
int val; 
int val2;    // variables to read the values from the analog pins

void setup() {
  Serial.begin(9600);   //open serial port
  myservo.attach(9);    // attaches the servo on pin 9 to the servo object
  myservo.attach(10);   // attaches the servo on pin 10 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, 180);     // scale it to use it with the servo (value between 0 and 180)
  Serial.print("Pot 1 val : ");
  Serial.println(val);
  myservo.write(val);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there

  val2 = analogRead(potpin2);          // reads the value of the potentiometer (value between 0 and 1023)
  val2 = map(val2, 0, 1023, 0, 180);   // scale it to use it with the servo (value between 0 and 180)
   Serial.print("Pot 1 val : ");
  Serial.println(val2);
  myservo2.write(val2);                // sets the servo position according to the scaled value
  delay(15)                            // waits for the servo to get there
}

You could also try writing to servos only when pot values have changed since last write.