Servo motor vibration

Hi everyone,

I'm using a 20 kg.cm servo motor for my project. I use an external power supply (USB port with the wires cut and connected to the power terminals of the servo motor). I also power my Arduino UNO using USB cable from the same computer.

Well, I use this code to send directions to the motor :

#include <Servo.h>
Servo servo;
char val[4];
int sval;
void setup()
{
  servo.attach(2);
  Serial.begin(9600);
  while(!Serial);
}

void loop()
{
  if (Serial.available() > 0)
  {
    Serial.readBytesUntil('\n', val,3);
    Serial.println(val);
    sval = String(val).toInt();
    if (sval != servo.read())
      {servo.write(sval);}
    delay(150);
  }
  Serial.flush();
}

Actually it works fine (only if I write 3-digit numbers in the serial monitor like "060" -_- ), however, most of the time, the servo vibrates and the shaft keeps going right and left (vibrating). I think the USB port of my laptop supports 1A current and +5V voltage. There is no load on the servo at all. Also, at some angles (like 50, 4,5,150), there is no vibration !!!

What is the reason for that ?

relevant reading.. "DBW"

..point out this:
..... servo is controlled by a string of pulses, normally 60 pulses per second. The pulse width controls the servo position, 1 msec for full right and 2 msec for full left. If the pulse width is 1.5 msec the servo is centered. However what happens if the pulse changes to 1.5 msec+ 1 usec. If the dead time is 2 usec nothing happens. If the dead time is zero the servo will do a constant dance.
I have no idea what is best, whatever works.

Thank you.
But this means that this vibration is something normal ?
How can I send a fixed frequency of 60 pulses per second no more no less ?

eng_osama:
Thank you.
But this means that this vibration is something normal ?
How can I send a fixed frequency of 60 pulses per second no more no less ?

It's the pulse width (1-2 millisecond) that is the primary information used and sent to a servo, the frequency of the pulses is more an artifact of the framing rate of the R/C analog radio communication protocol for which servos were originally developed to operate with.

I hope you dont try to drive your servo outside it mecanical limits.
There is no guarantee that it will handle the full range (0..180, parameters to the servo library)
Check your servos datasheet to find "dead time"..

The servo library produces the correct sequence of signals to control a servo when you call servo.Write() or servo.WriteMicroseconds(). There should be no need to wonder about anything apart from the angle (with servo.write() or the pulse width with servo.WriteMicroseconds.

I suspect you need a better power supply for the servo - that sounds like a powerful servo.

There is a separate issue that has been discussed several times on the forum where sevos move unpredictably if connected to power before the Arduino starts sending signals. That doesn't seem to be your problem - unless for some reason you are using servo.detach().

...R

Thank you all guys. The problem was just a power problem.
It seems that there is no accurate specification of my servo or the max output current of the USB port.

But when using PC power supply to externally power the servo, it worked perfectly.

I repeat, thank you.

Well obviously a 20 kg-cm servo is going to take many amps, the maths is obvious:

20 kg-cm = 2 N-m, normally servos seek around 6 radians/s, so mechanical power
= 2 * 6, allow a factor of two for mechanical losses and motor losses, something
like 24W is needed, 5A at 5V...