Micro Servo SG90 does not rotate full 180º

Hi,

I am just starting with Arduino, got "Most Complete Starter kit" and am running Lesson 9 Servo:

  • Micro Servo SG90
  • Arduino Mega 2560

The Servo does not complete 180º of rotation, only about 0 -> 165º, I wonder why?

After some research on this Forum, I've noticed similar (not equal) problems, and I've tried code and explanations on those posts, using to similar programs:


#include <Servo.h>
Servo myservo;

void setup() {
  myservo.attach(9);
}

void loop() {
  myservo.write(0);
  delay(1000);
  myservo.write(180);
  delay(1000);
}

and


#include <Servo.h>
Servo myservo;

void setup() {
  myservo.attach(9,544,2400);
}

void loop() {
  myservo.writeMicroseconds(544);
  delay(1000);
  myservo.writeMicroseconds(2400);
  delay(1000);
}

In both cases, servo only covers the range between 0-165º.

Is this normal due to this type of Servo?

Than kyou.

Hence the need for

attach(pin, min, max ) - Attaches to a pin setting min and max values in microseconds

with values other than the defaults of 544 and 2400.

2 Likes

50 years since a class on microprocessors but the timing used then was 500 to 2500, middle point at 1500 microseconds at 50 Hz.
Does the library handling add micros?

1 Like

Mea culpa; I took the comment in Servo.h at face value when it said "default min is 544, max is 2400". Looking further down the page, it's actually 500 and 2400 - except in the cases where it really is redefined by some boards as 544 and 2400.

1 Like

Are you powering the servo with an external 5V and connecting all the grounds together? Your code looks fine, with all ^ bases covered, it may just be that those servos are inexpensive and made in such numbers that precision to their specification is not their forte.

1 Like

What about trying higher numbers then 2400?

1 Like

That was the gist of my original suggestion of calling attach(pin, min, max) with numbers other than defaults.

1 Like

Let's see if the OP goes for it.

1 Like

Not normal but typical. I have 5 various "cheapy" servos, none of them will do full 180°. Here's a test program.

/*
 Try this test sketch with the Servo library to see how your
 servo responds to different settings, type a position
 (0 to 180) or if you type a number greater than 180 it will be
 interpreted as microseconds(544 to 2400), in the top of serial
 monitor and hit [ENTER], start at 90 (or 1472) and work your
 way toward zero (544) 5 degrees (or 50 micros) at a time, then
 toward 180 (2400). 
*/
#include <Servo.h>
Servo servo;

void setup() {
  // initialize serial:
  Serial.begin(9600); // set serial monitor baud rate to match
                      // set serial monitor line ending to "NewLine"
  servo.write(90);
  servo.attach(9);
  prntIt();
}

void loop() {
  // if there's any serial available, read it:
  while (Serial.available() > 0) {

    // look for the next valid integer in the incoming serial stream:
    int pos = Serial.parseInt();
    if(Serial.read() == '\n'){} //skip 1 second delay
    pos = constrain(pos, 0, 2400);
    servo.write(pos);
    prntIt();
  }
}
void prntIt()
{
  Serial.print("  degrees = "); 
  Serial.print(servo.read());
  Serial.print("\t");
  Serial.print("microseconds =  ");
  Serial.println(servo.readMicroseconds());
}  

2 Likes

Indeed I am, but had to find it on my own, the tutorial lesson wires it directly to the board (already left a comment with the Tutorial manufacturer), and behaviour is completely different for all different source of code values. I've started trying to solve this issue, and now I always power the board with the 9V AC adapter, thank you.

Thank you, I will try this and shall keep everyone posted

Thank you, I will try this

You're the Man, thank you!
Made all sort of different values, limits I've found: 490, 2555 (instead of announced 544, 2400)

Use this to test it:

#include <Servo.h>
Servo myservo;

void setup() {
  myservo.attach(9,490,2555);
}

void loop() {
  myservo.writeMicroseconds(490);
  delay(1000);
  myservo.writeMicroseconds(2555); // Max value tested to allow 180º, instead of announced 2400
  delay(1000);
}

Thank you. I am still going throught the basic tutorial lessons and haven't reached yet to the serial monitor setup.
When I am done with it, I will come back here, test this code you sent me and shall keep you posted.
Thank you very much.

Thank You for telling!
I once managed to control a 48 volt 2 wire fan using PWM. Impossible the seller, the agent said. "Come here and look.....".

Sometimes djunglework works.

My pleasure. Let's keep the pace exploring this electronic "LEGO"... :v:

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.