4051 button Matrix

I'm looking to read the status of at least 25 buttons. I have read the 4051 tutorial and have one chip working successfully for 8 switches. I have each switch wired to the y0 - y7 with a 10K resistor and 5v with the other side. It's working great.

It looks like i can use the second example with two 4051's in an 8 * 8 matrix, but I'm not understanding how this one works. I'm only going to use digital inputs (switches).

Does anyone have an example of how to implement this one? Sorry if this is a newbie question.

Thanks in advance,


You would use one 4051 to scan columns and the 2nd 4051 to scan rows just like any standard matrix keypad. Each column is linked and each row is linked for the matrix.

Then you set the common IN/OUT 4051 columns to a digital input pin, set the 2nd common IN/OUT 4051 rows to a digital output pin.

The program would switch on a row, scan all 8 columns for a HIGH and tell if one or more is pressed, then move to the next row and scan.

I'm surprised that using the 74165 (parallel in, serial out shift register) isn't used more often for reading inputs.

Thanks for the reply. So when you set the column you want to HIGH, you just loop through the rows (the 4051 as a multiplexer) to determine which ones have been pressed.

The wiring diagram is not clear to me. You mentioned that you hook up the common out (Z) to a digital input pin and another to a digital output pin. The picture has one going to 5V and the digital in pin and the other one going to ground??

Does everything else still get hooked up as follows?

?Z ----- common input/output (connected to Arduino Input/Output)
?E ----- enable input (active LOW) (connected to ground (gnd))
?Vee — negative supply voltage (connected to ground (gnd))
?gnd — ground (0 V)
?S0-S2 - select inputs (connected to three arduino digitalOut Pins)
?y0-y7 - independent inputs/outputs
?Vcc — positive supply voltage (5v)

Thanks again for all the help.

Rob, it has been awhile, but if you are still working on this, let me explain how I have done it regards to the confusing point: you have two 4051s one has the z connected to a digital input pin on the Arduino, the other has the z connected to a stable state (either pullup or pulldown). You set the digital input pin that the first 4051 has it's z connected to as pulled up or down opposite the stable state of the z on 4051 #2. As the Arduino loops through reading the digital input pin, it will see a change only on each switch that is depressed. All others will read as the pullup at z #1.