Servo motor twitching when used with potentiometer

My servo is twitching when controlling it with a potentiometer. I’m using the basic example “Knob” file from the Arduino IDE to do this.

I’m using an MG996R servo motor controlled with a 10k ohm linear potentiometer. Its power supply is a Tiger 7.4V Li-po battery that goes through an LM2596 Buck Converter that lowers the voltage to 4.8V. The operating voltage of the MG996R is 4.8V to 6.6V.

Any suggestions for tips on how to stop this would be much appreciated.

provide links please.

Try a 0.1uF - 1uF capacitor from the pot wiper to ground. The cap will act as a low pass filter and help with noise from the pot.

1 Like

@ej_salga Two thoughts on servo jitter.

  1. Yes, your analog value may vary without a filter cap, and may not be stable even with one (typically, 1-2 counts, but I've seen +/-3 worst case). Since 4 counts translates to roughly 1% on a 0-1023 count ADC, and 1% is more than a degree for a +/-90 degree servo, your servo position may be seeing 'command position change' of 1 or 2 degrees. You can check this by sending the command value to the Serial Monitor whenever it's different from the previous value. Filtering can improve this a lot.
  2. Even with filtering, that example uses degrees(the pot reading is mapped to an integer range). A single count change in the ADC can result in a whole degree of change on the servo. That's just the nature of that example code.

To improve it, you can gain some fine control by switching the servo range to integer microseconds instead of integer degrees. If you dig into the servo.h file in the examples folder, you'll find that mapping the number to a value in the range 544 to 2400 will give you finer control, but you'll need to use different calls to the library to utilize numbers in this range.
If this is 'greek', I can explain in more detail.
C

Hi,
Have you got the gnd of the Arduino and the gnd of the servo power supply?

What model Arduino are you using?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

I apologize for the late reply. Here is the picture diagram for the connections.

@groundFungus Thank you for your suggestion. I don’t understand how to connect the pot wiper to the ground. Does one end connect to the Vin pin and the other to the gnd pin?

@camsysca Thank you for the reply. So you mean with or without the filter from the capacitor, to entirely stop the twitching, I need to put in microsecond values instead of degrees in the map() command? Could you please give an example code on how to do this? Thank you :slight_smile:

@TomGeorge Yes, I connect the gnd of the power supply to the Arduino’s gnd pin which is connected to the servo and pot.

I’m using a Arduino Nano clone (CH340)

What is the output voltage of the LM2596 regulator?

If it is 5V, do not connect it to Vin, connect 5V to the 5V pin. If it is not 5v, it must be more than 7V and connect to Vin or the onboard 5V regulator will not work. If it between 5V and 7V, you need to adjust it. Best is to set it to 5V and connect it to the 5V pin.

The pot should connect one end to ground, the other end to 5V (not Vin), and the wiper to the analog input A0.

Connect the cap to the pot wiper and to ground.

The Arduino language reference has a reference for the Servo library and the writeMicroseconds() function.

HI,
This;

Or this;

Tom... :smiley: :+1: :coffee: :australia:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.