TowerPro MG995 doesnot do a full 180 sweep(i.e it does an interrupted 180 sweep)

Hi All,

This is my first post related to arduino and also on this forum.
As the title says I'm unsure why it doesn't work. I followed the online tutorial:

I connected the GND, +5V and Signal pins as said in that tutorial. The code is also the same. Ill post it here for easier understanding:

#include <Servo.h>
Servo servo1;

void setup()
{
  servo1.attach(9);
  servo1.write(180);
}

void loop()
{
}

As soon as we upload it to arduino it is expected to run a 180 degree continuous sweep which appears to be working for the tutorial's author but unfortunately it doesn't work for me. In my case it does an interrupted sweep - meaning - it rotates a bit, then pauses, then rotates, all this till it reaches its final position.

Could it be a problem with servo motor or any other problem ?

P.S: I have not used external power source. The setup is exactly same as shown in the tutorial.

Edit: Uploaded a small video which shows the problem. Please follow this link. Type: mp4 | Size: 440Kb

http://sendvid.com/3q4f5cm0

Try this version:

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

 modified 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Sweep
*/ 

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

Hi outsider,

Thanks for your reply.

Unfortunately its the same interrupted rotation.

Trying to power a servo from Arduino's 5V pin may or may not work, it may or may not trash your Arduino, but I wouldn't risk it. If you don't have a separate 5 or 6 volt supply, do you have 4 AAA, AA, C or D batts you could put in series for 6V?

Thank you. I can arrange a battery pack.
But what I do not understand is why it does work for that tutorial's author ? I have exactly the same setup. Why does it behave differently for my setup ?

I have a small servo that came in a starter kit, I tried the same thing you're doing with it and every thing seemed to work well 'til I tried to go above 157 degrees, at that point the servo started jerking and buzzing and caused the Arduino to repeatedly reset. With a 6V wall wart for power, it still hung at 157 deg. but didn't reset the Arduino, just started smoking. I used this test program to find the usable range:

/*
 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 200 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
  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();
    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());
}

Once I knew the usable range I could use it in projects as long as it was kept in that range. The servo you have does not have a very good reputation.

  • what Tom said, tnx Tom.

Hi,
The power available form his USB may be different from your USB port, also the quality of the cable can cause some current limitations and the source of the arduino PCB.

Also these servos are cheap mass produced, they are not necessarily all exactly the same.

When you connect a battery pack to power the servo, remember to connect the neg/gnd of the battery pack to the gnd of the arduino, this will provide the current loop for the servo signal.

Tom.... :slight_smile:

Thanks guys for the answers. Problem solved by using an external 12V DC power adapter. This takes care of the board and the servo :slight_smile:

@outsider I tried your code. It works now expected. Moving forward can we make that code run forever ?
Because for now it rotates to 180 degrees and then back to original. Can we make it run this loop forever ?
I guess void loop is supposed to do it. Isn't it ? Or I'm thinking wrong ?

Update: It works.

matt-p:
Thank you. I can arrange a battery pack.
But what I do not understand is why it does work for that tutorial's author ? I have exactly the same setup. Why does it behave differently for my setup ?

Luck, not judgement nor good practice.

You should never power a motor or servo from a logic supply, its asking to damage your logic chips
from inductive spikes and reset under load and probably other bad things...