Continuous Servo Motor not working

Hi all, I have been working on this for quite a while, and wondering what is going on. I am taking a robotics course online through my school and have been given two motors for the final project (they are for the wheels). Unfortunately it doesn't want to work. I have a program that I had to write, just to get a feel for the servo motors. However I write the program, and nothing happens! So I check the connections, everything seems good, Brown -GND Red - 5V Orange -Digital Pin 9. So then I check the code, I tried Digital and Analog Here is the code, tried multiple different code patterns:

#include <Servo.h>
//Includes the Servo.h file for easier programming.
Servo myServo; //Setting up the servo name.
int servoPin = 9;//Setting the servo pin, I've tried digital AND analog.

void setup()
{
  myServo.attach(servoPin);//Telling arduino that myServo uses servoPin
  myServo.write(90);//
}
void loop()
{
  myServo.write(0);  
}

By now you may be thinking, so you've only told me what you've tried, what actually happened!?! What happens:

  1. Upload sketch to Arduino Uno
  2. It compiles fine
  3. It uploads and... sometimes it spins on for a second, sometimes nothing.
  4. It just doesn't do anything.

Things I've tried that sorta work:

  1. same as steps 1-4 above
  2. I disconnect any 1 cord that is plugged in to either the Arduino Uno or the Continuous Servo.
  3. I connect then disconnect the plugged in cord over and over again
  4. By doing step 3 over and over again it makes the Continuous Servo crudely move and doesn't work very well at all.

Things that work but not in the way I want them to:
For some reason the "Sweep" example code in File->Examples->Servo->Sweep Works great.
The Continuous Servos I have tried:
TowerProtm Micro Servo 9G SG90
Moxietm Mox M9
Please help.

Servo test code that might be of use testing your servo. Note that powering a servo from an arduino often causes issues.

// zoomkat 3-28-14 serial servo incremental test code
// using serial monitor type a character (s to increase or a 
// to decrease) and enter to change servo position 
// use strings like 90x or 1500x for new servo position 
// for IDE 1.0.5 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

#include<Servo.h>
String readString;
Servo myservo;
int pos=1500; //~neutral value for continous rotation servo
//int pos=90;

void setup()
{
  myservo.attach(7, 400, 2600); //servo control pin, and range if desired
  Serial.begin(9600);
  Serial.println("serial servo incremental test code");
  Serial.println("type a character (s to increase or a to decrease)");
  Serial.println("and enter to change servo position");
  Serial.println("use strings like 90x or 1500x for new servo position");
  Serial.println();
}

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) {
    if(readString.indexOf('x') >0) { 
      pos = readString.toInt();
    }

    if(readString =="a"){
      (pos=pos-1); //use larger numbers for larger increments
      if(pos<0) (pos=0); //prevent negative number
    }
    if (readString =="s"){
      (pos=pos+1);
    }

    if(pos >= 400) //determine servo write method
    {
      Serial.println(pos);
      myservo.writeMicroseconds(pos);
    }
    else
    {   
      Serial.println(pos);
      myservo.write(pos); 
    }
  }
  readString=""; //empty for next input
}

Thanks Zoomkat,
I uploaded it(A bit tricky to understand)
put in some random numbers, doesn't work. The odd number turns it for a second then it turns off. Powering a servo from an Arduino usually does not work? What might the side effects be? Will try with a battery, which battery would work ?(BTW I'm a n00b to Arduino, robotics etc.).
All help appreciated.

If you power a servo from the Arduino 5v pin and it draws too much current (so the Arduino 5v is no longer 5v) the Arduino can behave very strangely - perhaps resetting over and over - and may also be damaged.

Use a separate 5v or 6v power supply with about 1 amp of current for each servo. Connect the servo power supply ground to the Arduino ground. 4 AA NiMh cells would work fine.

...R

Hi, An easy way to supply separate power to servos is to use a Sensor Shield version that has the ability to SEPARATE the power to the 3-pin servo connectors from the Arduino power. Example HERE:

DISCLAIMER: Mentioned stuff from my own shop...

For some reason the "Sweep" example code in File->Examples->Servo->Sweep Works great.

Are you sure that it is a continuous rotation servo?

Hi all! So happy to see such a helpful community.

@groundfungus

groundfungus:
Are you sure that it is a continuous rotation servo?

I really don't know, I will ask my teacher. Websites don't seems to be so helpful.

@Robin2

Robin2:
If you power a servo from the Arduino 5v pin and it draws too much current (so the Arduino 5v is no longer 5v) the Arduino can behave very strangely - perhaps resetting over and over - and may also be damaged.

Use a separate 5v or 6v power supply with about 1 amp of current for each servo. Connect the servo power supply ground to the Arduino ground. 4 AA NiMh cells would work fine.

Hi Robin2,
4 AA NiMh cells, so basically 4 AA rechargeable battery's? How would I go about setting this up? Could I just link all four battery's together, attach the power to the plus end of the battery, and the ground to the negative end of the battery's? How could I do this easily without purchasing anything.

hcorion:
4 AA NiMh cells, so basically 4 AA rechargeable battery's? How would I go about setting this up?

Simplest thing is to buy a battery holder for them - Google AA battery holder.

...R

Basic servo external power setup.

Hi all,
Thanks for all your help, I found out some of the kits had by accident normal servos rather than continuous. I'm being sent two continuous servos.
Over and out, Hcorion