# 64 Magnetic Reed Switches under Chess Board

I am trying to make a chess playing robot and I am struggling with the sensors. I am putting a magnetic switch underneath each square of the board and a magnet in each chess piece to set it on/off. I have a Mux shield which gives me 64 pins so I can have a pin for each switch, but this leads to a lot of wiring which comes out very messy. Is there another way I could avoid having to use an input for each individual switch??

Just use a switch matrix. Typical circuit is here in this project:- http://www.thebox.myzen.co.uk/Hardware/Econo_Monome.html

You only need the switch part of this circuit not the LED bit.

Thanks for the reply. A PCB such as this (just found this) should work? And I can only assume this will take more complex programming in comparison to 64 individual pins?

A PCB such as this (just found this) should work?

Hard to tell with such low resolution. You do need the diodes on each matrix position.

And I can only assume this will take more complex programming in comparison to 64 individual pins?

Yes it will take about 7 lines of code as opposed to about 3 for individual switches.

Hi,

If you only want the reed switches in the matrix, you can do it with only 9 Arduino lines, by using a technique called charlieplexing. The wiring and sketch are a little bit more complex than a normal matrix, and you will still need those diodes Mike mentioned, but it does mean you can avoid using extra chips.

Let me know if you need a diagram.

Paul

Sorry I thought the picture would upload better.

I have heard of charlieplexing before but did not really understand it. If you could put up a diagram it would be very helpful.

Schematic attached below.

This is how you would scan the matrix. Initially all 9 lines would be set to INPUT_PULLUP. Then for each of 1 to 8 in turn, you would set that line to OUTPUT and LOW. Then read the other 8 lines. Then set the line back to INPUT_PULLUP.

Thanks Paul for your help. It might be a really stupid question, but in the schematic why do the switches change position on either side of the board? As in they attach to a different row??

Many apologies, I just realised I have drawn that schematic with every one of the 64 diodes pointing in the wrong direction!

So, imagine them all pointing the other way. Suppose we make line 4 OUTPUT and LOW. This enables us to read the 4th column of switches. If the top switch is closed, line 1 reads low. If it is open, line 1 reads HIGH because it is set to INPUT_PULLUP. If the bottom switch in the 4th column is closed, line 9 reads LOW. If you look at the 8 switches in the 4th column, the 1st, 2nd and 3rd are connected to lines 1, 2 and 3 and the 4th, 5th, 6th, 7th and 8th are connected to lines 5, 6, 7, 8 and 9. Similar logic applies to each of the columns.

Notice that we don’t bother to ever make line 9 LOW, because there is no 9th column of switches. However, if your project needs some other buttons for any reason (like buttons to start a new game or select a difficulty level, for example) you could add up to 8 more and make them part of the matrix, in a 9th column.

Does that help?

I just realised I have drawn that schematic with every one of the 64 diodes pointing in the wrong direction!

You sure that matters, the whole thing is symmetrical, it is just the way you drive it.

Grumpy_Mike: You sure that matters, the whole thing is symmetrical, it is just the way you drive it.

Yes I think so Mike... exactly the way I drew it, if line 4 is LOW, you would only be able to read 7 switches on the 4th row, on lines 1, 2, 3, 5, 6, 7, 8 but not 9). The matrix is not quite symmetrical.

You could make each line HIGH rather than LOW to read a column of 8 switches. That would work as I drew it, but you would need 9 external pull-down resistors.

but you would need 9 external pull-down resistors.

Or a processor with internal pull down resistors. If I may mention it the Raspberry Pi.

PaulRB: Many apologies, I just realised I have drawn that schematic with every one of the 64 diodes pointing in the wrong direction!

So, imagine them all pointing the other way.

Not a problem if you actually wired them the "wrong" way. Just swap rows for columns.

Hi guys, thanks again for all your help. Since I posted last I decided to swap the magnetic reed switches for hall effect sensors as they will be more accurate. Would I be correct in the schematic will be similar to the one given above but as well all the sensors will be connected by the ground pin and go to ground on my arduino?

Would this be a suitable circuit, the middle pin in each is ground and will connect to ground on my arduino and I will connect each column with jumper wires?

Sorry forgot to add the image.

paddymcd93: Would I be correct in the schematic will be similar to the one given above but as well all the sensors will be connected by the ground pin and go to ground on my arduino?

No, a hall effect sensor is not a switch. You need a new circuit, either a chain of 8 parallel load serial out shift registers, or a cascade of multiplexers.

I decided to swap the magnetic reed switches for hall effect sensors as they will be more accurate.

?? The two are just as accurate as each other. Maybe you don't mean the word accurate.

?? The two are just as accurate as each other. Maybe you don't mean the word accurate.

Yea sorry Mike what I meant was, with the reed switches there was a possibility that a different magnet could cause the switch to stay either on/off but with the hall effect sensor I could set the threshold so that only the magnet closest would change it. This is the understanding I took from talking about the two with people anyway.

I am going to make a 3x3 matrix and test the reed switches to see if they are suitable for the project. I will post again when I find out.

but with the hall effect sensor I could set the threshold so that only the magnet closest would change it.

OK you then need a different circuit if you are going to use an analogue hall sensor. The shift register will not cut it you need to use analogue multiplexers.

If you need to adjust the magnetic field so that is activates only one reed switch, you could try establishing a distance above the board that achieves that, then drill a hole into the chess pieces to that depth and embed the magnet in the hole. Plug the hole with filler..

Your hall sensor design is going to turn out twenty times more complicated than your original idea, and you know what they say about the simplest solution...