Strange analog input with 4067 multiplexer

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?

HI,
If you look at one only sensor through the 4067, and do not scan for the others, what results do you get?
If you feed 0V and then 5V instead of the sensr output into the 4067, what do you get?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Fritzy is not a schematic...

Tom..... :slight_smile:

thanks I will try this.

I made a quick schematic

OK so I modified the for loop in order to read only the value from the adress 0 on the MUX:

for (int i = 0; i < 16; i++) {
//PORTD = controlPins[ i];
muxValues[ i] = analogRead(0);
// delay(100);
}

and of course I put PORTD = B00000000; in the setup to put all the MUX controls in LOW.

with direct link to +5V ang GND it works great and instantaneously.

With the sensors, it "works" somehow, but it is very very noisy with some gaps. for examples, when I move slowly my hand before the receptor, I get this kind of data:

102, 102, 103, 103, 103, 103, 103, 103, 102, 102, 102, 102, 102, 101, 102, 101,
109, 109, 108, 108, 108, 108, 108, 108, 108, 109, 109, 107, 110, 109, 110, 110,
114, 114, 114, 115, 116, 115, 115, 115, 114, 115, 114, 114, 114, 111, 113, 113,
118, 118, 119, 118, 118, 118, 118, 119, 119, 119, 120, 119, 119, 120, 118, 120,
133, 132, 133, 134, 133, 133, 132, 133, 134, 132, 133, 132, 133, 133, 133, 132,
154, 153, 154, 153, 153, 153, 154, 155, 155, 155, 155, 155, 156, 156, 156, 156,
178, 178, 178, 179, 179, 178, 178, 178, 178, 180, 179, 178, 178, 179, 179, 179,
216, 216, 216, 215, 216, 214, 217, 217, 217, 216, 214, 213, 214, 215, 216, 217,
22, 22, 24, 23, 23, 23, 22, 22, 22, 20, 20, 21, 20, 20, 21, 21,
49, 49, 48, 49, 49, 49, 49, 48, 49, 49, 49, 50, 50, 50, 50, 49,
35, 38, 39, 39, 38, 38, 39, 39, 38, 39, 38, 38, 37, 38, 39, 37,
245, 245, 245, 244, 244, 242, 242, 243, 245, 246, 246, 246, 246, 246, 245, 245,
213, 214, 216, 217, 217, 217, 218, 217, 217, 217, 217, 216, 217, 217, 217, 217,
221, 221, 222, 221, 219, 221, 221, 222, 222, 220, 222, 222, 222, 222, 223, 223,
216, 217, 217, 217, 218, 218, 218, 217, 217, 217, 218, 218, 218, 217, 218, 218,
213, 214, 214, 213, 213, 213, 213, 211, 214, 214, 214, 213, 210, 209, 211, 212,

the closer my hand is, the lower the value should be.
at the begining, I put my hand closer and closer, but the value "jump" from 179 to 216, and rejump in lower values (22,23...).
And after that rejump in higher values but my hand was still quite close to the receptor...

other strange thing: the max value is 255 and not 1023! even when I link to +5V. So this IC is not just a "router", it process the data somehow?

Hi,
Check when you have 5V into the 4067, what voltage is coming out and into A0?

Tom... :slight_smile:

when I put 5V in the 4067, the output react correctly.

But sorry it was my mistake for the 255, I made an array of byte...
I put a short in place, and now the values are in the good range.

I checked with a multimeter, all the sensors output are good and react correctly without noise when I put an object in front of it, with little variation depending on the sensor but that's OK for me... on the other hand, the readings by the arduino are still quite dirty, and even if my multimeter says "2.3V", the values picked by the arduino are quite differents.
I kind of feel that the values changes when I put my hand in front of the sensor, but it is very very noisy.

I bought another 4067, the same as this tutorial, the 74HC4067: Tutorial – 74HC4067 16-Channel Analog Multiplexer Demultiplexer | tronixstuff.com

I will test with this one.

thanks for the help.

You're using a 47K pullup resistor for the phototransistor. I believe Atmel specifies that the source impedance for an analog input should be <10K.

If you need to keep the 47K to retain the sensitivity, then try taking several readings and discarding the first.

You could also try adding a 0.1µF cap from the signal to GND, which will effectively reduce the source impedance for the analog input.

Hi,
Try using only one sensor as you did last time for me, but this time, only have the IR transmitting LED for that sensor as the only one ON.
Turn the others LEDs OFF please.
Can you post a picture of how you have physically setup your array?

Thanks..... Tom.... :slight_smile:

Did you connect Gnd also to Arduino?

You have no decoupling caps. You need a 0.1 ceramic between the power and ground of the multiplexer chip.

Have you set D4 - D7 as outputs (without affecting D0 & D1)?

thanks you all, it's working now.

the order of the controlPins was false (wrong order in the control wires...), I remade the order properly in the array (I checked all the adresses one by one to be sure), put a delay(1) just after every adress changes of the Mux in the for loop, and it's good now!
but I will probably put a 104 ceramic on the Mux, just in case.

thanks all!