MG995 servo acting crazy with external power supply and UNO

Hello fellows,

I have a problem with my servo (TowerPro Mg995) as it starts acting randomly(more like crazy all over the place) when connected to Arduino board and power supply. below are the system specs:

Board: Uno
Servo: TowerPro MG995
External power supply: regulated 5V @1A max output

Ground connections are shorted of course.

Code

// Include the Servo library
#include <Servo.h>
// Declare the Servo pin
int servoPin = 3;

// Create a servo object
Servo Servo1;

void setup() {
// attach the servo to the used pin number
Servo1.attach(servoPin);
}

void loop(){
// Make servo go to 0 degrees
Servo1.write(150);

delay(100000); //stop at position for 100sec
}

Thank you.

Image from Original Post so we don’t have to download it. See this Image Guide

b25256404531e2b0a6a5edf7aa273356a74e40de.jpg

…R

I wonder why you have used a picture of a PP3 9v battery when you really mean a 5v 1 amp power supply?

If you are connecting the 5v supply to the Arduino 5v pin are you quite sure that it is a regulated 5v supply that won't harm the Arduino?

What happens if you connect the Arduino to your PC with the USB cable instead of the 5v supply?

It may be that a 1 amp supply does not provide enough current for your servo and the Arduino.

...R

Robin2: I wonder why you have used a picture of a PP3 9v battery when you really mean a 5v 1 amp power supply?

Because I don't want to get into source details which is supplied by a battery in the first place.

Robin2: If you are connecting the 5v supply to the Arduino 5v pin are you quite sure that it is a regulated 5v supply that won't harm the Arduino?

The source is regulated, used a voltmeter on several instances and it holds at 5V.

Robin2: What happens if you connect the Arduino to your PC with the USB cable instead of the 5v supply?

Connecting the Arduino to PC and the motor to external power supply yields the same thing.

Robin2: It may be that a 1 amp supply does not provide enough current for your servo and the Arduino.

I'm really not sure, it happens with two identical servos so its not a bad motor.

ibro191:
Connecting the Arduino to PC and the motor to external power supply yields the same thing.

That suprises me. When you are connected to the PC do you have the servo GND connected to the Arduino GND (you should).

I am assuming, since you have not told me otherwise, that this problem happens all the time the Arduino is running and not just for a few seconds at start-up?

Try a shorter delay() - say 1000 for 1 second - and put some Serial.print commands in your code so you can see if the Arduino is behaving properly. Try this

#include <Servo.h>

int servoPin = 3;
Servo Servo1;
int counter = 0;

void setup() {
    Serial.begin(9600);
    Serial.println(F("Source File /root/my-documents/tmp/ForumD.ino"));
    Serial.println("Starting");
    Servo1.attach(servoPin);
}

void loop(){

    Serial.println(counter);
    counter ++;
    Servo1.write(150);

    delay(1000);
}

It should print the word “Starting” every time it resets and after that it should print an increasing number every second.

…R

Robin2:
That suprises me. When you are connected to the PC do you have the servo GND connected to the Arduino GND (you should).

Grounds are connected.

Robin2:
I am assuming, since you have not told me otherwise, that this problem happens all the time the Arduino is running and not just for a few seconds at start-up?

As long as the Arduino is executing the code the servo keeps on swinging back and forth relentlessly.

Robin2:
Try a shorter delay() - say 1000 for 1 second - and put some Serial.print commands in your code so you can see if the Arduino is behaving properly.

I have tried that, same thing. Servo out of control but the board doesn’t reset, counter goes on uninterrupted.

Servo Does not stop for one second until I plug it off or disconnect from Arduino PWM pin. Then it holds still.

Could it be a current problem? a 1A current somehow insufficient ?

Check this link, looks like you have a dud, dude. :slight_smile:
http://www.rcmodelreviews.com/mg995review.shtml

ibro191: I have tried that, same thing. Servo out of control but the board doesn't reset, counter goes on uninterrupted.

Then I reckon your servo is faulty.

Servo Does not stop for one second

Just to clarify, the 1 second (or your 100 second) delay will have no impact on a good servo. You only have one instruction telling the servo to go to 150deg and when it gets there it should stay there forever.

If you want to see the effect of the delay() you need to tell the servo to move to a different position and wait there for an interval before moving back to the first position.

...R

Robin2:
Then I reckon your servo is faulty.

I have mentioned before that this happens with two identical servos, and both are new out of package.

Robin2:
Just to clarify, the 1 second (or your 100 second) delay will have no impact on a good servo. You only have one instruction telling the servo to go to 150deg and when it gets there it should stay there forever.

I am aware of that, what I was implying is the continuous motion of the servo even though it has to stop at some position per command.

outsider:
Check this link, looks like you have a dud, dude. :slight_smile:

Appears so. Anyway, i’'ll do some testing and will post here once this issue is resolved. Thank you all.

ibro191:
I am aware of that, what I was implying is the continuous motion of the servo even though it has to stop at some position per command.

You are still misinterpreting how the Servo library works. The servo library continually sends a signal to the servo regardless of whether or not you have delay()s in your code. The only way to stop is to use Servo.detach().

…R

Hi, Can you post a picture of your project please so we can see your layout?

Thanks.. Tom.. :)