Arduino Forum

Using Arduino => General Electronics => Topic started by: exoro on Feb 25, 2016, 11:17 pm

Title: Simple 4051 analog multiplexing circuit not being so simple... Help appreciated
Post by: exoro on Feb 25, 2016, 11:17 pm
I'm trying to build this project (http://thecodeinn.blogspot.com/2013/10/arduino-and-multiplexing.html).

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?
Title: Re: Simple 4051 analog multiplexing circuit not being so simple... Help appreciated
Post by: Grumpy_Mike on Feb 25, 2016, 11:21 pm
Quote
I'm using 100k potentiometers if that matters.
Yes it matters, use a 10K one.

Quote
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.
Title: Re: Simple 4051 analog multiplexing circuit not being so simple... Help appreciated
Post by: exoro on Feb 25, 2016, 11:28 pm
Before I purchase a set of 10ks, is there any way I can get the 100ks to work?
Title: Re: Simple 4051 analog multiplexing circuit not being so simple... Help appreciated
Post by: Grumpy_Mike on Feb 25, 2016, 11:41 pm
You can try reading the same channel twice in a row and only using the second reading.
Title: Re: Simple 4051 analog multiplexing circuit not being so simple... Help appreciated
Post by: KeithRB on Feb 25, 2016, 11:43 pm
Use 10 in parallel.
Title: Re: Simple 4051 analog multiplexing circuit not being so simple... Help appreciated
Post by: Grumpy_Mike on Feb 25, 2016, 11:45 pm
Use 10 in parallel.
And watch them burn as the wiper for one is at one end and another wiper is at the other.  :)
Title: Re: Simple 4051 analog multiplexing circuit not being so simple... Help appreciated
Post by: Wawa on Feb 26, 2016, 03:09 am
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..
Title: Re: Simple 4051 analog multiplexing circuit not being so simple... Help appreciated
Post by: raschemmel on Feb 26, 2016, 06:10 pm
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 ?


Quote
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.
Title: Re: Simple 4051 analog multiplexing circuit not being so simple... Help appreciated
Post by: exoro on Feb 27, 2016, 09:26 pm
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.
Title: Re: Simple 4051 analog multiplexing circuit not being so simple... Help appreciated
Post by: Wawa on Feb 27, 2016, 09:41 pm
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..
Title: Re: Simple 4051 analog multiplexing circuit not being so simple... Help appreciated
Post by: MarkT on Feb 27, 2016, 09:45 pm
You clearly have noise somewhere, or have a weird power/ground setup.  We can't tell unless
you show us your setup in detail.
Title: Re: Simple 4051 analog multiplexing circuit not being so simple... Help appreciated
Post by: exoro on Feb 27, 2016, 10:17 pm
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!
Title: Re: Simple 4051 analog multiplexing circuit not being so simple... Help appreciated
Post by: raschemmel on Feb 27, 2016, 10:22 pm
Quote
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.
Title: Re: Simple 4051 analog multiplexing circuit not being so simple... Help appreciated
Post by: exoro on Feb 27, 2016, 10:28 pm
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.

(http://i.imgur.com/RUoYRAq.jpg)
Title: Re: Simple 4051 analog multiplexing circuit not being so simple... Help appreciated
Post by: raschemmel on Feb 27, 2016, 10:30 pm
You can remove the paper underneath and look at it so see if the metal clips are missing in that row.
Title: Re: Simple 4051 analog multiplexing circuit not being so simple... Help appreciated
Post by: Wawa on Feb 27, 2016, 11:47 pm
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..
Title: Re: Simple 4051 analog multiplexing circuit not being so simple... Help appreciated
Post by: exoro on Feb 27, 2016, 11:49 pm
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.
Title: Re: Simple 4051 analog multiplexing circuit not being so simple... Help appreciated
Post by: Grumpy_Mike on Feb 28, 2016, 12:02 am
Quote
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.
Title: Re: Simple 4051 analog multiplexing circuit not being so simple... Help appreciated
Post by: exoro on Feb 28, 2016, 12:04 am
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!