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;
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);
}
}
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.
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"