Hello, I've bought a CD74HC4067 multiplexer for my project involving an array of photoresistors, but whenever I've tried to read an output I got almost identical values on all pins usually 2-4 numbers apart which constantly fluctuated between 300 and 330.
So I've decided to just make the simplest possible circuit to test the multiplexer shown on the image bellow which should output a simple 0 as the C0 pin is connected to the ground, but the board keeps reading the same values (also shown bellow).
I have no idea what's going on so I would love to get some thoughts from anyone more competent than me on what might be causing the problem.
Documentation for the exact multiplexer is here
On the input of the A/D is a capacitor that forms a sample and hold circuit. In front of that is a data selector, just like your 74HC4067.
When the sample and hold signal is switch to a new input, that input has to charge or discharge the capacitor to the new voltage. If that new input is not connected to anything or if the voltage is a high impedance source, then the capacitor will not get the right voltage on it, and so the reading will be the same or only slightly different.
One solution is to read each input twice and only use the second reading. This allows the voltage on the capacitor more time to charge up.
Grumpy_Mike:
When the sample and hold signal is switch to a new input, that input has to charge or discharge the capacitor to the new voltage. If that new input is not connected to anything or if the voltage is a high impedance source, then the capacitor will not get the right voltage on it, and so the reading will be the same or only slightly different.
Good point - except that he is only reading one input, only selecting one input, and it is supposedly connected to ground which I would generally term a "low impedance source".
My bet is that his wiring does not actually match that Fritzing diagram or that he failed the critical step of pre-testing all his Chinese-assembled Dupont wires.
Yes but as CrossRoads pointed out in reply #1 he did not declare the multiplexer select pins to be outputs, so he was not actually addressing the one input but any of the other floating inputs of his multiplexer.
When he comes on to actually using the multiplexer this is something he will need to know, or at least take account of.
The inputs of a multiplexer chip should never be left floating whether addressed or not.
Grumpy_Mike:
Yes but as CrossRoads pointed out in reply #1 he did not declare the multiplexer select pins to be outputs, so he was not actually addressing the one input but any of the other floating inputs of his multiplexer.
When he comes on to actually using the multiplexer this is something he will need to know, or at least take account of.
See #2!
Grumpy_Mike:
The inputs of a multiplexer chip should never be left floating whether addressed or not.
Paul__B:
That would suggest you do not want to have unconnected "analog" pins on the ATmega chip itself.
It would, but only if the circuit of the 74HC4067 was the same as the analogue multiplexer inside the ATmega chip. I suspect that as the Arduino's internal multiplexer is part of a configurable pin system, this mitigates against it. But as CrossRoads points out it is easily fixed if it proves a problem.
Grumpy_Mike:
I suspect that as the Arduino's internal multiplexer is part of a configurable pin system,
Another name for which is - a multiplexer!
Semantics!
OK, basically these are nothing more than an array of CMOS switches. A4 and A5 are of course, used in the I2C interface, so the effect of activity on this interface (or any other external input to the analog pins) would for what it is worth, arguably be a far greater risk of interference than a floating pin.
The two lowest elements for input functions are a multiplexer switch which is used to (selectively) disable inputs in sleep mode (to prevent pass-through currents due to floating or indeterminate inputs) and a direct connection to the analog multiplexer detailed in Figure 24-1 and Figure 24-8.
So a "configurable pin system" is in this case clearly just - a multiplexer (and a bit).