MG90S servo not working as desired

Hi there,

Sorry to have to ask this but we've been pulling our hair out trying to get a MG90S servo to move from 0 to 180° and back again (fast forwards and slow backwards with a delay in the middle) using a Arduino Uno board.
We've tried all sorts of code from the servo section on the Arduino web site and other places but the servo just doesn't seem to work as we want. When we tell it to move from 0 to 180° it spins approx 6 times in one direction and then back again.
Any help would be greatly appreciated.

This is one of the codes we've tried.

I can add a video of the behaviour if it will help.

Thanks in advance

Jack

A regular hobby servo CAN'T spin 6 times. You either have a "winch" servo, used on sailing models to tension lines OR you have a "continuous rotation" servo: a hobby servo that ha been modified to remove the physical stop and the position feedback so it acts like a gearmotor.

I will upload a video and the code we are using in a little while. Maybe that will help.

This is the spec of the servo.

No that's a partial spec of a standard MG90S. If yours rotates for more than a complete circle the one you have is either the continuous rotation version or a broken one.

Steve

Try this simple sketch:

#include <Servo.h>
Servo servo;


void setup()
{
  servo.attach(7);  // Put the right pin number here
}


void loop()
{
  // Step through 180 degrees in steps of 30 degrees
  for (int position = 0; position <= 180; position += 30)
  {
    servo.write(position);
    delay(1000);
  }
  delay(2000);
}

Forget the code you have. Just attach the servo and tell it to go to 180. Does it rotate forever?

Sorry if I'm being stupid but I keep getting an error 'servo was not declared in the scope' See attached image.

So here's where we got to earlier with video attached.

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0; // variable to store the servo position

void setup() {
myservo.attach(9); // 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(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}

Sorry didn't realise I couldn't upload a video

Take the code you posted, delete everything in loop and just add
myservo.write(180);
At the end of setup.

That should demonstrate what the folks above have been saying that your servo is broken, counterfeit or modified.

johnwasser:
Try this simple sketch:

#include <Servo.h>

Servo servo;

void setup()
{
  servo.attach(7);  // Put the right pin number here
}

void loop()
{
  // Step through 180 degrees in steps of 30 degrees
  for (int position = 0; position <= 180; position += 30)
  {
    servo.write(position);
    delay(1000);
  }
  delay(2000);
}

So we have managed to get this one to work to a point. The servo rotates 6 revs stops for approx 3 secs and then rotates for a further 6 times and pauses and it comtinues to do this until it is un-plugged.

We will give the modified code a go in a minute.

No need. Case closed - you have a continuous rotation servo. You can't control its position.

Ok, thought that was the way it was going as we just tried the code below.

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0; // variable to store the servo position

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

void loop() {myservo.write(180);}

And it just rotates continuously.

Could anyone point me in the right direction of a servo of the same type but one that will do the job for us? Amazon maybe?

Thanks in advance

Jack

The type you have should be fine as long as you can get one from a reputable vendor. Towerpro represents themselves as the original manufacturer and warns that there are many people producing cheap knockoff versions.

Thanks for all your help guys. We've ordered one from the www.servoshop.co.uk. Fingers crossed this time we get the correct one Tower Pro MG90S. Thanks again. Jack.