(4051) Analog Multiplexer / DeMultiplexer library update

Okay that makes more sense now.

So if you have 2 4051s and you want 16 inputs then there's pretty much only one way to attack this.

You have the 4051s separately and run each of them into a separate analog pin (if you want an analog reading on your button. If it's a push button then you can just attach it to a digital pin for reading as you're only checking on off statement).

Now you'll need to look at your data sheet for your pin out but essentially you end up with Vcc and GND, Vee you attach to ground as well.

Then you have what might be marked as INH or E - This is the input/output selector pin. This is USUALLY attached to ground if you want the 4051 to work as an INPUT. If you push it HIGH then it will work as an output instead.

Beyond that you'll have two sets of pins, one set of three usually marked as A, B and C and then another set marked 0 - 7.

The 0-8 are your inputs or outputs (depending on whether you set INH LOW or HIGH). They are what you connect your buttons to. I'm just going to call these pins inputs from now on for simplicity.

The 3 control pins are used to select which of the 8 inputs you want to switch to and then measure. These work as three binary values which collectively work together to create a 3 bit integer (providing the range 0-7).

Your data sheet will have the details of which pin represents each bit.

The last pin we haven't looked at yet, usually called Z or Out/In, is the one you connect to the arduino that you are going to read.

So once you know what your IC looks like, grounded the pins that need grounding, added +5v to the Vcc and wired up your buttons, and put the Z line to an Arduino input, you just need to set up your A, B, C pins to three digital outs on the Arduino to control the switching.

At this point I'll point you to this example in my library: arduino-analog-multiplexer/MuxPot.ino at master · ajfisher/arduino-analog-multiplexer · GitHub which uses potentiometers on three inputs to demonstrate connecting and reading the value.

Replace the pots with buttons, and make it 8 instead of 3 and you've pretty much got what you need. The library I built makes this dead simple and means you don't need to worry about the bit manipulation etc.

Really the key is to check your data sheet to orient yourself to the pin out and then use the concepts I've described above.

Cheers
Andrew