Detecting the Presence of Magnetic Pieces on a Chessboard

I am working on a project that turns a standard chessboard into a MIDI instrument using Arduino for the sensing component. Currently I am using a 8x8 grid of reed switches, in which all of the reed switches are plugged in as digital inputs into an Arduino MEGA and the internal pullup resistor is used. I have added neodymium magnets to the bottom of the chess pieces so that when a piece is on top of one of the squares on a chessboard, the circuit is closed, output is HIGH and then something is trigger in the MIDI software.

I am seeing some issues with some of the squares not triggering consistently when pieces are placed on top. Any idea why this might be happening? I am considering switching to an 8x8 grid of hall effect sensors instead, but am unsure which sensor will perform better in consistently detecting presence of the magnetics. Any advice here? Is there another sensor I should be considering? I'm not the most experienced with sensors, but am more than happy to do my own research once I can get some guidance on where to start. Thanks!

I would guess the orientation of the magnet in some positions is not enough to magnetize the contacts of the reed switches.

The first thing I would do is test the reed switch vs magnet orientation. Start in 2D, meaning attach the reed switch to a piece of graph paper. Then by bringing the magnet in close to the reed, measure where the reed switched. Then rotate the magnet 90 deg and repeat. Then rotate the magnet in the Y plane repeat both the above.
Now rotate the reed switch 90 degrees. Repeat above.
You should be able to fine the optimum orientation.

Now try the reed on your board, put the chess piece at the edges of the position and see how close to the center it needs to be to work.

what about using photo resistors, just placing the chess piece would break the circuit.

1 Like

Sixty-four individual inputs?

@Paul_B Yes, 64 individual inputs, one for each square on a chessboard

@Paul_B is surprised because the more usual way to do this is by using a matrix. Only 8 inputs and 8 outputs would then be needed, and the wiring would be far simpler. It would also be necessary to place a small signal diode in series with each reed switch.

1 Like

That's right, a reed switch is sensitive to an axial field (along its axis), not a transverse field. How are the magnets oriented?

Neodymium magnets are very strong for their size, and reed switches are quite sensitive. Usually a small iron magnet is enough to trigger a reed switch from 10~20mm away. When you have more than one piece on the board, is it possible your magnets are affecting reeds other than the one they are directly above? Could the fields from other magnets be interacting and preventing some reeds from closing?

I would experiment with small, less powerful magnets.

Good thought.

Perhaps the OP can relate the incidences of not working with the existence of other pieces in the surrounding squares?

Using either reed switches or hall effect switches I would think about using a AVR243: Matrix Keyboard Decoder or similar where the chip itself is doing all the work. There is no shortage of AVR Libraries for use with Arduino. There are still chips available which were used for matrix decoding of the early PS2 keyboards. Anyway I am not saying to take this path, it is merely a suggestion. Most of these chips allow for multiple switch closures to as in many pieces on a chess board.


1 Like

@PaulRB is there any guidance or resources you know of that can help me get an understanding of the wiring scheme for this and how it might work programmatically? I am very new to creating matrices like this, so anything would be a great help

Thanks @Ron_Blain, I will look into this

In addition to detecting if a piece is present on a matrix the mere detection will not tell you which piece it actually is. That presents another problem which can get pretty complex solving. I don't have a solution off the top for that.


I think I would use a pcf8575 or perhaps 2x pcf8574 chips. Either would give you 8 row pins and 8 column pins for an 8x8 matrix, but only require 2x Arduino pins (SDA+SCL). You would need to wire a small diode such as 1n4148 in series with each reed switch. Alternatively you can use 16 digital pins on the Arduino if those are available. The sketch would need to scan each of the 8 columns in turn by pulling the column line high using INPUT_PULLUP mode, while the other columns are LOW. For each column in turn, the 8 rows can be read.

1 Like

Thanks so much @PaulRB. I'll look more into this based on your suggestion. seems like a good path forward

I don't think you would have that problem with hall effect switches.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.