I want to use many (about 30) switches as inputs to my Arduino Uno. I've built a circuit using four 74LS30 (nine input NOR gates) to multiplex 15 switches down to 4 pins (16th state is when all switches are off, 0000) which works. However, expanding this to accept inputs from more switches will mean that the circuitry will get VERY complicated. It's not just a matter of adding another 74LS30, as all the inputs on the current ones are in use. I'm limited in the number of available pins on the Arduino that I can use, as I'm also using a MotorSheild to control a DC motor and some servos.

Basically, what I need is a 32 line to 5 line (binary) multiplexer.Is there an IC (or two) that will do this for me?

Basically, what I need is a 32 line to 5 line (binary) multiplexer.Is there an IC (or two) that will do this for me?

There is no one IC to do this but you can cascade a number of 4051s to give you any number of inputs.With each 4051 you get 8 inputs, so using 4 of them gives you 32 inputs going down to 4 outputs. You can feed those outputs into another 4051 to get one output. So five chips will do it.

Thanks for your reply. Looking at various circuit diags. it appears that I'll need 6 pins on the Arduino to select which switch I want to check and another pin for the input to the Arduino. Only one of the 30 switches will be on at any one time. They're magnetic reed switches to give positional information.

I'm thinking of making a second 4 * 74LS30 board and using the (4 bit binary) outputs of both these boards to input into a single 4051 so that I need only the control signals for one chip and one input line = 4 pins.

No to look at up to 32 inputs on one arduino input you only need 5 pins on the collection of 4051s. The number of inputs you can select is given by two to the power n, where n is the number of select lines you need to use. In your case four 4051s are connected to your inputs, those four outputs are connected into a second layer 4051. While this has three select lines as you only want to select one out of four you only need to wire up two of those select lines and ground the third. The select lines on the first layer of 4051s are common so that makes five lines in total.

How do you use one pin to select one of two chips, as both enables are active low? Taking that one pin low would enable both of them and taking it high would disable both of them. Or have I got it wrong?

Thanks for the info. I'm thinking of using 74HC4067Ns but I don't know if my local electronics store in London has them. Mail order will probably incur more shipping charges than the value of the parts

Mail order will probably incur more shipping charges than the value of the parts

Yes they are only £0.91 here:-http://uk.farnell.com/texas-instruments/cd74hc4067e/logic-mux-demux-analog-hs-24dip/dp/1740160The trick is to order other stuff to get you up to the free shipping total, which is about £25 or so here. Once you get into electronics you will find there is always stuff you want or need. Why they even sell Arduiunos and Raspberry Pis and lots of other stuff. It is a good excuse to get interesting things. You can justify it by saying to yourself, "well I had to get it to get me up to the free postage value so in effect it is free".