grounding and potentiometers?

hi there,
i am having problems with hooking up a simple 10k potentiometer to the arduino. if i touch the potentiometer i get very stable values but as soon as i take my hand of it it starts to become unstable. i am suspecting this is due to improper grounding. would this effect stop if i would screw the potentiometer into a metal box? (and if i would use proper connectors and wires to the arudino)?

here my script:

#include <MIDI.h>
#define LED 13   		// LED pin on Arduino board

void setup() {
  pinMode(LED, OUTPUT);
  MIDI.begin(1);            	// Launch MIDI with default options
}

void loop() {
  int inFader         = 0;
  static int prevVal  = 0;
  inFader    = (inFader + analogRead(0));
  delay(1);
  inFader    = (inFader + analogRead(0));
  delay(1);
  inFader    = (inFader + analogRead(0));
  delay(1);
  inFader    = (inFader + analogRead(0));
  inFader    = (int) (inFader * 0.25) * 0.125;
  if (inFader != prevVal) {
     MIDI.sendControlChange(10, inFader,1); //cc, val, ch; 0 = ch16!
     prevVal = inFader;
  }
  
}

I'm not sure why you're reading the input multiple times then "averaging" the values (not sure why you're averaging the four measurements, then taking 1/8 of that measurement, either) - unless you were trying to combat what you are seeing.

It may be that you need better grounding (or shielding, actually) - but I really suspect that it may be those funky paperclips inducing/picking up noise, adding parasitic capacitance, extra resistance, who knows what...

I would first try removing those from the leads, stripping and re-tinning the ends of the leads well to be able to insert them directly into the headers (or solder on short lengths of solid -copper- wire for the ends).

Good luck.

I worked on a project some years ago which was using potentiometers to give a position feedback for a robotic leg. I had lots of problems with noise from the potentiometers which threw off the balance of the leg periodically. It turned out to be a mixture of unshielded connectors and cheap potentiometers.
I would start by shielding the connections and then look at the quality of your components.

If your application allows it, have you tried connecting a small capacitor (0.01uF perhaps) between the wiper on your potentiometer to ground?

This thread is 7.5 years old and OP is long gone.