1 program, 2 servos, 2 different outcomes?

Hello,

I'm new to arduino and electronics and I am a little bit confused.
I recently bought a starter kit and I've been playing around with
a toy servo that came with it. In particular, it is a Hextronik
HXT900 9GR servo. I include <Servo.h>, the library that comes
with the arduino IDE and I have no problems with running simple
code, like the following:

#include <Servo.h>
Servo myservo;
void setup() {
 myservo.attach(9); //Attach servo on pin 9   
}
void loop(){
myservo.write(0);
 delay(3000);
 myservo.write(120);
 delay(3000);
}

However, if I try to use any code, even a simple one like
the above with a bunch of "Tower Pro MG90S" servos that
I bought separately, I get a seemingly random behaviour.
The servo moves for a little bit, then stops, then goes back
and forth like crazy for a second or two, then makes clicking
noises.. I tried several brand new MG90S's and it is the same
"random" behaviour, wheras the HXT900 works fine.

Could you please give me any insight why this happens and
if I can do anything about it?

Thanks in advance..

Have you provided the servo with its own power, as opposed to driving it from the Arduino 5v? That's a good place to start when faced with servo problems: check the power. That "real" servo may well be trying to draw more current than the "toy" one, and if you're powering it from the Arduino, it may not be getting enough. Best practice is to power servo from outside the Arduino.... if the Arduino can't supply enough current you have no choice anyway.

My pic below shows how to hook two servos up to their own power supply, if you don't already know this. Note that the external power's ground is hooked to the Arduino ground, else the control signal on the yellow has no reference 0V.

Have you provided the servo with its own power, as opposed to driving it from the Arduino 5v? That's a good place to start when faced with servo problems: check the power. That "real" servo may well be trying to draw more current than the "toy" one, and if you're powering it from the Arduino, it may not be getting enough. Best practice is to power servo from outside the Arduino.... if the Arduino can't supply enough current you have no choice anyway.

Aha! Yes, I have been powering the servo from the arduino, so that may be
the issue. I think I'll be able to get my hands on some battery holders soon,
I'll report back then. Thanks!

Just out of curiosity: if the problem is the current, could I potentially use 5v from
the arduino and a transistor to amplify the current?

My pic below shows how to hook two servos up to their own power supply, if you don't already know this. Note that the external power's ground is hooked to the Arduino ground, else the control signal on the yellow has no reference 0V.

Thanks a lot. I have never made a project with external power supply so your
advice about ground will come in handy. Just to clear things out: I need 6V and
therefore 4AA batteries, right? The 2-battery holder is for demonstration, I
guess?

Just out of curiocity: if the problem is the current, could I potentially use 5v from
the arduino and a transistor to amplify the current?

A transistor cannot 'amplify' current. It can however control higher current if wired to a voltage source that has more current capacity. So your problem is that the arduino can only supply a limited amount of +5vdc current for external stuff and servos are almost always needing more then can be reliably supplied by the arduino. There is no magic component of device that can allow an arduino to supply more 5V current they it presently can, that simply takes an external voltage source with a higher current capacity.

Lefty

retrolefty:

Just out of curiocity: if the problem is the current, could I potentially use 5v from
the arduino and a transistor to amplify the current?

A transistor cannot 'amplify' current. It can however control higher current if wired to a voltage source that has more current capacity. So your problem is that the arduino can only supply a limited amount of +5vdc current for external stuff and servos are almost always needing more then can be reliably supplied by the arduino. There is no magic component of device that can allow an arduino to supply more 5V current they it presently can, that simply takes an external voltage source with a higher current capacity.

Lefty

Thanks, that clears this, I had misunderstood the use of the transistor.

The 2-battery holder is for demonstration, I guess?

Fritzing has only a few battery components in its library, which is why I stuck the "6V" post-it on top.... You could however think of it as a 2x2 cell holder with only the top 2 cells showing :wink:

Yep you need 4 cells....

Edit: I have servos running from 4x AA rechargeables which are only 1.2V each, for a total of 4.8 nominal, a bit over 5V in fact... they seem ok, since most servos specs say 4.8 to 6V. Admittedly they're not under heavy load and I'm not fussed about torque which is lower at low voltages. But I also recently hacked a PC powersupply and I have 5V from that too....