I'm trying to multiplex an analog input port on an Arduino Uno.
I've connected the input to 5V for testing stability of the reading. I've programmed a small routine that checks for consistency of the signal reading.
I'm using a breadboard of questionable quality.
The CD4051B Output is grounded via a 500k resistor, so that unconnected ports read 0.
If I read only port 4 for 30 seconds, it starts to read correctly and stable. If I start reading random ports (between 0 and 7), it reads correctly for about 10 seconds, then suddenly starts reading zero.
I've tried changing the pull-down resistor. It still goes to zero. I've tried removing the pull-down resistor. The value then starts reading randomly. I've also tried adding a 1uF capacitor. But it changes nothing.
I'm using digitalWrite on three pins to select the input port, and then waiting (delay) for 30ms before doing an analogRead on A0. I've experimented with various delay times, and 30ms seemed to improve things a lot when reading sequantially (0, 1, 2, 3...), but when reading randomly, it doesn't work at all.
I'm a bit lost to what the problem could be. I imagine it could be something with capacitance on the ports, but I have the impression that the multiplexer is actually supposed to support very fast switching?
I saw a comment on the 'arduino' board which said that "the for loop repeatedly cycles count from 0 to 7, so [selector pins] will average 2.5 V". Is this realistic? Wouldn't the digital pins be able to sink fast enough that the IC would mux correctly?
The IC has internal protection circuits. Is it possible that they are getting triggered? But this happens even with 1k resistor on Input 4.