Potentiometer spikes and dips

I am having problems with spikes/drops in potentiometer readings and am trying to find out what is causing it. The setup I have consists of an Uno R3 connected to a 9V power supply and also connected to an OTG Tablet via the USB Type B connector. The Tablet is running on it’s own battery.

Sensors used are a B1K potentiometer (I also have a B5K which shows the same problem) and a Melexis US1881 Hall-effect sensor) and the Arduino is also doing the PWM for a servo. The servo is quite grunty (33kg/cm) and has its own 5V/3A power supply. The servo has ground connected to one of the Arduino GND pins and the also to the GND of the power supply. The potentiometer and Hall-effect sensor share 5V from the Arduino, as well as GND (the second GND pin). Please see attached drawing.

The wiring is heat-shrunk together from the Arduino. The potentiometer is about 75cm from the Arduino, the rest of the wiring then goes to the HE sensor and the servo. The servo’s power supply wiring is a separate wire but is joined by the GND from the Arduino close to the servo. So the GND and PWM wires for the servo is in the same heat-shrunked section as the the wires for the pot and HE sensor. The wires are quite thin (7 strands tinned copper).

Typcially problem readings look like this: (circled areas on graph)
515,501,513 (drop of 14)
516,533,514 (spike of 17

A possible remedy could be to discard these spikes/drops, but I would like to find out what is causing these and would appreciate any feedback as to what can be fixed or improved to improve stability as I have occasionally very jumpy readings or stable readings with spikes/drops.

The normal reason for this with analogRead is just noise. The most common method to get rid of it is to make many readings and then take the average.

If you just add something like the following function to your sketch, and replace your original analogRead with analogAvg, it should help smooth things out.

int analogAvg(int pin)
{
int total=0;
for(int n=0;n<32;n++)
  total= total + analogRead(pin);
return total/32;
}

Everything should have separate ground wires, and they all should terminate to a common point (star-point connection scheme).

Could try a minimal sketch that's just reading the pot and displaying the results on print monitor (everything else disconnected). Perhaps even storing and printing min/max values.

Also could try substituting the pot for a 1K/1K divider and test for stability.

If the problem goes away, it could be determined which device or component is creating it.

The potentiometer and Hall-effect sensor share 5V from the Arduino, as well as GND (the second GND pin). Please see attached drawing.

Not good. There's an opportunity for the pot wires to pickup the signal from the Hall-effect sensor. In fact, this is my #1 guess as to what the main problem is.

might be a candidate for running median - http://arduino.cc/playground/Main/RunningMedian - (size 7 or so)

dlloyd: Everything should have separate ground wires, and they all should terminate to a common point (star-point connection scheme).

Thanks, I take it I should have the three separate GND wires (servo, pot, HE) connected to one Arduino GND pin (rail). Would it make any difference if the servo GND is on a separate Arduino GND pin to the other two?

dlloyd: Not good. There's an opportunity for the pot wires to pickup the signal from the Hall-effect sensor. In fact, this is my #1 guess as to what the main problem is.

To clarify things for myself, would the possible signal pickup be by the shared 5V or the shared GND or both?

Would it make any difference if the servo GND is on a separate Arduino GND pin to the other two?

Probably not ... but you could use just one GND wire from the Arduino that connects to the common ground point.

To clarify things for myself, would the possible signal pickup be by the shared 5V or the shared GND or both?

Ahh, I see now that the yellow wire (sensor signal) is separate. Any ways, I think it would be good to use completely separate wiring for the sensor and pot.

dlloyd: Everything should have separate ground wires, and they all should terminate to a common point (star-point connection scheme).

This was what the problem was ultimately (using separate wires for all). Thanks to everyone for their help and very useful suggestions.

As an aside, I use the Melexis US1881 Hall Effect sensor as an rpm counter and was getting unexplicable latch behaviour as well. It turned out that using a very strong slide past magnet would latch/unlatch it unexpectedly. The solution was to either use a much weaker magnet closer to the sensor or a smaller thinner cylindrical magnet further away.

Hi, sorry but I would be shot for producing a graph like that, what is it a graph of? What is the y axis, scale, Volts, mVetc What is the x axis?

Without scales we cannot judge the severity of the noise.

Tom...... :)