Problems with running 2 servos at the same time with pot

Hi,

I am trying to controle 2 servos with 2 pots, making one servo go with one pot is no problem, but when I ad the second servo and pot to the program, it starts bugging.
when I am turning one pot one servo moves fine, but when I turn the other pot both servos starts moving!!

Whats wrong? Any respons is good respons.

Sorry for the bad english :wink:

Here is one of the codes I have tryed, (tryed different codes, different AI, different PWM Out and different libraryes but it is always the same)

#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); // attaches the servo on pin 10 to the servo object

}

void loop()
{
val = analogRead(potpin1); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 179, 0); // scale it to use it with the servo (value between 0 and 180)
myservo1.write(val); // sets the servo position according to the scaled value
val = analogRead(potpin2); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo2.write(val);

delay(15); // waits for the servo to get there
}

  1. What power supply are you driving the servos from? If you are driving them from the Arduino +5v supply, it is likely that 2 servos will overload the +5v supply, especially if you are powering it from USB.

  2. What value potentiometers are you using? If they are greater than about 47K then they will interfere with each other. The usual workaround is to read the analog pin twice and discard the first reading. If the pots have a value greater than about 220K, you may need to insert a delay between the two readings.

I am using the standard 10K pot that comes with the arduino and the 10K touch sensitive resistor.

Tried with seperate power to the servos but no change.

Tried with seperate power to the servos but no change.

Were the grounds common between the separate supply and the arduino? They need to be.

If so try powering one servo from the separate supply and the other from the arduino as you had before.

The grounds are common.

Tried to power one servo from the arduino and the other from the seperate supply, but no change.

Has to be a problem with the interfering signals.

Cricetus:
I am using the standard 10K pot that comes with the arduino and the 10K touch sensitive resistor.

How have you connected the pot and touch sensitive resistor to the Arduino?

Common 5V and ground from the arduino bord, and the midpin`s as signal to AI 0 and AI 1 on the arduino

Try increasing
delay(15); // waits for the servo to get there
to something more realistic like:-
delay(250); // waits for the servo to get there

Check the voltage on the two supplies.
Change the code so that the number you send out to the servos is displayed (use a Serial.print() ) to see that you are sending steady values.

Cricetus:
I am using the standard 10K pot that comes with the arduino and the 10K touch sensitive resistor.

Which is the pot that interferes with the other one?

Have you got the specification of the touch sensitive resistor?

10K touch sensitive resistor.

These do not give an output when not touched, the inputs are left floating.
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

That is probably the cause of your problem. You need an additional 10K resistor from the input to ground on your touch sensor.

The 10k resistor solved the problem:D
Great respons from the forum, thanks!