Controlling a servo motor does not work (hopefully an easy one)

Hi,

I am trying to control my servo.
I have an Arduino Diecimila board, the servo is called SERVO POWER HD 6001HB (bought here http://www.bricogeek.com/shop/motores/251-servo-power-hd-6001hb.html).

I have attached the red cable to the 5V, the brown cable to the ground and the yellow cable to pin 3.

Now if I run the example code, the Sweep sketch, it works, the servo slowly turns 180 degrees and back.
But if I try to run such a simple sketch:

#include <Servo.h> 

Servo servo1;

void setup() 
{ 
  servo1.attach(3);

  servo1.write(0);
  delay(5000);
  servo1.write(30);
  delay(5000);
  servo1.write(70);

  servo1.detach();
}

void loop() 
{  }

it doesn’t work. Sometimes it does not move, some others it moves just once, some others it moves a bunch of times like in a random way.

I have tried to check the sequence of commands by adding some Serial.println() and I have seen strange things, the delays are not respected (while in other situations they work) and the lines sometimes are printed in a strange order .

Any idea?

thanks…

You are not trying to power the servo from the Arduino's 5V pin are you? That's not good, servo's take several amps peak, way more than the Arduino regulator (or a USB socket) can handle.

That probably explains it, I am in fact powering the servo with the Arduino (Arduino powered by the USB).

I have followed this tutorial http://blog.bricogeek.com/noticias/tutoriales/tutorial-control-de-servomotores/ but there the servo is different and the Arduino is the Mega edition. I will try with an external power source and let you know..

Thanks !

Hi,

Check the links in my signature for how and why.

Duane B

rcarduino.blogspot.com

Thanks to both of you, these posts from DuaneB are actually very good. Now My servo is working correctly.

That recommendation about using a common ground between the power source of Arduino and the exernal one fro the servos has avoided me some headhackes :D