4214Views12Replies

Author Options:

why does the arduino work with one servo but not two? Answered

well i got an arduino few days ago, just installed the sweep program on it and made it a little bit faster with the sweeping

heres the code:

// Sweep
// by BARRAGAN <http://barraganstudio.com>

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created

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

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

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

right so, it works with one servo, but as soon as i add a second servo the amber light starts to flash and the servos stop, and carry on strangely... why? is it the code? if it is plz tell me whats wrong...

I pasted the code so you can try it with your arduino, and i dont have to upload a vid :P

Thanks

12 Replies

user
Noodle93 (author)2009-02-21

Are you using a separate power supply for the servo's? If not there's your problem. You begin to overload the power, and it will essential 'crash'.

Select as Best AnswerUndo Best Answer

user
amando96 (author)Noodle932009-02-21

ohhh gotta be it, i am just using the 5v pin for both the servos...

Select as Best AnswerUndo Best Answer

user
Noodle93 (author)amando962009-02-21

Yep that'll do it. Just get a 4xAA battery pack and use that. Also pick up a 9v battery connector and some batteries :) Nothin beats having arduino without the wires!

Select as Best AnswerUndo Best Answer

user
amando96 (author)Noodle932009-02-21

i connected the servos to the 4xAA battery pack... and the 9v battery to the arduino, but the servos go mad and dont do what they are told... so is it suposed to only be the signal wires from the arduino to the servos? or is the red and black wire suposed to be connected to both the arduino AND the battery pack?

Select as Best AnswerUndo Best Answer

user
Noodle93 (author)amando962009-02-21

Ok. You need to have the signal pin connected to the arduino. Then connect the servo positive and ground pins in parallel to the battery pack. You then need to tie the grounds of the servo pins and the arduino ( I had this problem when I started). So just get a wire from the ground of the battery pack to the arduino. Hopefully you'll understand this. ;) have fun. P.S It's impossible to say how long it'll last on a 9v battery. But for one, I'm pretty sure arduino doesn't use that much juice, but the 9v battery has a low mAh (milli-ampere hour) rating so yeah. But it'll last long enough probably.

Select as Best AnswerUndo Best Answer

user
Wesley R Tech (author)Noodle932016-03-12

Im having the same issue. I am using a 2*AA pack for 2 servos. Only one works. If I try 4*AA they will both go?

Select as Best AnswerUndo Best Answer

user
amando96 (author)Noodle932009-02-22

ok so the signal wires and the GND wires are connected to the arduino? hey it worked! i dont understand why though... =/ is the GND partly a signal aswell?

Select as Best AnswerUndo Best Answer

user
BIGBUG (author)amando962009-03-03

Better late than never... Regardless of voltage all voltage supplies must share a common ground.

Select as Best AnswerUndo Best Answer

user
amando96 (author)BIGBUG2009-03-03

yer i've noticed with some other stuff aswell :)

Select as Best AnswerUndo Best Answer

user
Noodle93 (author)amando962009-02-22

No. But simply put. You're outputting voltage from Arduino to the servo via the signal pin, but it's not getting anything back! Remember, you can plug a LED into pin 13 and turn it HIGH but it won't do anything, the other end needs to be plugged into GROUND for electricity to flow! This is the flow of electrons! So we ground the arduino and the servo's so that everything flows. Have fun :)

Select as Best AnswerUndo Best Answer

user
amando96 (author)Noodle932009-02-24

yea i know that! lol but like it doesnt make sense :O i'm missing something... hmmm thanks a lot though, wouldnt get there on my own xD

Select as Best AnswerUndo Best Answer

user
amando96 (author)Noodle932009-02-21

yea i still have the 4xAA battery pack from the RC car :) and how long does an Arduino usually last with a 9v battery? thanks

Select as Best AnswerUndo Best Answer