How to have 256 bit input for micro-controllers like Arduino

arduinoinputswitches

I want to read 256 digital input, each of which is driven by a switch. I don't need to read state of all 256 switches more than 5 times a second (or may be even less). Multiple switches can be ON and OFF at any point in time. Obviously that's too much of wiring if I want to do it naively. So I want to do it as simply as possible without using loads of components or wires. My first thought is to have have 16X16 matrix with diodes. But that's too many diodes to add on to breadboard. So essentially I'm looking for some chip that will have 16+16 input pins that I can use it to feed in rows and columns of the matrix. That chip then will have (may be) 8 output pins that I can read somehow 16 times in succession to get all of 256 bits.

Questions I have…

  1. Does this kind of chip exists?
  2. Is this the best, cheapest and least messiest way to do it?
  3. Can it be done without chip with something like Arduno Mega that already have 56 bit input? I do want to reduce component count.
  4. Should I be using may be combination of chips which does only 8 rows and columns?

If you have any pointer to tutorial/guide to implement this, that had be great as well!

Best Answer

You've got the right idea with a diode array. I would recommend building a 16x16 matrix with the switches in series with 256 diodes + a pair of 16 bit I2C or SPI port expanders. Or you could use a pair each of 74165 and 74594 shift registers instead of the port expanders. Solder the diodes directly to the switches when you wire up the matrix, don't stick them on a bread board. You'll also need 16 pull-up or pull-down resistors.

Alternatively, you could daisy-chain 32 74165 shift registers and connect each switch to its own pin. You'll also need 256 pull-up or pull-down resistors.