second servo does not turn but vibrates

hi everyone,

I use a 2 axis potentiometer joystick and two servos.

I used the simple program that you can find in the example programs of arduino. I upgraded it a little for two servos.

Also the servos are powered separately. (not via arduino board.)

Now, when I turn on the joystick, servo 1 works perfectly. If I turn the joystick to the other side (second axis), servo 2 will not turn like it should be.

I don't get it. I searched over the internet for codes and everytime i found some code it was just the same as mine...

this is the code:

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

#include <Servo.h>

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

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

void setup()
{
myservo.attach(5); // attaches the servo on pin 9 to the servo object
myservo2.attach(6);
}

void loop()
{
val = analogRead(potpin); // 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)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there

val2 = analogRead(potpin2);
val2 = map(val2, 0, 1023, 0, 179);
myservo2.write(val2);
delay(15);
}

any help is welcome

thanks in advance

KleineFille

That code looks ok to me- I don't see anything obviously wrong.

So two suggestions:

Enable Serial and add some serial.print lines so you can (for example) see the changes in val2 so you can see it's doing anything
Swop the wiring for the pots so you can see if they both actually work, ditto for the servos.

Sounds like a power issue.
Do you use the 5V pin of the Arduino to power the servos ?
The 5V pin can not supply enough current, not even for one servo.
You need a seperate power supply of 4.8 to 6V for the servos.

Erdin:
Sounds like a power issue.
Do you use the 5V pin of the Arduino to power the servos ?
The 5V pin can not supply enough current, not even for one servo.
You need a seperate power supply of 4.8 to 6V for the servos.

OP already said this....

Also the servos are powered separately. (not via arduino board.)