Simple 4051 analog multiplexing circuit not being so simple... Help appreciated

I'm trying to build this project.

This project is supposed to cycle through each analog input, output each signal individually to the A0 pin of the Arduino, and then Serial.print the value of each analog input.

I can't seem to get it working after many tweaks and tries.

What happens is that as the code cycles through the analog inputs of the 4051, each input gets an arbitrary number. If I connect a single potentiometer to the 4051 and ONLY check the single input it is on, it works fine. But when I introduce another potentiometer I immediately start having problems again.

I'm using 100k potentiometers if that matters. I'm also using the CD74HC4051E version. In the tutorial, the M74HC4051B1 version is used. I don't believe there is a difference between them, is there?

If there is a difference between the two 4051 chips, how can I change my circuit to allow for it?

I'm using 100k potentiometers if that matters.

Yes it matters, use a 10K one.

If there is a difference between the two 4051 chips,

Not one that will give you problems.

Note all the inputs must be connected to something, do not let them float.

Before I purchase a set of 10ks, is there any way I can get the 100ks to work?

You can try reading the same channel twice in a row and only using the second reading.

Use 10 in parallel.

KeithRB:
Use 10 in parallel.

And watch them burn as the wiper for one is at one end and another wiper is at the other. :slight_smile:

exoro:
Before I purchase a set of 10ks, is there any way I can get the 100ks to work?

Use 100n caps from each mux input to ground, one for each pot (no cap at the output of the mux).
When the mux switches to the relevant input, the Arduino sees the low impedance of the cap instead of the high impedance of the pot.
Now you can use any pot value, even >1Megohm.
Reading the analogue input twice (or more), and discarding the first read is always wise.
Maybe also wise to ground any unused mux inputs, and not select them in your code.
Leo..

There's nothing wrong with the circuit. You are connecting something wrong. Draw a schematic of how you are connecting the voltages to the inputs of the 4051.

Post a photo of YOUR circuit, drawn based on your actual circuit. Show you pot connections to the MUX inputs.

Are you aware that the addressing of the mux (S1,S2,S3) is binary and input 1 is 000, input 2 is 001 , input 3 is 011
where "000" = s0=0,s1=0,s2=0
"001" = s0=1,s1=0, s2 =0
"011" = s0=1,s1 = 1, s2 = 0

Are you aware of that ?

Instead of having to read each signal individually, we can send a number, in binary, to the multiplexer over 3 digital pins (3 bit binary number, depending on the high/low state of these three pins), then, the multiplexer will redirect the signals it gets from the potentiometer we want to the common pin, where we can finally read it.

I got the 10k pots in the mail today and it still does the exact same thing:(

I've also tried connecting 8 pots to every single mux input. I'm still getting weird numbers.

The last thing I tried was grounding all mux inputs except for mux input y5. When I look at the serial monitor, I'm getting interesting results. y1 and y5 are outputting the same exact value even though y1 is grounded!

Would the 100n capacitor trick still work in this case? Also, would reading the analog pin twice or more help? I tried that by repeating analogRead(0) but it didn't seem to work.

Time to post a picture of YOUR setup, and the code you're using now.
100n caps is not a "trick" but a "must" if you're working with impedances >10k.
Leo..

You clearly have noise somewhere, or have a weird power/ground setup. We can't tell unless
you show us your setup in detail.

YES! Got it working. Thank you all for helping out. I appreciate it greatly. The most important problem that I didn't even realize was that there was a row of pins on my breadboard that was completely dead. After I moved the 4051, it started working!

YES! Got it working. Thank you all for helping out. I appreciate it greatly. The most important problem that I didn't even realize was that there was a row of pins on my breadboard that was completely dead. After I moved the 4051, it started working!

Depending on which breadboard type you purchase, some of them have TWO sections on the same side, which MOST people jumper together (one jumper for blue, one jumper for red).
Evidently, you have one of those breadboards. the smaller ones have continutiy all the way across.
This falls under the category "Learning how to use a breadboard".
There is nothing wrong with your breadboard. You just don't have the jumpers installed, like everyone else does.

It's not even that surprisingly. I have a breadboard similar to the one above, but twice the length. The row (or I guess column depending on how you're looking at it) doesn't complete a circuit almost like there's no metal below. Then again, I did by the breadboard for next to nothing on Aliexpress.

You can remove the paper underneath and look at it so see if the metal clips are missing in that row.

exoro:
I have a breadboard similar to the one above, but twice the length. The row (or I guess column depending on how you're looking at it) doesn't complete a circuit almost like there's no metal below.

Yes, there are "double breadboards" with four red lines and four blue lines.
Common problem. That's why it's always wise to post a picture of YOUR setup.
Leo..

Like I said, I appreciate all of you answering.

My last question is why do you recommend a 10k pot instead of a 100k. I swapped out to the 100k and it works fine. Sorry if I'm not understanding the technical reason behind it.

My last question is why do you recommend a 10k pot instead of a 100k.

Because that is what is recommended in the data sheet.

When a channel is changed or the input voltage changes if the impedance is too high then there is not enough time to charge up the sample and hold capacitor on the front of the A/D.

Grumpy_Mike:
Because that is what is recommended in the data sheet.

When a channel is changed or the input voltage changes if the impedance is too high then there is not enough time to charge up the sample and hold capacitor on the front of the A/D.

Thank you!