RC Timer servo--why it just runs when give it power

Hi, please help. I am desperate. I have to show my robot in 1.5 week, but this rc timer servo I bought just runs crazy.
The servo I bought is
http://www.rctimer.com/index.php?gOo=goods_details.dwt&goodsid=525&productname=
Here is my program:
#include <Servo.h>

#define LEFTFRONTSERVOPIN 6

Servo leftFrontServo;

void setup()
{
pinMode(LEFTFRONTSERVOPIN, OUTPUT); //sets the left servo signal pin to output
leftFrontServo.attach(LEFTFRONTSERVOPIN); //attaches left servo
Serial.begin(9600);
}

void loop()
{

}
As you may see, there is NO action in loop, but when I connect 1 servo to this program, it just moves by itself. Basically I tried, no matter what I put in the loop, the servo just moves by itself in a pattern. very strange, and I am desperate. What should I do? Could you please suggest some way to figure out why this servo behaves like this? Please help.

You don't need this line:

pinMode(LEFTFRONTSERVOPIN, OUTPUT);     //sets the left servo signal pin to output

.... but I have no idea if it being there will make the servo do what you describe.

How is it powered?- always better not to have it powered from the Arduino; rather from its own supply with the ground from the servo linked to the Arduino ground.

What you experience might be caused by the fact that the Servo library has a default setting (1500 microseconds) which is applied as soon as the servo is attached. This will move the servo arm to about its mid point position.

If this is the problem you could edit the file Servo.h to change the line

define DEFAULT_PULSE_WIDTH 1500

to some other value that suits your project.

Remember however that this value affects all connected servos. I am using a library called ServoTimer2 (which controls the servos using Timer2 rather than Timer1) and I have modified the attach command so that it takes an initial servo position as well as a pin number.

...R

This will move the servo arm to about its mid point position.

If this is the problem you could edit the file Servo.h to change the line
#define DEFAULT_PULSE_WIDTH 1500

There’s no need to modify the library (which would affect all connected servos) - you can “Servo.write” the default position for individual servos before you do the “attach”.

But I don't think that's the OP's problem: sounds to me like it's running amok (ok, he says moving in a pattern), not just finding its centre.

Re my comment on setting the servo pin as output: would that have any effect?

But I don't think that's the OP's problem:

Agreed: I was just trying to stop him modifying the library as per the suggestion.

Are the grounds connected?

That servo uses a lot of current. At 4.8V it needs 800mA at no load when running, 200mA idle.

I did acknowledge your point in the post you quoted from.

As far as I can recall I did try a prior Servo.write and it didn't work for me.

...R

AWOL: There's no need to modify the library (which would affect all connected servos) - you can "Servo.write" the default position for individual servos before you do the "attach".

Hi JimboZA, thanks for point out that extra line. I have removed it.
Another question is, you said:
—>rather from its own supply with the ground from the servo linked to the Arduino ground.
This is why I hesitated to connect servo to other supply. I read your line in a book but don’t quite understand it.
I have attached my board, could you please check my comment in there is correct way of connecting the breadboard for servo power? Many thanks in advance.

