Controlling 64 buttons with Arduino

Hi, i need some help creating a circuit that allows me to read 64 button inputs with Arduino.

I have to be able to read multiple buttons beeing pressed at the same time.

I thought of creating a 8x8 button matrix but my buttons use 4 pins and i dont really know how to wire them into a matrix properly.

also ghosting would be an issue when using an 8x8 matrix.

I thought about using diodes to prevent it.

I have both 74HC595 aswell as 74HC165 available.

Any help would be appreciated

Using Arduino Leonardo / pro micro

thank you :smiley:

If you can have multiple buttons pressed at the same time, use a few port extenders and give them all a dedicated port.

To expand on the post of wvmarle, the MCP23017 (I2C) or MCP23S17 (SPI) port expanders have 16 I/O pins. 4 of them for 64 inputs. They also can generate an interrupt on pin change and have internal pullups that can be enabled.

Your buttons use 4 pins, huh? Are they going to be individually illuminated?

No, its the type of button where 2 pins are always connected to each other, if you press it. all 4 pins get connected.

So, just don't connect the other two...

If I solder 5 wires to each side of a button, do you call it a 10 wire button?

8x8 matrix can be done :slight_smile: Depending on the physical arrangement of the buttons this can be simple. And if you want to be able to use more then one button at the same time, add diodes :slight_smile:

I'd like to see these odd buttons or a link to where you got them

Here is a link to a picture of the button

Is there someone who can show me how to create a matrix with them? and where to put the diodes?

I question your understanding of how the button works. A simple google search would answer your matrix question and I hope you aren't disregarding those plans because you think you need a diagram for "4 pin" buttons.

Do you have a multimeter?

See here.

Here's a method using 74HC165, pullup resistors to create High outputs when no button is pressed, and DIODE-AND for an interrupt.
When an interrupt is seen from Any button being pressed, use SPI to read in all 8 shift registers and then act on the data.
The internal pullup for the interrupt may need some outside help depending on how things are wired up.

// interrupt or PCINT received?
digitalWrite (ssPin, LOW);
digitalWrite (ssPin, HIGH); // captures the level of all the inputs
for (x=0; x<8; x=x+1){
inputArray[x] = SPI.transfer(0); // send out dummy byte on MOSI while read real data on MISO
}
// now act on the 8 bytes somehow
for (x=0; x<8; x=x+1){
if (inputArray[x] !=0xFF){
// one or more buttons was pressed, do something
}
else {
// stop doing something
}

Maybe do a continual scan of the interrupt pin (instead of an interrupt) if you want to keep repeating an action (sound output?) while a button is pressed. Lots of ways to react to the button data that comes in.