Servo control - HS-805MG

Trying to get a Hitec servo to operate and its just buzzing.

Using Mega 2560 on USB and the Servo on 4x AA.

Tried different sketches but no success with anything.
Control wire from servo set to PWM #9.

Found this data and tried sending a pulse but still nothing...
https://www.servocity.com/html/hs-805mg_servo.html#.VgZBf7e5dyp

Thanks in advance

//
#include <Servo.h>
/
/
Servo myservo;//create servo object to control a servo
//
void setup()
{
myservo.attach(9);//attachs the servo on pin 9 to servo object
myservo.write(1500);//back to 0 degrees
delay(1000);//wait for a second
}
/
*/
void loop()
{
myservo.write(1500);//goes to 0 degrees
delay(1000);//wait for a second
myservo.write(600);//goes to 90 degrees
delay(1000);//wait for a second.33
myservo.write(1500);//goes to 0 degrees
delay(1000);//wait for a second.33
myservo.write(2400);//goes to 90 degrees
delay(1000);//wait for a second.33
myservo.write(1500);//goes to 75 degrees
delay(1000);//wait for a second.33

}

You need to make sure the arduino ground and servo ground are connected together like in the attached pix.

servo-wire.jpg

myservo.write(600);//goes to 90 degrees

Your numbers seem to be all over the place.

0 degrees should be about 1000 µsecs
90 1500
180 2000

The actual range of servos varies. If in doubt start at the centre and explore outwards in both directions.

...R

thanks Zoomkat...instant function!

R - the datasheet shows 0 @ 1500 then 600 to 90 or 2400 to other 90.

Seems to work now.
Will add a pot and see what i can do

jeep15cba:
R - the datasheet shows 0 @ 1500 then 600 to 90 or 2400 to other 90.

I'm curious.
Would you mind posting a link to the datasheet ?

...R

R - the datasheet shows 0 @ 1500 then 600 to 90 or 2400 to other 90.

Those position values are what is normally seen for RC control (+-45 deg or +-90 deg from the center 0 deg position) Those position commands are microsecond values, so you should use writeMicroseconds() for them. Below is some servo test code for testing the degree commands and the microsecond commands.

// 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, 500, 2500);  //the pin for the servo control, and range if desired
  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);
    }
    Serial.print("Last servo command position: ");    
    Serial.println(myservo.read());
    readString=""; //empty for next input
  } 
}

zoomkat:
Those position values are what is normally seen for RC control (+-45 deg or +-90 deg from the center 0 deg position)

Are you sure?
My servos don't work like that. They use (approx) the range 1000 to 2000 µsecs.

...R

Are you sure?
My servos don't work like that. They use (approx) the range 1000 to 2000 µsecs.

I can't speak to your servos, but I have several different brands of the inexpensive analog hobby RC type servos and can usually use a range in excess of your servos, maybe more like 500us-2500us or a little less to get 180 deg rotation. YMMV

zoomkat:
I can't speak to your servos, but I have several different brands of the inexpensive analog hobby RC type servos and can usually use a range in excess of your servos, maybe more like 500us-2500us or a little less to get 180 deg rotation. YMMV

That I can understand.

But the OP said something very different. He said (in the Reply you quoted) that 1500 gave 0 deg and 600 gave 90 deg

...R

But the OP said something very different. He said (in the Reply you quoted) that 1500 gave 0 deg and 600 gave 90 deg

I'm not in a position to explain what the OP is saying or seeing, I'm just giving my understanding of how servos work. The OP is using out of bounds microsecond values with myservo.write which normally uses degree values such as 0-180. There is some accommodation for out of bound values in the servo library but I can't say if that influences what the OP"s servo is doing.

 myservo.write(1500);//goes to 0 degrees
  delay(1000);//wait for a second
  myservo.write(600);//goes to 90 degrees
  delay(1000);//wait for a second.33
  myservo.write(1500);//goes to 0 degrees
  delay(1000);//wait for a second.33
  myservo.write(2400);//goes to 90 degrees
  delay(1000);//wait for a second.33
  myservo.write(1500);//goes to 75 degrees
  delay(1000);//wait for a second.33

Hey guys,

Link to the datasheet from the OP https://www.servocity.com/html/hs-805mg_servo.html#.VgZBf7e5dyp

I've thrown another code into it and now it moves smoothly whilst controlled by a 10k pot
//
#include <Servo.h>
/
/
Servo myservo;//create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
//
void setup()
{
myservo.attach(9);//attachs the servo on pin 9 to servo object
myservo.write(1500);//back to 0 degrees
delay(1000);//wait for a second
}
/
*/
void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 600, 2400); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there

}