Electronic – Is it possible to read a 10 by 10 switch matrix with 8 by 8 I/O pins

microcontrollermultiplexerswitches

I was asked this question on an interview: given 8 output pins and 8 input pins on a microcontroller, is it possible to read a 10 by 10 switch matrix without using multiplexor and demultiplexor chips?
I'm not sure it's possible…

Best Answer

I would do something like this:

schematic

simulate this circuit – Schematic created using CircuitLab

I use 7 of the outputs and 8 of the inputs to create a matrix of 56 crosspoints, and I put two switches at each crosspoint, for a total of 112 switches. The 8th output is used to control a set of pullup/pulldown resistors for the inputs.

Scan the array twice. The first time, set Out7 low, and pulse the other outputs high one at a time. Look for any inputs going high. This tells you whether the lower switch at each crosspoint is closed.

The second time, set Out7 high, and pulse the other outputs low one at a time. Look for any inputs going low. This tells you whether the upper switch at each crosspoint is closed.