Sweep behaving erratically with external power supply

Hi guys,

Just getting to the last few things on a project I have been working on, my code needs to make a servo move, so have bought a servo and have attempted to get the Sweep sketch going.

I tried it originally with just the board powered by the USB and noticed the servo was drawing too much power. Its a high torque servo (Turnigy s811~26 kg.cm) so bought a 6V DC battery to power it externally.

I am well aware the the ground from the power supply need to be connected to the ground on the arduino board (Using a Mega).

Even still the servo will alternate back and forth approximately a degree, it never moves further than this, but switch back and forth. Removing the ground connection as expected makes it bahve even more erratically.

Im stumped as to what is causing this, I am tempted to buy a smaller servo to see if it have the same problem, however my project will need a big servo in it eventually.

Any ideas welcomed.

Do you have a datasheet? I couldn't find something like "s811" :frowning:

I for the life of me cannot find it either!

This is all the details I can find for it:

Features:
• Standard mounting points for easy installation
• All necessary hardware included
• Specific robotic use
• 180° Rotation

Specifications:
Model: TGY-S811
Output: Single
Operating Voltage: 4.8V / 6.0V
Operating Speed: 0.25sec. 60° / 0.21sec. 60°
Stall Torque: 26kg.cm / 33kg. cm
Size: 60x77x30mm
Weight: 164g
Motor: Brushed
Ball Bearing: 2BB
Gear: Metal
Plug: JR Type
Wire Length: 30cm

Can you share your script? What library are you using?

Im using just the Servo.h library, so its the exact same code as below.

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


#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(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>=1; 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 
  } 
}

I thought it possibly could be something to do with the timing, not giving the servo enough time to move to its new position before it loops through again. Thoughts?

When the servo is plugged into just the battery and the signal wire is touched by my hand, it sweeps randomly, so I assume the servo is ok.

I also saw on another thread someone post a servo test (Below), though only "servo-test-22-dual-input" is displayed in the Serial.

/ zoomkat 10-22-11 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// for IDE 0022 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.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control 
  Serial.println("servo-test-22-dual-input"); // so I can keep track of what is loaded
}

void loop() {
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string 
    int n = readString.toInt();  //convert readString into a number

    // auto select appropriate value, copied from someone elses code.
    if(n >= 500)
    {
      Serial.print("writing Microseconds: ");
      Serial.println(n);
      myservo.writeMicroseconds(n);
    }
    else
    {   
      Serial.print("writing Angle: ");
      Serial.println(n);
      myservo.write(n);
    }

    readString=""; //empty for next input
  } 
}

"I thought it possibly could be something to do with the timing, not giving the servo enough time to move to its new position before it loops through again. Thoughts?"

If you want to test that, increase the delay by about 10 times (just for a test). Did it help?

Not all servos are created equal. This one may be a rogue.

Ill have to have at look at it when I get home. I'll let you know what happens.

Im starting to think that the servo is a bit different to 'normal' ones.

I found this on a comment
"
Harold 1 points - 7/5/2015

I've received mine and let me tell you that they are huge and sturdy. To achieve about 160-170 degrees, I've applied a signal with the following characteristics: 333 - 250 Hz 0 degrees => 500 us center (since couldn't achieve 180 deg, center is half the maximum) 1500 us Maximum (about 160-170) 2500 us They also rotate really smooth and quite (no load)."

at Radio Control Planes, Drones, Cars, FPV, Quadcopters and more - Hobbyking

Maybe someone can decipher this.

UPDATE:

Changing the delay time to 20 milliseconds had no affect on the servo test code above. Still only output one line in the Serial Window.

Tried running Sweep again, with a re-check of wiring and grounding, it worked! I still cant explain why it didnt last time I tired, perhaps a silly wiring error. But will test again a few more times, and see if the servo continues to work.

Thanks for the suggestions guys!