Multiple Servos With Potentiometers

Hello this is my first time on the forums and I am having trouble controlling 4 servo motors with 4 potentiometers. When I test it on the Arduino all servos are being controlled by one potentiometer, I want each individual potentiometer to control its assigned servo. Here is my code and thank you for the help!

Robot_Arm.ino (2.06 KB)

Some multi servo/pot test code.

//zoomkat multi pot/servo test 3-23-13
//includes dead band for testing and limit servo hunting
//view output using the serial monitor

#include <Servo.h> 
Servo myservo1;  //declare servos
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;

int potpin1 = 0;  //analog input pin A0
int potpin2 = 1;
int potpin3 = 2;
int potpin4 = 3;
int potpin5 = 4;

int newval1, oldval1;  //pot input values
int newval2, oldval2;
int newval3, oldval3;
int newval4, oldval4;
int newval5, oldval5;

void setup() 
{
  Serial.begin(9600);  
  myservo1.attach(2);  
  myservo2.attach(3);
  myservo3.attach(4);
  myservo4.attach(5);
  myservo5.attach(6);
  Serial.println("testing multi pot servo");  
}

void loop()
{ 
  newval1 = analogRead(potpin1);           
  newval1 = map(newval1, 0, 1023, 0, 179); 
  if (newval1 < (oldval1-2) || newval1 > (oldval1+2)){ //dead band 
    myservo1.write(newval1); //position the servo
    Serial.print(newval1); //print the new value for testing 
    Serial.print("a,");
    oldval1=newval1; //set the current old value
  }

  newval2 = analogRead(potpin2);
  newval2 = map(newval2, 0, 1023, 0, 179);
  if (newval2 < (oldval2-2) || newval2 > (oldval2+2)){  
    myservo2.write(newval2);
    Serial.print(newval2);
    Serial.print("b,");
    oldval2=newval2;
  }

  newval3 = analogRead(potpin3);           
  newval3 = map(newval3, 0, 1023, 0, 179); 
  if (newval1 < (oldval3-2) || newval3 > (oldval3+2)){  
    myservo3.write(newval3);
    Serial.print(newval3);
    Serial.print("c,");
    oldval3=newval3;
  }

  newval4 = analogRead(potpin4);           
  newval4 = map(newval4, 0, 1023, 0, 179); 
  if (newval4 < (oldval4-2) || newval4 > (oldval4+2)){  
    myservo1.write(newval4);
    Serial.print(newval4);
    Serial.print("d,");
    oldval4=newval4;
  }

  newval5 = analogRead(potpin5);           
  newval5 = map(newval5, 0, 1023, 0, 179); 
  if (newval5 < (oldval5-2) || newval5 > (oldval5+2)){  
    myservo5.write(newval5);
    Serial.print(newval5);
    Serial.print("e,");
    oldval5=newval5;
  } 
  delay(50);  //to slow loop for testing, adjust as needed
}

Collinz4:
Hello this is my first time on the forums and I am having trouble controlling 4 servo motors with 4 potentiometers. When I test it on the Arduino all servos are being controlled by one potentiometer, I want each individual potentiometer to control its assigned servo. Here is my code and thank you for the help!

The code looks fine - how have you wired it up? My guess is you've connected only the first pot and
discovered it controls all the servos. That's entirely expected as you have floating inputs.

Yes my wiring was off, I bought an inexpensive breadboard and I believe it had some resistance problems. I looked at the signal with my oscilloscope and it had a ton of feedback. Thanks for the help and sorry for the late response back.