Reading chess board with reed switches

I have this chess board and pieces with magnets on the bottom. My idea is to place a reed switch below each tile so that Arduino can detect movements by comparing boards before and after one movement.

How do I wire these reed switches to use as less IO pins as possible without using too much code (I need room for the chess logic)?

Gatis:
I have this chess board and pieces with magnets on the bottom. My idea is to place a reed switch below each tile so that Arduino can detect movements by comparing boards before and after one movement.

How do I wire these reed switches to use as less IO pins as possible without using too much code (I need room for the chess logic)?

A basic switch matrix (similar to what's used in the Keypad library) will give you a major reduction in I/O necessary. You'll still need 16 total wires to the chessboard, but provided you don't need a lot of additional I/O for other things it's do able. You could theoretically get it down to a single pin by using a form of serial encoding, but you'd need a non-trivial amount of logic circuitry between the chess board and the Arduino to achieve that.

A switch matrix like a Keypad wouldn't work as there would be more than piece at any given time.

Your could try using 8x 74HC165 8bit parallel to serial shift registers.
http://www.nxp.com/documents/data_sheet/74HC_HCT165.pdf

That would allow you to read in all 64 through just 3 pins (Clock, Data, Latch). The 165's can be daisy chained such that they all share the same clock and latch(PL) pins, and the serial out from one goes into the serial in of the next and so on until the 8th whose serial out goes into the arduino.

You would basically just have to pulse the latch pin, and then call shiftIn() 8 times to get all 64 pins.

I wrote "similar", not "exactly like" a keypad. Read the other link I included, especially the last section titled "Scanning Method". This method polls only one row at a time in quick succession, instead of all rows all the time. This allows the presence or absence of a piece to be accurately detected because the pin attachted to each column can only register the switch for the single row being polled.

Although admittedly your method works as well.

Even that polling method wouldn't account for certain combinations of presses:

r0----x---o---o
      |   |   |
      x---x---o
      |   |   |
      o---o---o
      |   |   |
      c0  c1  c2

In that diagram, an x means switch pressed (connected), o means unconnected. If you turn the row0 on (indicated by -----), then you will read 110 on the columns even though only the first switch on row0

Edit: Ahh, I see the diodes there, that would solve the problem.

I need room for the chess logic

On Arduino?

florinc:

I need room for the chess logic

On Arduino?

I think we're gonna need a bigger Arduino.

Arduino Mega R3 to the rescue!

It's pretty easy to "make" more pins on an Arduino but impossible to make more program memory. That's where Megas are nice.

A switch matrix plus two 165 will let me read whole board with 7 pins (3 for each 165 and 1 return pin).

I believe i can use two arduinos, 1 for reading board and controling an arm, and the other one for chess logic. We'll see.:slight_smile:

When you capture a piece your detection of movement is going to get a little goofy. It's no longer a simple problem of "piece removed from spot X, placed at spot Y". You would have to track whose turn it is or guarantee that the capture piece is always picked up first/second before the capturing piece is laid in its place.

Would be nice to be able to detect the black pieces from the white pieces. I had been looking for a hall sensor that could detect either of N, S, or none but could only find one in a 5sot-553 package (which is puny).

Oops, i actually meant a 595 for rows and a 165 for cols.

Do i need resistors or can i just attach rows and columns directly? How do i wire this thing?

If you are going down that route, you would need a diode for each reed switch - You don't need a resistor though.

Wire it so that you have:

Row ----|>|------o-o----Col

where --|>|-- is a diode, and o-o is a reed switch.

Do see a simpler solution?

I could use the 595 only and read 8 cols with 8 pins. That would simplify things a bit.

The issue is not the chips you are using. To do a simple matrix like that which requires more than one switch to be pressed (at most 32 are required for chess), you have to use diodes.

The alternative to using diodes for each switch is to use 8 47HC165s as suggested already.

Got it. So, if I go with 8 74HC165's, will I need resistors? Sorry, I've got ask since I know little about interfacing.

You may need pull up resistors on each of the 74HC165 inputs to ensure a known state when the reed switches are open (unless they are SPDT). But as resistors are 0.1pence a shot, cost isn't much of an issue, and space shouldn't be too bad.
Having said that you would still need a pullup resistor on each input of the 74HC165 for the other method as well for the same reason.

Hm... then sounds like the same amount of soldering trouble, but cheaper? I'm failing to see other benefits. I find soldering one reed switch to each diode and dealing with a single IC easier to do.

Thanks guys!

That would be fine. A 595 for the rows, and 8 arduino inputs for the columns (with the internal pullup resistors turned on).

As for price:
For the Matrix method
Diodes are about 5p each, and the 74hc595 is around 41p,

64*5p + 41p = £3.60

For the parallel to serial method
Resistors are about 0.25p each, 74hc165s are around 31p each.

831p + 640.25p = £2.64

As for soldering, that is really up to you.
Disadvantages of 2nd:

  • Have to solder 8 IC sockets rather than 1.
  • Have to solder 64 resistors.
  • You have 65 wires coming off the chess board rather than 17. Though if you put the electronics under the chess board this isn't an issue
    Advantages:
  • Dont have to solder 64 diodes
  • Dont have to solder the reed switches into a matrix of rows and columns. Instead all reed switches go to an input, and to GND.

Its neck and neck really. The only real difference is that the matrix uses 9 pins, while the parallel to serial method uses 3.
Either is fine

Have you seen this project for chess on an arduino
http://www.andreadrian.de/schach/#Selbstbau_Schachcomputer_SHAH
It is in German however.

I am trying to build a reed switch based chess board too. The scanning matrix aproach seems the most elegent solution.
However there is another way. (I think, I am new to Arduinio and may have missed something) Have you seen the Centipede Shield? See Centipede Shield V2 - Macetech Electronics Store. This is a shield with 64 pins that links to the Arduino boad using only a few pins. It also uses ribbon style connectors so that would simplify wiring. I assume you would wire one end of all the reed switches to ground and the other 64 to ribbon ends.
I assume that this would simplify processing as you would just need to scan for a change of state. (Would you still need a resistor or diode on the Reeds?)

If you looked for two move combinations, ie the "From" move followed by the "To" move, then the first move would always be a change of state from closed (Occupied square) to open (Piece gone). The second move would be to an empty square (Open to closed) unless its a capute then its to a closed and you can assume you will get a combination as the old piece is first lifted (closed to open) and the replaced (Open to closed). But all are on the same square and the final state is closed (occupied).

Any practical observations most welcome.

Max

It says about that shield.

Each I/O port corresponds to one MCP23017 IC.

So those chips have a built in pull up resistor so there is no need to add one to your reed switch.