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 :
i tested it using one single multiplexer and it workes as intended, but when adding the slave i cannot getting it to work, i am not sure how to code it.
When using this code :
// 74XX4051 ADDRESS PINS :
#define M_S0 2
#define M_S1 3
#define M_S2 4
#define S_S0 7
#define S_S1 6
#define S_S2 5
// 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 OF THE MASTER
for ( byte count = 0; count < 8 ; count++ ) {
// SET THE ADDRESS
digitalWrite(M_S0, bitRead(count, 0) );
digitalWrite(M_S1, bitRead(count, 1) );
digitalWrite(M_S2, bitRead(count, 2) ); // => 000 - Y1-Z
// LOOP THROUGH ALL THE ADDRESSES OF THE SLAVES
for ( byte count_1 = 0; count_1 < 32 ; count_1++ ) {
digitalWrite(S_S0, bitRead(count_1, 0) ); // => 000,000,000,000 => Z1, Z2, Z3, Z4
digitalWrite(S_S1, bitRead(count_1, 1) );
digitalWrite(S_S2, bitRead(count_1, 2) );
// READ THE ANALOG VALUE
value = (bitRead(count_1, 2),bitRead(count_1, 1),bitRead(count_1, 0));
}
// READ THE ANALOG FOR THE MASTER ADRESSE
value = analogRead(Z);
// SERIAL OUTPUT
// print : ### value
Serial.print(bitRead(count, 2));
Serial.print(bitRead(count, 1));
Serial.print(bitRead(count, 0));
Serial.print(' ');
Serial.println(value);
delay(100);
}
}
I' am only getting random readings really (The reading LED for the moisture sensor does not switches on when the reading is done)
What i am doing wrong ? .
Any help will be appreciated.