Mux reading problem.

Dear all.
I am using Below circuit and arduino to get data. My concept is simple Instead of sensor i am giving predefined voltage 0~5v using potentiomenter .Here is My code.In below code I whenever particular pin connected A0~A7 i can read proper values.

Here is problem statement.

There are totally 2 mux circuit . I am switching channel for 50ms.So i can read values. Here what i am testing. I have connected Ao with 5v of mux1 IC and other 15 analog values are not connected. I am expecting 0 in other 15 channel expect MUX1 analog channel Ao pin enabled.For your reference i have attached snap shot of serial monitor. I can read value 5v properly in paricular channel . But other analog which get switched / or not connected reading unexpected values instead of Zero.

So how can i solve the problem here. I tried to increase delay of switching didn’t worked. SO why it reading values even if those pins are not connected.

#include <avr/wdt.h>
int SO_enable=7;
int S1_enable=6;
int S2_enable=5;
int Enablepin=4;
int Sensor_Value0=0;
int Sensor_Value1=0;
float  voltage0;
float voltage1;
float ARDUINO_ANALOG_SCALING=0.0048875855327468231;
int row,column;
int DigitalHigh=8;
int DigitalHigh1=9;
float  Mux1_array[9]={
  0.0};
float  Mux2_array[9]={
  0.0};
int array[9][4]={
  {    0,0,0,0  }
  ,
  {    0,0,0,1  }
  ,
  {    0,0,1,0  }
  ,  
  {    0,0,1,1  }
  ,
  {    0,1,0,0  }
  ,
  {    0,1,0,1  }
  ,
  {    0,1,1,0  }
  ,
  {    0,1,1,1  }
  ,
  {    1,0,0,0  }

};

void setup()
{
  wdt_enable(WDTO_8S);
  pinMode(SO_enable, OUTPUT) ;// pin can enable/disable using digital IO 7 of arduino
  pinMode(S1_enable, OUTPUT) ;// pin can enable/disable using digital IO 6 of arduino
  pinMode(S2_enable, OUTPUT) ;// pin can enable/disable using digital IO 5 of arduino
  pinMode(Enablepin, OUTPUT) ;// pin can enable/disable using digital IO 4 of arduino
  pinMode(A0, INPUT) ;
  pinMode(A5, INPUT) ;
  pinMode(DigitalHigh,OUTPUT);
  pinMode(DigitalHigh1,OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  wdt_reset();
  digitalWrite(DigitalHigh,HIGH);
  digitalWrite(DigitalHigh1,HIGH);
  for(row=0;row<6;row++)
  {
    int k=(8*array[row][0]+4*array[row][1]+2*array[row][2]+1*array[row][3]);
    digitalWrite(Enablepin,array[row][0]);
    digitalWrite(SO_enable,array[row][1]);
    digitalWrite(S1_enable,array[row][2]);
    digitalWrite(S2_enable,array[row][3]); 
   delay(50); 
    Sensor_Value0=analogRead(A0);
    Sensor_Value1=analogRead(A5);
    Mux1_array[row]=(Sensor_Value0 * ARDUINO_ANALOG_SCALING);
    Mux2_array[row]=(Sensor_Value1 * ARDUINO_ANALOG_SCALING);
    Sensor_Value0=0;
    Sensor_Value1=0;
    Serial.print("Ao mux1 sens value:");
    Serial.print(Mux1_array[0]);
    Serial.print("\t");
    Serial.print("Ao MUX2 sens value:");
    Serial.println(Mux2_array[0]);
    Serial.print("A1 mux1 sens value:");
    Serial.print(Mux1_array[1]);
    Serial.print("\t");
    Serial.print("A1 MUX2 sens value:");
    Serial.println(Mux2_array[1]); 
    Serial.print("A2 mux1 sens value:");
    Serial.print(Mux1_array[2]);
    Serial.print("\t");
    Serial.print("A2 MUX2 sens value:");
    Serial.println(Mux2_array[2]);
    Serial.print("A3 mux1 sens value:");
    Serial.print(Mux1_array[3]);
    Serial.print("\t");
    Serial.print("A3 MUX2 sens value:");
    Serial.println(Mux2_array[3]);
    Serial.print("A4 mux1 sens value:");
    Serial.print(Mux1_array[4]);
    Serial.print("\t");
    Serial.print("A4 MUX2 sens value:");
    Serial.println(Mux2_array[4]);
    Serial.print("A5 mux1 sens value:");
    Serial.print(Mux1_array[5]);
    Serial.print("\t");
    Serial.print("A5 MUX2 sens value:");
    Serial.println(Mux2_array[5]);
    Serial.print("A6 mux1 sens value:");
    Serial.print(Mux1_array[6]);
    Serial.print("\t");
    Serial.print("A6 MUX2 sens value:");
    Serial.println(Mux2_array[6]);
    Serial.print("A7 mux1 sens value:");
    Serial.print(Mux1_array[7]);
    Serial.print("\t");
    Serial.print("A7 MUX2 sens value:");
    Serial.println(Mux2_array[7]);
    Serial.print("A8 mux1 sens value:");
    Serial.print(Mux1_array[8]);
    Serial.print("\t");
    Serial.print("A8 MUX2 sens value:");
    Serial.println(Mux2_array[8]);
    Serial.println("...................................................................");
    
    
  //delay(500);
  }


}

Mux_test1.pdf (4.01 KB)

and other 15 analog values are not connected. I am expecting 0 in other 15 channel

Sadly, AVR inputs are immunised against hope before they leave the factory.
If you expect zero, then you must connect the inputs to ground.

int array[9][4]={
  {    0,0,0,0  }
  ,
  {    0,0,0,1  }
  ,
  {    0,0,1,0  }
  ,  
  {    0,0,1,1  }
  ,
  {    0,1,0,0  }
  ,
  {    0,1,0,1  }
  ,
  {    0,1,1,0  }
  ,
  {    0,1,1,1  }
  ,
  {    1,0,0,0  }

};

What’s this waste of RAM doing here?

I didn't get your answer.

If you expect zero, then you must connect the inputs to ground.

My question is simple.When i am switching and given input @ particular A0~A7 i am expecting 5v or ov. If particular pins get connected

Example S0,s1,s2=0 AO pin given 5v . I expected 5v , At same when It switch to S0=0,s1=0,s2=1 I expect A1 pins read zero since nothing being connected to pin. similarly in all pins of mux IC.

AO only should read 5v and A1~A7 should read Zero values.

If i apply voltage @ each pins using voltage devider network or potentiometer it read properly. SO my question is Why can't it read if nothing connected.

I also found that When any data line given with 5v . Other data lines also carry voltage which matching to voltage shown in fig?? My question is Why?? I check circuit there is no Shorting of pins. How it is getting voltage. All are under same ground potential.

I don't understand what you're saying.

If you expect to read zero on an analogue input pin, that pin must be connected to ground.

This is my circuit. You mean to say When i connect pins Gnd or 5v then only it read particular pins as zero.Its true Here I can find changes when i give 5v or gnd pins.

I got my answer 70% but remaining 30% is remain question

If The pins are open I can’t expect Zero. My question is Why?? Why can’t expect zero.

MUX testing.pdf (51.6 KB)

If The pins are open I can't expect Zero. My question is Why?? Why can't expect zero

Because they're high impedance floating pins - they'll pick up any stray signals.