2 servos causing problems?

Hi,

Trying to figure out this chronic problem every time I want to run more than 1 servo on a program.
If I use the sample servo sweep program with only the ONE servo, it sweeps smoothly in both directions at the same speed as it should.
However, if I try to simply copy and paste the program and add a second servo, both servos either rotate slowly in one direction and snaps back to its starting point repeatedly or snaps to the end point and rotates smoothly back to its starting point.
Ive double checked everything but this has been a constant issue. Seems like they're both interfering with each other.
Maybe digital vs analogue servos are the problem?

Any help greatly appreciated.

Thank you so much.

How would you expect someone to help you with your code if they cannot see your code?

Post your code using code tags.

Do you use the 5V pin of the Arduino board to power the servo motors ? That 5V pin is not even strong enough for one servo motor.

This is because a simple copy and paste will use the same variables. Each servo needs its own name both for the attach command and the servo write command.

@Kirwin, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with your project :wink: See About the Installation & Troubleshooting category.

Please post your code.
Please provide a wiring diagram; reasonably sized photo (around 300kB) of handdrawn one is fine.

hi. Sorry about that. Here it is but its an exact copy of the example code for the one servo sweep but with 2 servos.
Thanks so much.

#include <Servo.h>

Servo myservo1; // create servo object to control a servo
Servo myservo2; // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0; // variable to store the servo position

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

void loop() {
for (pos = 90; pos <= 0; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 0; pos <= 90; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 90; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position

}

for (pos = 0; pos >= 90; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}

Hi. No. I'm running the 2 servos through a 6 volt AA battery pack. Ive had the same problem even when using an adafruit motor controller so voltage or current doesn't seem to be the issue

Thanks

Can you please edit post #6, select all code and click the </> button to apply code tags and next save your post. It makes it easier to read, easier to copy and prevents the forum software from incorrect interpretation of the code.

Do these make any sense ?

1 Like

Try a pos = +1 and pos= -1 for each servo - (like Sweep). Not two +s for 1 servo and two -s for the other.

Post/duplicate LOCKED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.