Problem: Electronic fluctuations when using potentiometer and SG-90

Hello Everyone.

I set up a circuit where I could change the angle of the servo with a potentiometer. I have a few problems:

-Sometimes the value that the potentiometer reads changes crazily even when I am not touching it. For example in the picture I’ve attached, it varies between 146 and 176 which means the difference goes up to 30 without touching the potentiometer. But let’s say this is a problem caused by the loose contact. Because sometimes the difference in values is 3 or 4 which is more suitable than 30.

-Here comes the second problem: Why there is a difference in values when I was not touching the potentiometer? How can I prevent this?

The Code:

#include <Servo.h>

Servo servo1;
int value;

void setup()
{
  Serial.begin(9600);
  servo1.attach(6);
}

void loop()
{
  value = analogRead(A0);
  value = map(value,0, 1023, 0, 180);
  servo1.write(value);
  Serial.println(value);
  delay(150);
}

The readings:

Thanks.

How is the pot wired and what type of connections are you using ?
Are you using a breadboard ?

I agree, likely caused by a loose contact.

The solution should be obvious. Fix that loose contact.

I’m sorry for the missing details. Servo is directly connected to the Arduino with jumper cables, the potentiometer is connected by using a breadboard. Would fixing the loose contact solve all the electronic fluctuations including the small ones?

A loose connection involving the pot will probably cause a variation in the voltage read by the Arduino. Breadboard connections are notorious for not providing secure, unchanging connections, particularly if the jumper wires are sub par

2-3 points jitter is perfectly normal. You will always see this.

Thank you for your responses. They were useful to me.

So, have you solved the problem ?

In future, if you need to post the Serial monitor output then instead of a picture of it, select the text using the mouse, then press Ctrl-C and the text will be copied to the clipboard ready to paste here, using code tags when you do

It's a feedback loop. If all the connections are not 100% solid you will always get jitter. That's a given for a feedback
loop.

You should never attempt to power motors or servos from the Arduino 5V line. The Arduino can actually be destroyed that way! Yes, I know, there are a lot of bad tutorials that tell you to do that.

Use a 4xAA battery pack for 1-2 servos, and be sure to connect the grounds.

wvmarle:
2-3 points jitter is perfectly normal. You will always see this.

Actually no, on a battery powered ATmega328 I get < 0.5 LSB jitter, its actually very well
behaved.

However if powered with USB or a buck converter, or if there are loads being switched I’d
agree that a few counts variation is pretty common.

As for the actual problem I suspect either long cables, poor layout, perhaps a high value pot (10k or
5k is a good value to choose).

If the servo is being powered from the 5V Arduino pin that could explain it - this is very poor
practice for many reasons. Separate servo power is strongly advised.

Mmm... Can try battery power... The other day I built a project with two 100k pots, got about 2 steps jitter. Adding a 33nF cap between the wipers and gnd didn't help, that should be more than enough to thoroughly stabilise the thing and even make discarding the first ADC read unnecessary. Averaging 64 samples gets it nice and stable. This is an ATtiny861a on USB power, as DAC experiment, the only output now is an RC filter on the OC1B pin.

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