Servo Problem (Jiggle and Power)

Hello, I have a problem that my GWS PARK HPX servo was jiggling. I try many different programs, but all of them didn't work. I connected 6V individual battery power to servo but it had no response, either I connected it to 5V on arduino. After I connected it to VIN and it worked, but not work as I respected.

Please help.

Adam

#include <Servo.h> 

Servo myservo;
int value = 0;

void setup() 
{ 
  myservo.attach(9);  
} 
 
void loop() 
{ 
  if (value == 0) 
    value = 120;
  else
    value = 0;
  
  myservo.write(value); 
  delay(1500);
}

Do you have the ground on the arduino connected to the ground on the battery?

You risk damaging your Arduino (and computer even) doing this, use a separate supply for servos, always.

USB can only provide 0.5A, servos take more (the peak currents can be a lot more). And yes when you run
from separate power you must common the grounds together and use a power source that can handle
at least an amp comfortably if you want reliable servo action. 9V PP3-size batteries are not suitable at all BTW,
they only do 100mA or thereabouts. 4 x NiMH AA cells might be a reasonable choice, or a 6V 1A+ wall-wart.

Try some code that is not in a loop.

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

Thanks!

After using separate battery the servo can run well.

Can I use 9v battery to arduino board and supply the servo with arduino 5V pin?

r5059112:
Thanks!

After using separate battery the servo can run well.

Can I use 9v battery to arduino board and supply the servo with arduino 5V pin?

No, the voltage regulator on the arduino board is not capable of supplying the power to the servo regardless of what adapter you use. You need to bypass the arduino completely with your power supply to the servo (and any other motors for that matter).

Like MarkT said, you can NOT use a 9V battery to power the servo. It is not capable of supplying enough current for any amount of time, plus it's too high for the servo to be directly connected. Use a battery pack of 4AA cells to power the servo. It's always a good idea to keep motor power supplies as separate as possible from the logic supplies.

Thank for everyone!

I learn a lot from you!

Adam