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