the old multiple servo chestnut

i have written a programme that uses two potentiometers and two servos

the idea being that one pot A controls servo A

the other pot B controls servo B

the problem is that pot A seems to control both servos A and B , whilst pot B does what its meant to (control servo B only)

does anyone know why pot A is controling both?

another thing i find is that you get false signals being created on the pot or elsewhere that causes the servos to move on their own. its mooted that a changing voltage from the 5V pin connected to the pots can cause this

any ideas on how to make this programme work?

multiple_servo.pde (1.04 KB)

i adapted this programme for the servo programme

// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott http://people.interaction-ivrea.it/m.rinott

#include <Servo.h>

Servo A; // create servo object to control a servo
Servo B;

int potpin = 0; // analog pin used to connect the potentiometer
int potpinB = 5;// analog pin for second pot
int valA; // variable to read the value from the analog pin
int valB;
void setup()
{
Serial.begin(9600);
B.attach(13);// servo B attached
A.attach(9); // attaches the servo on pin 9 to the servo object
}

void loop()
{
valA = analogRead(potpin);

valB = analogRead(potpinB); // reads the value of the potentiometer (value between 0 and 1023)
Serial.println(valB);
valB = map(valB,0,1023,0,179);

valA = map(valA, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
A.write(valA); // sets the servo position according to the scaled value
B.write(valB);
delay(15); // waits for the servo to get there
}

i added the serialbegin/ serial.println to see exactly what the pot was doing intially. i used it to discover that one of the pots had flaked out on me and no longer worked.

i find that the serial monitor can be useful in finding out what is going on in the programme when it is running.

my general feeling is that arduino can'r operate multiple servos with the programme they provide as an example

for example if you adapt the knob programme it doesn't work

clearly theres something else at work that the programme can't give you as a clue.

wmeister:
my general feeling is that arduino can'r operate multiple servos with the programme they provide as an example for example if you adapt the knob programme it doesn't work clearly theres something else at work that the programme can't give you as a clue.

First learn to use the # in the post tool bar to put your code in a code box. Second, where is the provided example for using two pots with two servos that you mention?

ok i have rewritten the code i adapted from the "knob" programme that comes in the examples you can use

the idea is that two potentiometers are used to separately control two servos

the problem is this

when i turn pot A both servos operate simulataneously
when i turn pot B only pot b works (which is what i want)

potA and potB are connected 5V and ground with the middle pin supplying the analog input for the arduino

servo power comes via 6V battery pack the signal pin is connected to pins 9 and 13

for some reason the signal from pin 9 9the servo output for servoA is also making servoB operate

i can only think that i should put a diode on the ground wire of the servo to stop signals flowing up into the other servo???

as it is i am fast realising that pot control isn't so great for servos, any change in the voltage or anything else makes the servos shake a little from the set point

it would be nice to get this problem sorted out before i go ahead and do something with a joystick to control the servos and use something like "switchcase" to control the servos

// this has been robbed from the examples in arduino and adapted to control 2 servos instead of 1

#include <Servo.h> // arduino knows to look in this library for servo control
 
 Servo A;  // create servo object to control  servo A
 Servo B; // create servo object to control servo B
 
 int potpinA = 0;  // analog pin 0 used to connect the potentiometer
 int potpinB = 5;// analog pin 5 used to connect second potentiometer

 int valA;    // variable to read the value from the analog pin 0 
 int valB; // variable to read the value from the analog pin 5


 void setup() 
{ 
 
  Serial.begin(9600); // starts up the serial communication
 
  B.attach(13);// attaches servo B (signal wire connnected to pin 13 )
  A.attach(9);  // attaches servo A signal wire connected to pin 9)
} 
 
 void loop() 
{ 
  valA = analogRead(potpinA);// reads analog signal from pot A (value between 0 and 1023)
  valB = analogRead(potpinB);  // reads the value of the potB (value between 0 and 1023) 
  
  Serial.println(valB); // i added this to see what signal the analog pin was getting real time
  
  valB = map(valB,0,1023,0,179); // converts the analog signal to the degrees of movement of servo 
  valA = map(valA, 0, 1023, 0, 179);    // as above   
  
  A.write(valA);  // sets the servo position according to the scaled value 
  B.write(valB);   // set servo to position in degrees according to scaled value         
  delay(15);                           // waits for the servo to get there 
}

[code]

[/code]

What's the circuit you're using? How powerful is the 6V battery? What decoupling do you have on the servo supply? How long are the cables?

the circuit is both servos connected to negative battery pack as the return path to the batteries 6V AA pack in serial to run tiny servos ( i got them as exerimental only)

the ground pin of the arduino is connected to this negative. this must allow a return path for the signal being pumped out on the servo signal pins)

the positive of the batteries powers both servos

the signal cable comes from separate pins as dictated by the programme

no cable is longer than 4 inches (i've got a small breadboard linking all this stuff together)

(both pots eventually flaked out on me - bough tsome more yesterday)

it would be nice to get this going but if i can't i'll just move on

it might be a fault with the arduino its self, i wonder if the freetronics suffers from the same problem? for the moment i prefer the orignal product because they were the people who got the thing rolling - i've resisted the urge to buy knock offs.
from what i'm seeing the servos seem to shake very slightly around the set point .

they seem to be getitng a signal from elsewhere

a for position its seems better to use a digital joystick using microswitches and switchcase rather than analog control