Hi, Afremont, I need your knowledge transfer. I actually do not understand what the "current" relationship to power supply etc (I am a software engineer not electric person. I'm shamed I forgot all the physics I learned in high school :blush:) So you said -->That servo uses a lot of current. At 4.8V it needs 800mA at no load when running, 200mA idle. Could you please explain to me how to understand this part--how to get 800MA? I connect this servo to arduino board's 5v slot, do you mean that slot does not have enough power to run this servo? If so, why does it just turn randomly (back and forth)? I see that no matter what I put in loop, the servo does NOT perform anything accordingly. So this is maybe due to power is not enough.

The power hungry servo cannot draw from the Arduino. You must have an independent supply. I see 4 servos up to 800ma each. Even 1 servo may toast the poor little arduino. 4 means smoke city. So yes use the 4 AA battery pack with common ground. Ultimately you would need LiPo's or NiMH for reasonable use.

What does your robot do?

The voltage regulator on the board cannot supply that much "current". The "voltage" is no problem, but there is simply not enough current available. Therefore, the regulator begins to "fold back" (reduce the output voltage) at some point the voltage drops enough that the chip browns out and goes into reset until the voltage comes back. I suspect this is happening rapidly and is responsible for the weird movements of your servo.

If you're just going to run one, then a 4-cell AA pack should do fine. If you want to run several, then you should look into a 6V lead acid battery.

charboing:
—>rather from its own supply with the ground from the servo linked to the Arduino ground.
This is why I hesitated to connect servo to other supply. I read your line in a book but don’t quite understand it.
I have attached my board, could you please check my comment in there is correct way of connecting the breadboard for servo power? Many thanks in advance.

I connect this servo to arduino board’s 5v slot, do you mean that slot does not have enough power to run this servo? If so, why does it just turn randomly (back and forth)?

Ok, so it seems you have connected the servo to the Arduino for power… all sorts of weird behaviour seems to happen when that’s how servos are hooked up. And of course it may damage the Arduino…

Have a look at the pic I’ve attached… note that the Arduino is powered in whatever way suits you, the servo has its own power, and the servo ground is connected to the Arduino ground. Yellow to Arduino i/o pin, of course.

Hi JimboZA, thanks for pic of servo connection. It is very clear. Now I know what to try. I have removed the line you mentioned (the one with OUTPUT). But the servo is still move as before with no action in LOOP. I will try to connect it to battery pack and see. But why does it even move in the first place? How can I avoid that? My robot is a walking robot--it walks on 4 legs. Each leg has a servo. I need to make them move in sync--ie, the front left moves same time as left back legs. Should I try Robin2 mentioned:

define DEFAULT_PULSE_WIDTH 1500

What does it mean? Would that stop the random movement? Thanks.

Hi Afremont, do you think 6V is enough for 4 servos? should I buy 6 volt 4.5 Ah Rechargeable Battery or not rechargeable? Do you think this one is ok: http://www.amazon.com/volt-4-5-Rechargeable-Battery-Electronics/dp/B002QGVW3K/ref=pd_sim_auto_4 I also need charger. Would this one work: http://www.amazon.com/Sealed-Lead-Battery-Charger-D1724/dp/B001G8AIMU/ref=sr_1_1?ie=UTF8&qid=1368125725&sr=8-1&keywords=6v+lead+acid+battery+charger Are you sure they would work? I have to demo my project next Sat. If this is the solution, I need to buy them today. Please help. Thanks.

Hi, one more crucial question: how do I connect that 6V battery to breadboard? Thanks

I have just been re-reading your initial post. You don’t say whether the problem only exists with one servo or if it happens with others as well?

Do the wiring as has been suggested and write a short Arduino sketch that just does servo.attach(pin) in setup() then connect your servo and report what happens. Also see what happens if you reboot the Arduino while the servo is connected.

I expect that this short code will make the servo arm move to about its middle position.

…R

That battery and charger should work fine.

You don't need more volts just because you have more servos. More than 6 volts will damage the servos. If you have more servos you need more amps.

Connect the battery to the breadboard with some single-core wire that can be plugged into the breadboard holes. Just make sure not to mix up the positive and negative. (I'm assuming there is no risk of the wire being accidentally pulled out).

...R

The lead acid battery is fine for bench testing, but probably too heavy for a moving small robot. For the actual robot LiPo (Lithium polymer) or NiMH should be used. Lithium's are now the batteries of choice.

Hi Robin2 and Joe,
Thanks for help. Regarding Robin2 question:

I have just been re-reading your initial post. You don’t say whether the problem only exists with one servo or if it happens with others as well?
the main problem was on all the servos. I tried one by one, all of them have same problem.

Now I read all of the posts and tried the new wire arrangement, well not lucky either: I don’t have 4 battery pack, I have 3 battery pack which I tried but nothing worked. The servo just does not move at all or give the buzzing sound.

So I plug in this power with LED and upload led program. the led is not lighting. I am sure the battery are new. Could it be battery pack has problem:
I have attached my wiring. I don’t know which line on battery is positive or negative, so I just switched the wire to try. neither way works.Is the wiring wrong?
If wrong, please correct me.