Attempt to Control 2 Servos Separately on 2 Pots

Hello! I'm relatively new to Arduino and these forums, but have had great success with Adafruit's tutorials and use of the Wave Shield, Motor Shield (with stepper and DC motors, and 1 servo), and some other components (relays, LEDs, etc) .

I am now trying to control 2 servos separately on two individual potentiometers. I can run one servo on one pot, or run both servos on the same pot, but I cannot run both individually (in hopes of eventually creating a pan/tilt head, then attaching it to my parallax 27800 joystick).

I am using the Arduino Uno.

Here's what I see as the problem:

In a sketch, I can give the command for "myservo1.attach(9)" or "myservo2.attach(10)" without problems, but as soon as I add both, pins 9 and 10 connect to each other (I read about 40ohms resistance on my meter). They do this directly from the Arduino Uno, even with the motor shield removed.

I removed the motor shield and all components then attached my meter to pins 9 and 10, then went through the sketch and added one line of code at a time and waited for the meter to read a connection, and it was definitely at the inclusion of two attach commands.

When I use the example sketch "bare minimum" there is no connection.

However, when I use this next sketch, digital pins 9 and 10 read 43ohms of resistance between each other (connected!):

#include <Servo.h>

Servo myservo1; // create servo object to control a servo
Servo myservo2;
int potpin1 = 0; // analog pin used to connect the potentiometer
int potpin2 = 1;
int val; // variable to read the value from the analog pin

void setup()
{
myservo1.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(10);
}

void loop()
{
}

Since 9 and 10 are my signal pins, I think it will be impossible to make this work without help.

Ideally, this was the sketch I was planning to use:

#include <Servo.h>

Servo myservo1; // create servo object to control a servo
Servo myservo2;

int potpin1 = 0; // analog pin used to connect the potentiometer
int potpin2 = 1;
int val; // variable to read the value from the analog pin

void setup()
{
myservo1.attach(9); // attaches the servo on pin 9
myservo2.attach(10); // attaches the servo on pin 10
}

void loop()
{
val = analogRead(potpin1); // reads the value of the pot
val = map(val, 0, 1023, 0, 179); // scale it between 0 and 180
myservo1.write(val); // sets servo according to the scaled value
val = analogRead(potpin2); // reads the value of the pot
val = map(val, 0, 1023, 0, 179); // scale it between 0 and 180
myservo2.write(val); // sets servo according to the scaled value
delay(15); // waits for the servo to get there
}

... but this just makes my two servos move in sync, because the signal wires are connected (at least that's what I think)!

Thanks in advance for any help! I can provide screen shots if needed, but I've tried so many configurations, and I think I've identified the problem, I just can't find the solution!

Regards,
Jason

Thanks for your response!

I believe the two signal wires were connecting to each other because the resistance between them changed from infinite to 40ohms. I only moved on to sticking my meter onto things because I was out of options before bothering someone more knowledgeable.

On your advice, I won't be metering pins in the future.

I could successfully use "sweep" and "knob," but then when trying to use two servos they'd always move in unison.

However, after your post I took everything back out, set it all up again, and it worked perfectly using the code I pasted at the end of my last post. I've been known to get upload and communication errors frequently (always solved by unplugging USB and closing the arduino interface, then restarting).

The case could be made that I wired something wrong the first 100 times I tried it, but I put it back together in a heartbeat by memory so that too seems unlikely.

I have no idea why it works now, but didn't before.

In any case, thanks for your response, and I'll try not to post any more stupid questions!

Thanks again,
Jason

Could have been some type of artifact of using a single val for both servo positions.

I'll pretend it was that, then, and hold on to a little of my pride. Thank you both for your responses!

Hi, i found this page searching for a similar problem. here is my sketch based off the arduino example sketch. notice the val2 near the bottom..even in the parentheses.
Only problem i found is that my second servo has random oscillation or noise. It jiggles back and fourth untill i slightly tap my joystick/pot.
Any how i'm pretty brand new to this any advice is appreciated.

// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott

#include <Servo.h>

Servo myservo; // create servo object to control a servo
Servo myservo2; // create servo object to control a servo

int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int potpin2 = 1; // analog pin used to connect the potentiometer
int val2; // variable to read the value from the analog pin

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