Servo problem

I just got my arduino and servo. But my servo may be acting strangely. Whenever I tell the servo to go somewhere it keeps going to 0 than to that position and stops after 10-15 seconds or more.
This is the code used in this video

#include <Servo.h> 

Servo myservo;  // create servo object to control a servo 

void setup() 
{ 
  myservo.attach(11);
  myservo.write(50);
} 

void loop() 
{ 
}

it is connected like this:

Ground from Arduino to breadboard row 3

Ground from external power supply to breadboard row 3

Ground from SERVO to breadboard row 3

Power supply positive to servo VCC

Servo signal to pin 11 (tried other ones too)

Servo power supply is 5.1V 0.7A

Arduino is powered from USB.

Is that your video?- ie is that the behaviour you get with that code? Or is it the behaviour you need?

All that should happen with that code is that it will try to centre at 90 by default with the attach, then go to 50 degrees and nothing happens after that since it's in setup() and loop() is empty.

Whenever I tell the servo to go somewhere it keeps going to 0 than to that position

Going to one end of travel is usually caused by a bad control signal or possibly bad grounding between the servo external power supply and the arduino. Below is some very simple servo command code you can try with the serial monitor.

//zoomkat 7-30-10 serial servo test
//type servo position 0 to 180 in serial monitor
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);
  myservo.attach(9);
  Serial.println("servo-test"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the String readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured String 
    int n = readString.toInt();  //convert readString into a number
    myservo.write(n);
    readString="";
  } 
}

JimboZA:
Is that your video?- ie is that the behaviour you get with that code? Or is it the behaviour you need?

All that should happen with that code is that it will try to centre at 90 by default with the attach, then go to 50 degrees and nothing happens after that since it's in setup() and loop() is empty.

The behaviour in the video is with the code I posted .

The behaviour in the video is with the code I posted .

How are you powering the servo? With the code you posted the arduino may be resetting when the servo moves, causing the the code to repeat itself. Unless changed, the servo will try to go to 90 deg when attached, then to the 50 deg you send it to.

Shibafu:
The behaviour in the video is with the code I posted .

Hmmmm well I have no clue why that might be, other than as zk says to check the power. Are you 100% sure that code loaded?- there's no chance an earlier sketch could be running?

zoomkat advocates putting a serial print in setup() so that you can open the monitor and see that the right sketch loaded.

Put these two lines in the top of setup() just below the opening {....

void setup() 
{ 
  Serial.begin(9600);
  Serial.println("... put whatever you want to say here...");
  myservo.attach(11);
  myservo.write(50);
} 

void loop() 
{ 
}

And open the serial monitor with control shift m

Shibafu:
Servo power supply is 5.1V 0.7A

This sounds very like another Problem that I answered yesterday - which also had a 0.7a power supply. In that case the problem seemed to be that the power supply could not provide enough current. I can't remember what the other Thread was or I would link to it.

...R

In the video the servo's not loaded: I'd be very surprised if it's drawing over 2/3 of an amp, and that travel looks a lot more than just 90-50-90 degrees repeating.

Very simple servo test code you can use with the serial monitor to test your servo.

//zoomkat 7-30-10 serial servo test
//type servo position 0 to 180 in serial monitor
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);
  myservo.attach(9);
  Serial.println("servo-test"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the String readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured String 
    int n = readString.toInt();  //convert readString into a number
    myservo.write(n);
    readString="";
  } 
}

zoomkat:
Very simple servo test code you can use with the serial monitor to test your servo.

//zoomkat 7-30-10 serial servo test

//type servo position 0 to 180 in serial monitor
// Powering a servo from the arduino usually DOES NOT WORK.

String readString;
#include <Servo.h>
Servo myservo;  // create servo object to control a servo

void setup() {
  Serial.begin(9600);
  myservo.attach(9);
  Serial.println(“servo-test”); // so I can keep track of what is loaded
}

void loop() {

while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the String readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured String
    int n = readString.toInt();  //convert readString into a number
    myservo.write(n);
    readString="";
  }
}

I tried it.
Lets say servo is in 90.
I tell him to go 45, he goes to 0 than to 45.Is this normal?
Still sometimes when I tell him to move he goes to 0 than to that position few times before stoping.

Shibafu:
Lets say servo is in 90.
I tell him to go 45, he goes to 0 than to 45.Is this normal?

This is certainly not normal.

Can you try powering the servo from 4 AA NiMh batteries?
Have you another servo that you can try with the same code?