Problem with coding HC4051

Are the pins connected according to the diagram or according to the defines in the sketch? The two don't match.

Why step through all 8 inputs on the master when you only have 4 slaves?

value = (bitRead(count_1, 2),bitRead(count_1, 1),bitRead(count_1, 0));

The commas don't paste the three bits together into a value. You probably meant:

  value = count_1 & 0x07;

You don't have the analogRead() inside the loop that loops through the slave inputs so you will only be reading input 7 of the first four slaves followed by the four unconnected inputs of the master.

If you want to display the first 32 inputs, try:

void loop () {

  int value;

  // LOOP THROUGH ALL THE ADDRESSES OF THE MASTER
  for ( byte count = 0; count < 32 ; count++ ) {

    // SET THE ADDRESS BITS
    digitalWrite(S_S0, bitRead(count, 0) );   // Slave A0
    digitalWrite(S_S1, bitRead(count, 1) );   // Slave A1
    digitalWrite(S_S2, bitRead(count, 2) );   // Slave A2

    digitalWrite(M_S0, bitRead(count, 3) );   // Master A0
    digitalWrite(M_S1, bitRead(count, 4) );   // Master A1
    digitalWrite(M_S2, bitRead(count, 5) );   // Master A2

    // READ THE ANALOG VALUE
    value = analogRead(Z);

    // SERIAL OUTPUT
    Serial.print(count, BIN);
    Serial.print('\t');
    Serial.println(value);
  }

  delay(3000);
}