Big Button Matrix

Hey Guys,

As a part of a bigger project, me and a mate are building a button matrix, using two 4051 multiplexers. We run through the rows and collumns, send power in on one side and see where it comes out on the other.

Arduino Code & Fritzing Layout:

As a test we built a 2 by 2 grid, and tried writing expandable code.
Enlarging it to a 25 button grid (or bigger) is just a case of redefining some variables and connecting some new buttons.

So far the plan.
We used the example code for the 4051 IC found on the playground,
( and modified it to meet these plans.

But it doesn’t work.
That’s about all I can say about it now - tomorrow we’ll take a closer look, but as far as we can say, it’s all wired up and programmed correctly.

Problem is that the output from the Arduino seems to be total bogus.
Care to take a look at it and tell us where we made the big obvious mistake?


A quick perusal of the code suggests that some changes should be made. For instance:

  pinMode(inputBinPin1, OUTPUT);    // s0
  pinMode(inputBinPin2, OUTPUT);    // s1
  pinMode(inputBinPin3, OUTPUT);    // s2

Are the pins input or output? I suspect that input should be changed to column.

  for (count=0; count<rowCount; count++) {
    for(countCol=0; countCol<colCount; countCol++) 

I would change count to rowIndex and countCol to colIndex, to make it clear(er) that one refers to rows while the other refers to columns.

I don’t think that the delay after the digitalRead is doing you any favors.

In a multiplexing scheme, you have to be switching which button is energized very quickly, so that you can tell when it is being pressed. The delay means that pressing and releasing the button in row 2, column 2 can happen while you are looking to see if the button in row 1, column 1 is being pressed, and you’d miss the button press.

Fritzing blue screens on me, so I can’t look at your schematic.

I made some updates today. The name of the variables should make more sense now. Still totally broken. We get a return value of "1" for every button in the grid, makes no sense.

We get a return value of "1" for every button in the grid, makes no sense.

What do you mean by a return value? There are no function calls being made, so nothing is returning a value.

Ey Guys, Thanks for the help so far, we integrated some of your suggestions. In the last code it was just a stupid typo that made everything go haywire.

Good good good, we're on track again.