Pages: [1]   Go Down
Author Topic: Servo not rotating 180 degrees  (Read 2493 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to get my DFRobot servo to work:
http://www.dfrobot.com/index.php?route=product/product&product_id=120

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:
Code:
#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.
Logged

Vejen, Denmark
Offline Offline
Edison Member
*
Karma: 9
Posts: 1178
RAWR! ^,..,^
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you 100% sure that it actually can do 180 degrees?

I got a few 180 degrees servo's too, but not one of them can actually do 180
Logged

captain-slow.dk | non contagious!

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Below is simple servo test code that might be of use in testing your servo.

Code:
// 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="";
  }
}
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17259
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Lefty
« Last Edit: December 25, 2010, 11:46:07 am by retrolefty » Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Not all servos have a mechanical 180 degree travel, so 120 degrees may be the mechanical limit for your servo.

Per the link provided for the servo: "The DF15MG is a double bearing, high torque 180 degree rotation servo." Still could have mechanical issues.
« Last Edit: December 25, 2010, 11:56:45 am by zoomkat » Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am still unable to rotate the full 180 degrees. The servo shaft can rotate over 180 degrees; but the Arduino is not able to control it that way.

Maybe I have to live with it.
Logged

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you tried the writeMicroseconds method?
Logged

Per Arduino ad Astra

0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It seems that the servo library and NewSoftSerial don't work together.
In the code you posted, you are not using NewSoftSerial, so the relevance of this observation escapes me.
Logged

Pages: [1]   Go Up
Jump to: