Servo not rotating 180degrees.

Hello, I have two identical servos( http://www.abra-electronics.com/products/ROB%252d10333-Servo-%252d-Medium.html), however, when I hook it up to the appropriate voltage( 6v, 4AA batteries), it only rotates about 145 degrees. Any suggestions? I think it may be in my very simple program.

#include <Servo.h>

Servo myservo;

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}

void loop()
{

myservo.write(90); //I play around with the angles(0-180) but the most it can go is 170 and the minimum is about 25.
delay(15); //I also play around with the delay(I put 20 for 170 degrees)

}

Have you checked for mechanical issues (or even opened in up?)

It might be that the specs are lying and it can't do 180?

The arduino servo library makes some assumptions about how wide a control pulse corrosponds to the end of travel position for a servo will be:

#define MIN_PULSE_WIDTH 544 // the shortest pulse sent to a servo
#define MAX_PULSE_WIDTH 2400 // the longest pulse sent to a servo

So for a 0 degree command they use a 544 usec pulse and for a 180 degree command they use a 2400 usec pulse. It may be that your specific servo can handle slightly lower and higher values to actually reach 180 degrees of travel. You can perform some tests using the servo.writeMicroseconds(uS) command to find the actual physical end of travel points for your specific servo. However you have to be careful as if you drive your servo too hard against either mechanical stop you can cause damage and draw high motor current values.

Lefty

I understand, but the servo.writeMicroseconds(uS) command is fairly new to me. Is it possible that you could send me a sketch on how to find the end points?
-thanks

vek11:
I understand, but the servo.writeMicroseconds(uS) command is fairly new to me. Is it possible that you could send me a sketch on how to find the end points?
-thanks

The below is just a modification of the servo sweep example sketch. Just adjust the two global variables minposition and maxposition to see if you gain any extra travel for your specific servo. adjust the limit values only by 5 usec or so each attempt, but stop the sketch (power off, or hold reset down) if the servo starts buzzing or making noise if it starts to reach a mechanical stop at either end of travel.

// Sweep
// by BARRAGAN <http://barraganstudio.com> 
// This example code is in the public domain.


#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
int pos = 0;    // variable to store the servo position 
int minposition = 544;    //adjust this value smaller to find start end position by 5 usec steps
int maxposition = 2400;   //adjust this value larger to find stop end position by 5 uses steps
void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 
 
 
void loop() 
{ 
  for(pos = minposition; pos < maxposition; pos += 5)  // move in 5 usec steps 
  {                                   
    myservo.writeMicroseconds(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
  for(pos = maxposition; pos>= minposition; pos-=5)     // move in 5 usec steps 
  {                                
    myservo.writeMicroseconds(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
}

Lefty

vek11:
I understand, but the servo.writeMicroseconds(uS) command is fairly new to me. Is it possible that you could send me a sketch on how to find the end points?
-thanks

servo test code.

// 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
  } 
}

I used the first sketch, and my servo was running fine in the first part of the loop and reached 180deg without any loud buzzing. However, when it went back to 0deg(the second part of the loop), it could not make completely get to the 0deg position. So I made the minposition smaller(decreased it by 5u each attempt), but nothing really happened. Any way to fix this?