hello guys,
I designed an array of 16 IR sensors based on 2 IR LED and a phototransostor each.
when I read a value from the phototransistor directly from its pin, there is no problem, everithing is ok, and the value is changing correclty when I put an object in front of it.
but, when I use the mux to get all the values, the results are very very strange, almost random for every sensors, and only from 0 to 255 (normaly I can go up to about 1000).
my mux is the CD4067BE from TI: http://www.ti.com/product/cd4067b
an example of the 16 values from the array I obtain (they should be steady at about 880):
149, 39, 0, 212, 184, 152, 125, 105, 133, 78, 5, 210, 159, 113, 61, 37,
194, 172, 178, 184, 192, 203, 223, 214, 183, 174, 158, 136, 113, 93, 66, 26,
245, 207, 158, 128, 96, 85, 68, 69, 237, 211, 212, 214, 213, 218, 210, 200,
167, 78, 21, 220, 185, 147, 106, 81, 66, 252, 199, 164, 129, 102, 76, 76,
163, 137, 90, 34, 5, 209, 173, 143, 64, 14, 226, 187, 140, 94, 52, 25,
there is my circuit, the sensors are on the left (phototransistor in the upper part, centered, and the 2 gray LED are the IR emiters)
the orange wires are for the controls, and the blue wires are the analog inputs (I didn't draw all of them to make it more clear)
for the code, I use port manipulation (PORTD):
in the setup:
byte controlPins[] = {B00000000,
B10000000,
B01000000,
B11000000,
B00100000,
B10100000,
B01100000,
B11100000,
B00010000,
B10010000,
B01010000,
B11010000,
B00110000,
B10110000,
B01110000,
B11110000
};
byte muxValues[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
and in the loop:
for (int i = 0; i < 16; i++) {
PORTD = controlPins[ i];
muxValues[ i] = analogRead(0);
delay(100);
}
(the delay is just to make it more readable, but the results are the same without)
what did I made wrong?