I’m working on a basic robotic arm controlled using potentiometer input to position a servo motor. While the system functions, I’m facing an issue where the servo exhibits jitter and does not always move smoothly or accurately to the intended angle, especially when the potentiometer is near certain positions.
I’ve included my full hardware setup, current code, and a clear description of the problem below. My goal is to achieve stable, smooth servo motion that accurately reflects the potentiometer input. I suspect the issue may be related to how I’m handling analog readings, timing, or signal updates, and I’d appreciate guidance on correcting this behavior or improving the approach.
Any feedback, best practices, or suggestions are welcome.
Specific Issue:
Even when the potentiometer is held steady, the servo continues to make small, rapid movements instead of holding a fixed position. This jitter becomes more noticeable near the middle range of the potentiometer.
Expected Behavior:
The servo should remain stable at a fixed angle when the potentiometer is not being adjusted.
Actual Behavior:
The servo constantly corrects itself with small movements, resulting in jitter and audible noise.
Hardware Setup:
Arduino Nano
Standard servo motor (SG90) connected to pin 9
Potentiometer connected to A0
External 5V supply for the servo (common ground with Arduino)
Code -
#include <Servo.h>
Servo armServo;
const int potPin = A0;
const int servoPin = 9;
int potValue = 0;
int servoAngle = 0;
unsigned long previousMillis = 0;
const unsigned long interval = 20;
void setup() {
armServo.attach(servoPin);
Serial.begin(9600);
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
potValue = analogRead(potPin);
servoAngle = map(potValue, 0, 1023, 0, 180);
Serial.print("Pot: ");
Serial.print(potValue);
Serial.print(" | Angle: ");
Serial.println(servoAngle);
armServo.write(servoAngle);
}
}
Servo jitter is often due to an inadequate servo power supply, which must be able to supply at least 1 Ampere per servo, for SG90. Please post a wiring diagram, with all parts identified (including type of Arduino), and the details of the servo power supply. A photo of the setup would also be helpful.
Any variation of the potentiometer 5V (or 3.3V) supply will also show up as servo jitter.
Is the pot value obtained with analogRead() jumpy? If so you could implement a smoothing algorithm or (IMO Better) switch to a differential rotary encoder device.
Regarding the power supply: the servo is powered from an external regulated 5V supply rated at 2A, with the ground connected in common with the Arduino Uno. The Arduino itself is powered via USB. I’ll attach a wiring diagram/photo of the setup in my next post for clarity.
As for the potentiometer input, I monitored the values using Serial.println() and the readings do fluctuate slightly even when the potentiometer is held steady, especially around mid-range values. This seems to correlate with the servo jitter I’m observing.
I’m going to experiment with input smoothing (averaging / deadband) to see how much this reduces the issue. I’ll also look into encoder-based input as suggested, as that may be more appropriate for precise positioning in a robotic arm application.
I appreciate the suggestions — I’ll report back once I’ve tested these changes.
A quick test - if the servo jitters when you explicitly write a value (as opposed to reading an analog input), then the problem lies not in the analog input approach, but in the wiring of the servo. Conversely, if it's quiet with a fixed value, then the problem lies with the analog input and it's conversion to a servo angle.
Servo jittering is common, as well as all the above possible cures, one that gets ignored a lot is because you are writing an angle. This is inaccurate and will cause you problems. What you need to do is to use writeMicroseconds method of setting the servo's position. See the documentation for the servo library.
That in of it self will not immediately stop the jittering, but will allow you much finer control to find a point where the servos do not jitter. Hint, try this on just one servo at first. It is better to do things one step at a time when hunting down a soloution for any problem.
@learn_with_passion - it would be helpful to the community for you to post a complete sketch with your solution and say a little bit about all and what went into solving your problem.
I only notice now this is you first thread. Ppl don't always stick around and share, but it's nice when they do!