New to Multiplexing. Need help understanding why I can't get it to work. (4076)

Description of my problem:

I have an analog 4076 Multiplexer I am trying to use to read 16 buttons through one pin on my Arduino Uno. However, after trying a couple different multiplexer libraries as well as pre-written code, all of my attempts have been unsuccessful.

Given that I can seem to get anything working, I have tried to strip down both my code and my circuits in order to identify what is causing my problem. My problem being that I cannot seem to read or write any signal through my multiplexer.

Description of attachments:

I have attached pictures of two different circuits and their respective codes.

-The first is just a test circuit reading a button through an analog pin, which seems to work just fine.

-The second is of my multiplexer setup and its code, which just tries to read the same button through one port in the multiplexer.

Verbal description of my circuit and code:

My understanding of multiplexing is that you use digital pins (4 in my case) to select different channels in order to direct the signal through the multiplexer. In my example code, I wrote LOW to all pins, indicating that the multiplexer should direct the signal through to the Y0 channel. I have also connected the EN pin to ground. The resulting readings from the analog port A0 is consistently 'HIGH', with no change occurring when I press the button. Even unplugging the multiplexer entirely seems to not change the resulting readings. It is as if my multiplexer wasn't even plugged in at all.

Analog Button Read Circuit:

Analog Button Read Code:

Analog Button Read Serial Monitor Results:

Schematic of the Multiplexer Circuit:

Picture of the Multiplexer Circuit:

Multiplexer Code. Designed to read button status from Y0 channel of the multiplexer via the A0 analog port:

Serial Monitor Results of the aforementioned code and circuit. This is the only reading displayed, despite any presses of the button:

Edit:

SOLVED: The multiplexer wasn't plugged into the breadboard properly.

Properly Connected Multiplexer:

Analog Read Serial Monitor Results:

Digital Read Serial Monitor Results:

End Note:

-As I am new to a lot of this, I guess I just assumed I had to use analogRead for analog pins but I've now opted for using digitalRead in order to read the status of the button through the multiplexer. A much cleaner solution than trying to decode the erratic tendencies of the results I was getting with analogRead.

Besides verifying the switch is good, beware the switch orientation:

tactile switch.PNG

You could also need some connection to the switch, like a pullup

tactile switch.PNG

I think the switch is connected ok. Using diagonally opposite pins means the orientation does not matter.

But I agree about using a pull-up resistor. Either a 10K between Z and 5V, or set A0 mode to INPUT_PULLUP in your sketch. Without this pull-up, A0 is "floating" and could read anything.

Please post your sketches and pictures here on the forum according to the forum guide in the sticky post. We should not need to visit external sites full of ads and so on.

If you really do have a 4076 then that's your problem, a 4076 is not a multiplexer. Maybe it's just a typo and you actually have a 4067, which is a 16 input multiplexer.

Have you tried measuring the voltage at Y0 while pressing and releasing the button to make sure changes between 5V and 0V, then repeat the same test at Z, to see the change?

As Paul says; post your code in code tags. I find it hard to believe that some code to test how a multiplexer works could be too big to fit here.

All right, if I have to do the work for you ...

Picture of single button read test.


Code to test one button.

OK, so one button works - you have used INPUT_PULLUP but why on earth would you use analogRead?


Fritzing (ptui! :astonished: ) schematic of multiplexer test circuit.


Photograph of multiplexer test circuit, poorly taken with flash, should be taken outside in full daylight but not in sun. Poor pictures make it very difficult to verify you have the jumper wires inserted in the correct sockets - black on black.

Nevertheless it is of course, a 4067. Should by preference be a 74HC4067 but better than nothing. :sunglasses:

Now your code for this:

Expand

This should have been posted as code in your first post since it is not too big but cannot be recovered from an image.

And no, I cannot spot the problem.

Or - maybe I can - There is something bizarrely wrong with the pin stock holding the multiplexer module to the breadboard. Have you actually connected the pins to the module? It appears you have not. :roll_eyes:

Paul__B:
There is something bizarrely wrong with the pin stock holding the multiplexer module to the breadboard. Have you actually connected the pins to the module?

I agree. If the headers had been correctly soldered to the module, we would not see the yellow plastic insulators, they would be underneath the module. All we would see is the top of the metal pins, each with a shiny cone of solder around them.

This isn't the same module, but it shows the idea:
images (1).jpg

images (1).jpg

Hey thanks for the feedback! Turns out I totally had my multiplexer plugged in incorrectly and that was the source of my problem. I knew it had to be something silly I was overlooking.

Also, I can see why you were perplexed as to why I was using analogRead. After fixing my multiplexer and testing out the code with both analogRead and digitalRead, it has become clear that digitalRead has much better and cleaner results (duh, its only a 1 and a 0) for reading the button through the multiplexer. I suppose I assumed since it was an analog-16-channel multiplexer that I would have to use analogRead.

Thanks for all the help! :slight_smile:

I also went back and reformatted my post to include the pictures. Sorry about that. Still learning the ropes.

cdubbsr:
Hey thanks for the feedback! Turns out I totally had my multiplexer plugged in incorrectly and that was the source of my problem. I knew it had to be something silly I was overlooking.

It would appear that it was not soldered, and therefore not connected at all. How was it plugged in? :astonished: