Issue using 74HC4051 on custom PCB with Pots

I have this small board which runs 2 latching switches and 6 pots through a 4051 multiplexer into an arduino uno.

The switches appear to work perfectly but I'm having issues with the potentiometers as they appear to suffer from interference with one another whilst also converging down to ~0 over long periods of time.

I've tried using an external power supply for the uno and playing around with adding in delays but it appears the power supply did nothing and the delays only prolong the inevitable.

The code I'm currently using is basically a copy of the sparkfun guide but i've added it below.

Where I imagine the issues are originating are the PCB itself which I've attached png's of. Each pot runs through a 100nf cap which was recommended elsewhere as filtering but perhaps this is the crux of my issue? as I have seen examples without using caps before the input of the MUX.

Any help in the right direction would be much appreciated.

[code]const int selectPins[3] = {2, 3, 4}; // S0~2, S1~3, S2~4
const int zInput = A5; // Connect common (Z) to A5 (analog input)

void setup()
{
Serial.begin(9600); // Initialize the serial port
// Set up the select pins as outputs:
for (int i=0; i<3; i++)
{
pinMode(selectPins[i], OUTPUT);
digitalWrite(selectPins[i], HIGH);
}
pinMode(zInput, INPUT); // Set up Z as an input
pinMode(A0, INPUT); // Set up Z as an input

// Print the header:
Serial.println("Y0\tY1\tY2\tY3\tY4\tY5\tY6\tY7\tGND");
Serial.println("---\t---\t---\t---\t---\t---\t---\t---\t---");
}

void loop()
{
// Loop through all eight pins.
for (byte pin=0; pin<=7; pin++)
{
selectMuxPin(pin); // Select one at a time
int inputValue = analogRead(A0);
delay(100);
inputValue = analogRead(A5); // and read Z
Serial.print(String(inputValue) + "\t");
}
Serial.println();
}

// The selectMuxPin function sets the S0, S1, and S2 pins
// accordingly, given a pin from 0-7.
void selectMuxPin(byte pin)
{
for (int i=0; i<3; i++)
{
if (pin & (1<<i))
digitalWrite(selectPins[i], HIGH);
else
digitalWrite(selectPins[i], LOW);
}
}[/code]

I think that you misunderstand the use of a cap. It can be used with audio signals for DC decoupling. Otherwise it should remove noise when connected from signal to Gnd, alone or with a resistor as a low pass RC filter.

Your pots are basically DC values. Those caps should be between the pins and ground (or removed)

Thanks, i'll remove the caps and see how it fairs.

If You use autoformat in the IDE Your code looks like this:

const int selectPins[3] = {2, 3, 4}; // S0~2, S1~3, S2~4
const int zInput = A5; // Connect common (Z) to A5 (analog input)

void setup()
{
  Serial.begin(9600); // Initialize the serial port
  // Set up the select pins as outputs:
  for (int i = 0; i < 3; i++)
  {
    pinMode(selectPins[i], OUTPUT);
    digitalWrite(selectPins[i], HIGH);
  }
  pinMode(zInput, INPUT); // Set up Z as an input
  pinMode(A0, INPUT); // Set up Z as an input

  // Print the header:
  Serial.println("Y0\tY1\tY2\tY3\tY4\tY5\tY6\tY7\tGND");
  Serial.println("---\t---\t---\t---\t---\t---\t---\t---\t---");
}

void loop()
{
  // Loop through all eight pins.
  for (byte pin = 0; pin <= 7; pin++)
  {
    selectMuxPin(pin); // Select one at a time
    int inputValue = analogRead(A0);
    delay(100);
    inputValue = analogRead(A5); // and read Z
    Serial.print(String(inputValue) + "\t");
  }
  Serial.println();
}

// The selectMuxPin function sets the S0, S1, and S2 pins
// accordingly, given a pin from 0-7.
void selectMuxPin(byte pin)
{
  for (int i = 0; i < 3; i++)
  {
    if (pin & (1 << i))
      digitalWrite(selectPins[i], HIGH);
    else
      digitalWrite(selectPins[i], LOW);
  }
}

Are You sure You have analyzed the last function, selectMuxPin, for i = 0, 1 and 2? It looks cryptic to me.

When analogRead gives strange values in a tight loop like this I would use a short delay, a number of micro seconds, (read mux spec for settling time) after setting the mux to allow it to switch. Do every analogRead twice dropping the first reading often improves accuracy as well as stability.

Had a chance over the weekend to work on it and turned out it was a bit of everything. The capacitors were wrong to be going between the wiper and input of the 4051 but I did find some very minor improvement when connected between the wiper and ground on each pot.

Without the capacitor running between the wiper and input I got fairly consistent readings although with noise/fluctuations but no interference between pots. And just used this example to smooth out the noise with averaging.