I am using the sample sketch that is provided by the IDE. I am using external power for the servo, so that the Arduino is not stressed on that part. The code is:
#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
void setup()
{
myservo.attach(8, 544, 2400); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(30); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(30); // waits 15ms for the servo to reach the position
}
// myservo.write(0);
}
My problem is that I am unable to sweep the full 180 degrees that is supported by the servo. I guess the rotation is around 120 degrees. I have not found any solution for this.
Is anyone been able to use this servo as it is supposed to be.
Below is simple servo test code that might be of use in testing your servo.
// zoomkat 10-4-10 serial servo test
// type servo position 0 to 180 in serial monitor
// for writeMicroseconds, use a value like 1500
// for IDE 0019 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.attach(7); //the pin for the servo control
Serial.println("servo-test-21"); // so I can keep track of what is loaded
}
void loop() {
while (Serial.available()) {
delay(10);
if (Serial.available() >0) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
}
}
if (readString.length() >0) {
Serial.println(readString); //so you can see the captured string
int n;
char carray[6]; //converting string to number
readString.toCharArray(carray, sizeof(carray));
n = atoi(carray);
myservo.writeMicroseconds(n); // for microseconds
//myservo.write(n); //for degees 0-180
readString="";
}
}
Not all servos have a mechanical 180 degree travel, so 120 degrees may be the mechanical limit for your servo. Also some servos require pulse widths shorter and longer then the standard widths of 1 and 2 millisecond provided by the arduino servo command when using degree values of 0 and 180 respectively.
There is a writeMicroseconds() command where you can give the pulse width commands longer then 2millec and shorter then 1 millisecond to determine how much 'over-travel' your specific servo has. http://arduino.cc/en/Reference/ServoWriteMicroseconds
I have tried to delayMicroseconds; same issue. I will now try the library from IDE 16. It seems that the servo library and NewSoftSerial don't work together. Maybe that gives me the 180 degrees too?