Hi everyone, i hope i can get somehelp on how getting this to work.
I have multiple Sensors (32 of these) i want to read their values. I am using a master multiplexer HC4051 connected to 4 slave multiplexers, this is my wirings :
http://i.stack.imgur.com/IBdBc.pngAnd this is my code
// 74XX4051 ADDRESS PINS :
#define M_S0 7
#define M_S1 6
#define M_S2 5
#define S_S0 2
#define S_S1 3
#define S_S2 4
// 74XX4051 ANALOG PIN :
#define Z 0
void setup(){
// CONFIGURE ADDRESS PINS
pinMode(M_S0, OUTPUT);
pinMode(M_S1, OUTPUT);
pinMode(M_S2, OUTPUT);
pinMode(S_S0, OUTPUT);
pinMode(S_S1, OUTPUT);
pinMode(S_S2, OUTPUT);
// CONFIGURE SERIAL
Serial.begin(57600);
}
void loop () {
int value;
// LOOP THROUGH ALL THE ADDRESSES
for ( byte count = 0; count < 32 ; count++ ) {
digitalWrite(M_S0, HIGH); //TURN THE SENSOR ON FOR READING
digitalWrite(M_S1, HIGH);
digitalWrite(M_S2, HIGH);
digitalWrite(S_S0, HIGH);
digitalWrite(S_S1, HIGH);
digitalWrite(S_S2, HIGH);
// 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
delay(50);
// READ THE ANALOG VALUE
value = analogRead(Z);
digitalWrite(M_S0, LOW); //TURN THE SENSOR OFF WHEN READING IS DONE
digitalWrite(M_S1, LOW);
digitalWrite(M_S2, LOW);
digitalWrite(S_S0, LOW);
digitalWrite(S_S1, LOW);
digitalWrite(S_S2, LOW);
// SERIAL OUTPUT
Serial.print(count, BIN);
Serial.print('\t');
Serial.println(value);
}
delay(3000);
}
1- All my sensors are in the air, so i should expect a “0” reading. but i’am getting really random reading from the serial monitor every cycle ! (4 of my sensors are not connected to the multiplexer, does make any interferance ?)
2- The part ```
digitalWrite(M_S0, HIGH); … digitalWrite(M_S0, LOW);