Controlling continuous rotation servos

Hello all,

Firstly apologies if this subject has been mentioned previously.

My project involves controlling 3 continuous rotation servos. I am quite new to the arduino programming language in relation to programming servos. The only code I seem to be able to find is that relating to the "sweep" function found in the arduino library, but as my servos will have the potentiometers removed from them I don't see how this can be used to control my motors.

I essentially want to tell all three motors to rotate at a specific speed for a specific number of seconds, simultaneously, and then for them to stop. They then need to do the reverse, simultaneously. This code will need to be initiated using a push button. e.g first push for the first code, second push for the reverse code.

I would be VERY appreciative I could be given advice on where to start, or whether there is any code available that should allow me to get started.

Thanks :slight_smile:

Hi AhmedemhA,

Contious rotation servo's accept values ranging from 0-180. 0 is full speed in one direction and 180 is full speed the other way around. Writing 90 should stop the servo. You should experiment for every servo individually which value makes your servo stop.

Hope this is clear.

Erik

Below is some servo test code that might be of use testing your servos. writeMicroseconds provides for finer speed control of continuous rotation servos.

// zoomkat 12-25-13 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// Send an a to attach servo or d to detach servo
// for IDE 1.0.5 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

#include <Servo.h> 
String readString; //String captured from serial port
Servo myservo;  // create servo object to control a servo 
int n; //value to write to servo

void setup() {
  Serial.begin(9600);
  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7, 500, 2500);  //the pin for the servo control, and range if desired
  Serial.println("servo all-in-one test code 12-25-13"); // so I can keep track of what is loaded
  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) {
    Serial.println(readString);  //so you can see the captured string 

      // attach or detach servo if desired
    if (readString == "d") { 
      myservo.detach(); //detach servo
      Serial.println("servo detached");
      goto bailout; //jump over writing to servo
    }
    if (readString == "a") {
      myservo.attach(7); //reattach servo to pin 7
      Serial.println("servo attached");
      goto bailout;
    }    

    n = readString.toInt();  //convert readString into a number

    // auto select appropriate value
    if(n >= 500)
    {
      Serial.print("writing Microseconds: ");
      Serial.println(n);
      myservo.writeMicroseconds(n);
    }
    else
    {   
      Serial.print("writing Angle: ");
      Serial.println(n);
      myservo.write(n); 
    }

bailout: //reenter code loop
    Serial.print("Last servo command position: ");    
    Serial.println(myservo.read());
    Serial.println();
    readString=""; //empty for next input
  }
}