Jitter with 3 Independently Controlled Servos using 3 Potentiometers

Hi Guys
New to the Ardunio community and programming.
I wanted to automate my shutters with servos and I am using the following code:

#include <Servo.h>

Servo servo1;
int potpin1= 0;
int val1;

Servo servo2;
int potpin2 = 1;
int val2;

Servo servo3;
int potpin3 = 2;
int val3;

void setup ()
{
servo1.attach (2);
servo2.attach (4);
servo3.attach (6);
}

void loop ()
{
val1 = analogRead (potpin1);
val1 = map (val1, 0, 1023, 0, 179) ;
servo1.write (val1);

val2 = analogRead (potpin2);
val2 = map (val2, 0, 1023, 0, 179) ;
servo2.write (val2);

val3 = analogRead (potpin3);
val3 = map (val3, 0, 1023, 0, 179) ;
servo3.write (val3);

delay(15);
}

WIth this code there is a lot of jitter and interference. Can someone explain where I am going wrong.
THank you

It looks like you have one of the servos connected (at least logically - you haven't given a wiring diagram) to the same pin (2) that is defined for potPin3.

You also shouldn't be using pins 0 and 1 as they are used by the Serial comms.

If this is the problem it would have been avoided if you had defined the servoPins as in

Servo servo1;
int servoPin1 = 2;
int potpin1= 3; 
int val1;

and later

servo1.attach (servoPin1);

...R

It looks like you have one of the servos connected (at least logically - you haven't given a wiring diagram) to the same pin (2) that is defined for potPin3.

I assumed that the pot was wired to an analogue input pin.

Uncompiled, untested

#include <Servo.h>

const byte potPin [3] = {0, 1, 2};
const byte servoPin [3] = {2, 4, 6};
Servo servo [3];
const int nServos = sizeof (servoPin) / sizeof (servoPin[0]);

void setup ()
{
  for (int i = 0; i < nServos; i++) {
    servo[i].attach (servoPin [i]);
  }  
}

void loop ()
{
  for (int i = 0; i < nServos; i++) {
    int val = analogRead (potPin[i]);
    val = map (val1, 0, 1023, 0, 179) ;
    servo[i].write (val);
  } 
}

How are you powering the servos?

Good morning. The potpins are analog and the servo pins are digital.
I am powering it through the Arduino Due board. 5v and ground on the bread board.
How can I do the schematic on this website?
Thank you

Also in the last sketch, it says that 'val1' was not declared in this scope.
I have downloaded Fritzing, Will figure it out and get a schematic up.
Thanks

The forum doesn't give a means of producing a schematic, but you could easily draw it by hand and take cellphone pic. Or try Fritzing. Upload by choosing Additional Options below the typing area.

If you mean that the servos are provided by 5v from the Arduino via breadboard, you certainly don't want to do that..... give them their own 5-6v from a supply that can provide about 1A each. Then hook the ground (0v) from the motors and the battery to the Gnd of the Arduino.

val = map (val, 0, 1023, 0, 179) ;

I did say it wasn't compiled.

You need to power the servos from a separate supply, like four AA batteries.

Hello
Thank you so much.
There is still a bit of jitter at the ends of the movement but a lot better.
Also, what does this mean?:

const int nServos = sizeof (servoPin) / sizeof (servoPin[0]);
for (int i = 0; i < nServos; i++) {

Imagine, some time in the future, you want five servos, not three.
Just put the new pin numbers in the array and recompile.
It's just simple future-proofing, and saves you having to trawl through your code and change every "3" to a "5"