problem reading a specific analog output

Hi!

I wrote this little app to read from specific inputs on a multiplexor and I have 8 small potentiometers.

The problem is that when I ativate one input and read it's value it still reads all the other 7 values so it doesn't matter which input I activate I can still change the value with any of the potentiometers.

I'm using a: 74HCT4051N multiplexer
and regular analog potentiometers.

My code:

int analog1 = 0;
int value = 0;

void setup() {
  beginSerial(9600);        // connect to the serial port
}

void changeMpu(char val1, char val2, char val3) {
  digitalWrite(1, val1);
  digitalWrite(2, val2);
  digitalWrite(3, val3);
}

void loop() {
  changeMpu(LOW, LOW, LOW);  
  delay(1000);
  printString("A");
  value = analogRead(analog1);
  printInteger(value);
  serialWrite(10); // <-- end of line
  serialWrite(13); // <-- carriage return
  
  changeMpu(HIGH, LOW, LOW);
  delay(1000);
  printString("B");
  value = analogRead(analog1);
  printInteger(value);
  serialWrite(10); // <-- end of line
  serialWrite(13); // <-- carriage return
}

Thanks in advance!
/sebb0

It seems you haven't configured digital pins 1,2 and 3 as outputs, so function digitalWrite may don't work properly. But there is another problem:
when using serial comunication pins 1 and 2 cannot be used because they are mapped to Rx and Tx pins in the serial socket as you can see in the schematics.
So try to assign another set of pins as outputs and good luck. :wink:

Thanks for the quick answer and it works a bit better now.

Another problem I have is that when I change one of potentiometers that I haven't configured it to read the output to the computer just stops with a strange and always different letters.

Also, if I set one of the potetiometers to a specific position and then set to other to a different one, I get two different values which is good. But they aren't very stable and can change without me even touching the potentiometer.

Hej,

these problems you are reporting about the board-to-computer communication stopping, and the readings not being stable sound to me as typical wiring problems. I think you have to take a careful look to the circuit.

/David