Full Rotation Servo

I have a medium Springrc full rotation servo. The normal servo serial library doesn't seem to working properly. I downloaded a ContinuousServo.h library that sort of acts as a step motor library on my servo, but I am only able to make it spin in one direction. I am trying to connect the servo to a gear drive and rack system and would like to be able to have the servo spin in one direction for a certain amount of time and then stop and reverse. Does anyone have some advise? How can I control the full/continuous rotation servos accurately in both directions over time parameters?

this is the code I have so far.

#define sensorIR A0 //Must be an analog pin
#include <ContinuousServo.h> // servo library
ContinuousServo servo1(11); // servo control object

float sensorValue; //inches; // or cm; Must be of type float for pow()
int presenceDetected;
float UV, Bright;

const int threshold = 10;
const unsigned long interval = 20*1000UL; // Twenty seconds
//const int motorPin = 13;

unsigned long startTime = 0;

void setup() {
Serial.begin(57600);
pinMode(9, OUTPUT);
pinMode(11, OUTPUT);
// servo1.attach(11);

}

void loop() {
// if the analog value is low enough, turn on the motor:
// if (analogRead(sensorValue) < threshold) {
// startTime = millis();
// Serial.println(startTime); // Serial Print When the sensor is sensed.
// Serial.print("on");
// servo1.write(0);
//
// //digitalWrite(motorPin, HIGH);
// }
//
// // If time has expired, turn the motor off
// if(millis() - startTime > interval) {
// Serial.println("off");
// servo1.write(95);
// }

IR();

if (sensorValue > 200) {
//if (inches < 10) {
LED();
}

//if (inches < 10) {
if (sensorValue > 200) {
presenceDetected = 1;}
else {
presenceDetected = 0;
}

if(presenceDetected == 1)
{ servo1.step(0);
Serial.println("Servo180:");
}
else {
servo1.step(500);
Serial.println("Servo0:");
}

delay(100);
Serial.println(sensorValue);
//Serial.print("Inches: ");
//Serial.print("centimeters;");
//Serial.println(inches);
Serial.print("presenceDetected:");
Serial.println(presenceDetected);
//Serial.println(cm);
//int position;
//servo1.write(180);
//delay(100);

}

void IR()
{ sensorValue = analogRead(sensorIR);
//inches = 4192.936 * pow(sensorValue,-0.935) - 3.937;
//cm = 10650.08 * pow(sensorValue,-0.935) - 10;
delay(100);}

void LED()
{ digitalWrite(10,HIGH);
delay(100);
digitalWrite(10,LOW);
delay(100);

digitalWrite(9,HIGH);
delay(100);
digitalWrite(9,LOW);
delay(100);}

My understanding is that a full rotation servo will go fwd with values above 90deg and backwards with values below 90deg (or vice versa). Are you saying that doesn't work with your servo?

...R

#include <ContinuousServo.h>

Do you have a link to this, please?

That works on the normal servo.h library. But I am unable to get it to work properly as its missing the timing mechanism in the hardware of the full rotation servos.

Servo test code you can use to determine the values to get the servo to do what you want.

// zoomkat 10-22-11 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// for IDE 0022 and later
// 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.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control 
  Serial.println("servo-test-22-dual-input"); // 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

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

    readString=""; //empty for next input
  } 
}

brittaij:
That works on the normal servo.h library. But I am unable to get it to work properly as its missing the timing mechanism in the hardware of the full rotation servos.

That statement makes little sense to me. Can you rephrase it?

Lefty