4051, Inputs & Outputs with 1 multiplexer?

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
helium
 
Posts: 40
Joined: Thu May 30, 2013 8:23 pm

4051, Inputs & Outputs with 1 multiplexer?

Post by helium »

Hi,

I'm working on a project which uses an Arduino Pro Mini, and I'm very limited in available pins.
The only available pins I have are D2, D3, A6, & A7.
I plan on using a 74HC4051 8-channel multiplexer to expand the number of analog inputs I can use. I plan on using D2, D3, and A6 as 'select' pins for the 4051, and A7 as the pin that the Arduino reads analog values from.
So far, so good.

But then I ran into a problem; I also wanted to have some outputs, so I wondered:
Since A7 can be used as both a digital output and an analog input, can I use the single 4051 to both read multiple analog inputs and output multiple digital outputs?
So I can have a few sensors and a few LEDs connected to a single 4051, and whenever the Arduino wants to access them, it just 'selects' the appropriate pin and sets A7 as either an input or an output depending on what's needed?

The only problem I think, is if I accidentally output to an analog input pin on the 4051. But could I just use a diode in series with the analog input line to avoid current going the wrong way?

Also, when I get ready to read/write to/from a 4051 pin, should I first set the Arduino A7 pin as an input/output, or first 'select' the pin to read/write from?

This is the basic schematic of what I want:
Old without diodes
Old without diodes
4051 Old.png (25.29 KiB) Viewed 975 times
This is the same one, but with diodes inline with the analog lines.
New with diodes inline
New with diodes inline
4051 New.png (24.21 KiB) Viewed 975 times
If I do use diodes, what kind should I use? I don't want to too noticeably disturb the analog values coming from the joysticks.

User avatar
zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: 4051, Inputs & Outputs with 1 multiplexer?

Post by zener »

I was really hoping someone else would answer this first! This could be a little bit complicated. There are hardware issues and software issues. Even if I make a list of things to do and you do them all it does not guarantee it will work. I think it is possible to do it but it could take some trial and error. Here are my observations and comments. Hopefully others will have something to add also:

1) You need to ground pin 6 of the 4051

2) The on resistance of the 4051 channels can be as high as 1K. So you can't put the LED current through there. You can transmit a high or low, but you need an additional stage to drive the LED such as a buffer or inverter. You need one that can sink or source whatever current you need for your LED's.

3) The diodes will likely cause you trouble. Instead, I would put the analog signal from the joysticks into a follower and then through some resistance (although the 4051 has resistance also.) I do not know what the current limit through the 4051 is per channel. This should provide some protection.

Software issues are another matter. I believe you can change the I/O pins from input to output on the fly but I am not positive about that.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”