Electronic – Checking how many inputs (reed switches) are active using minimal GPIO pins

microcontrollerraspberry piswitches

I've been a programmer, for a while, but I am new to the hardware aspect of things so I apologize for my lack of knowledge.

Just for a fun project to try to get better with hardware, I've decided to make an electronic chess board that records your moves.

I'm using reed switches for this project (they activate when they are near magnets) and I have a question.

In chess, there are 64 tiles which means I need 64 reed switches. I realized that connecting each reed switch to its own GPIO pin is inefficient and annoying considering that I'll need to get more pins (I'm using a RPi B+, so I have 27 pins to work with currently). I decided to check if anybody else has done what I'm trying to do using reed switches to see if they had any workarounds to this. Nobody has gone into too much detail about how they did it, but it appears that some people have gotten away with using 16 pins (one for each row/column).

All I really need to know is how many reed switches are activated on each row and column. I'm assuming there is a way of connecting everything in such a way where every activated switch adds to the voltage, and then I can read the voltage for each input. However, my RPi only allows me to see if there is a high or low voltage supplied to the input.

Any tips? Thanks!

Best Answer

As mentioned by others, it can be done using an 8x8 matrix. If you look at the internet you will find plenty of picture where they are used for keypads.

However those standard schematics are assuming you press only one key at a time. Some combination of two switches are also possible. But in your case need to be able to detect any combination if pressed switches.

I worked on that problem a while ago and found you can do it with an 8x8 matrix, but, as also mentioned by WhatRoughBeast, it requires a diode in series with each switch.

enter image description here