Introduction: 4x4 Demo of an Electronic Chessboard/ With Arduino Mega + RFID Reader + Hall-effect Sensors
I am Tahir Miriyev, 2018 graduate from Middle East Technical University, Ankara/ Turkey. I majored in Applied Mathematics, but I always loved making stuff, especially when it involved some handwork with electronics, design and programming. Thanks to a unique course on prototyping, offered at our department of Industrial Design, I got a chance to make something really interesting. The project can be treated as a Term Project, lasted for the duration of a whole semester (4 months). Students were assigned a task to find a creative approach to designing already existed products/demos and realize their ideas using Arduino microcontrollers and sensors. I was thinking about chess, and after doing some research on successful projects, I noticed that in previous projects makers basically used ready-set chess engines (where all moves of each figure were programmed in the core), along with Raspberry Pi, some MUX'es, LED's and reed switches. In my project, although, I decided to get rid of any external software in terms of a chess engine, and to find a creative solution for the Figure Recognition problem, using RFID reader, Hall-effect sensors and Arduino Mega.
Step 1: What Is a Figure Recognition Problem and How I Solved It
To put it simply, suppose you have a chessboard with a "brain"=microcontroller, and you have to make your board understand which figure you held in your hand and where you've placed it. This is the problem of Figure Recognition. Solution to this problem is trivial when you have a chess engine with all pieces standing on their initial positions on the board. Before I explain why it's so, let me make some remarks.
For those who are enthusiastic about how things work here, I have to make a clarification on why we need reed switches (or in my case, I used Hall-effect sensors): if you place a magnet under each piece and pick it up from a square on the board (assuming that there is a reed switch under every square) due to the existence/non existence of the magnetic field above the sensor, you can make your controller understand whether there is/is not a piece standing on the square. However, it still doesn't tell microcontroller anything about exactly which piece is standing on the square. It only tells that there is/not a piece on a square. At this point, we are face to face with a Figure Recognition problem, which can be solved using a chess engine, with all pieces placed on their initial positions when the chess game starts. This way microcontroller "knows" where every piece stands right from the beginning, with all addresses fixed in the memory. Nevertheless, this brings us a huge limitation: you can't select, let's say, any number of pieces and place them randomly anywhere on the board and start analyzing the game. You always have to start from the beginning, all pieces should be on the board originally, as this is the only way for the microcontroller to track their locations once you lifted a piece and placed on some other square. In essence, this was the problem I noticed and decided to work toward.
My solution was quite simple, although creative. I placed an RFID reader on the front side of a board. Meanwhile, I attached not only a magnet under pieces but also an RFID tag, with each piece having a unique ID. Hence, before you place a figure on any desired square, you can first hold the piece close to the RFID reader and let it read the ID, identify the piece, save it in the memory, and then you can place it wherever you want. Also, instead of using reed switches, in order to simplify the circuit design, I used hall-effect sensors, which work similarly, with the only difference of sending 0 or 1 to a microcontroller as a digital data, which signifies "there is" or "there is not" any piece on the square, respectively. I added LED's as well (unfortunately not of the same color, didn't have ones), so that when you lift the piece, all square locations, where a lifted piece could be placed, will light on. Think of it as an educational practice for chess learners:)
Lastly, I would like to note that despite the fact I used several techniques, the project remains simple and understandable, not deeply worked out or over complicated. I didn't have enough time to proceed with 8x8 chessboard (also because 64 hall-effect sensors are costly in Turkey, I covered all expenses related to the projec), that's why I did 4x4 demo version with only two pieces tested: Pawn and Queen. Instead of using a chess engine, I wrote a source code for Arduino, which generates everything you'll see in the video below.
Step 2: How Things Work
Before we pass to the step-by-step explanation of how the project was done, I think it would be better to watch an illustrative video and get some intuitive idea on what I am talking about.
Note #1: one of the red LED's (first in the row/ from left to right) burnt out, never mind.
Note #2: although widely used, from my experience I can say that the RFID Technology is not the best idea to use in DIY applications (of course if you have alternatives). Before everything worked, I did many trials with placing chess pieces close to the reader and waiting until it correctly reads the ID. Serial port should be set up for that because the way RFID reader reads the ID is just a headache. One should try by himself/herself in order to understand the issue. If you need more assistance, please mail me ( email@example.com) or add on skype (tahir.miriyev9r1), so that we can schedule a conversation and discuss things in details, I will explain everything thoroughly.
Step 3: Tools and Components
Here is the list of all the tools I used for the project:
- Breadboard (x1)
- Omnidirectional A1126LUA-T (IC-1126 SW OMNI 3-SIP ALLEGRO) Hall effect sensors (x16)
- Basic 5 mm LEDs (x16)
- Jumper wires
- 125 kHz RFID Reader and Antenna (x1)
- Arduino Mega (x1)
- RFID 3M Tags (x2)
- Glossy paper
- short Planks (wooden)
- Acrylic paint (dark green and creme) x2
- Thin cardboard
- 10 mm round magnets (x2)
- Pawn and Queen pieces
- Soldering iron and soldering materials
Step 4: Schematics (Fritzing)
Schematics are a little bit complicated, I know, but the idea should be clear. It was the first time I used Fritzing (highly recommended by the way), probably connections could be drawn more accurately. Anyway, I noted down everything inside the schematics.
Note: I couldn't find the exact model of RDIF Reader among components in the database of Fritzing. The model I used is 125Khz RFID module - UART. You can find tutorials on Youtube about how to set this module with Arduino.
Step 5: Process
Time to explain how things were made. Please follow the step-by-step description:
1. Take a 21x21 cm cardboard, as well as some extra cardboard to cut and glue the walls of the upper part of the board, in order to make 16 squares with A B C D 1 2 3 4 enumerated. Since cardboard is thin, you can stick 16 hall-effect sensors into each square, with 3 legs each and 16 LED's with 2 legs each.
2. After you set components, you will need to do some soldering, to solder legs of Hall-effect sensors and LED's to jumper wires. At this point, I would recommend selecting colored wires in a smart way, so that you won't get confused with the + and - legs of LED's, also VCC, GND and PIN legs of Hall-effect sensors. Of course, one might print a PCB with sensors and even WS2812 type of LED's already soldered, but I decided to keep the project simple and do some more "handwork". At this point, all you have to do is to prepare cords and sensors, on later stages following from Fritzing scheme you can see where you should attach the end of each wire. Shortly, some of them will go directly to the PINs on the Arduino Mega (there is enough of them on the Arduino), others to the breadboard and all GNDs can be soldered to a single piece of cord(making common ground) which later on should be connected to the GND on the Arduino board. One important note here: Hall effect sensors are OMNIDIRECTIONAL, which means it doesn't matter which pole of a magnet will be held close to the sensor, it will send 0 data while there is some magnetic field nearby and 1 when there is not, namely, magnet is away (further than lets say 5 sm) from the sensor.
3. Prepare similar 21x21 cm cardboard and fix the Arduino Mega and a long breadboard onto it. You can also cut 4 walls of any desired height from cardboard again, and glue them vertically with those two layers of 21x21 cm square boards. Then follow Fritzing Schematics to set things up. You can also set the RFID reader after you're done with LEDs and Hall-effect sensors.
4. Test whether all LEDs and sensors work, by sending signals using basic codes. Don't avoid this step as it will let you test out whether everything works properly and pass to further construction of the board.
5. Prepare Pawn and Queen, with two magnets of a 10 cm radius attached below, as well as round RFID tags. Later on, you'll need to read IDs of those tags from Serial Screen on Arduino IDE.
6. If everything works great, you may start the main code and try things out!
7 (optional) . You may do some artistic work with wood which will give your demo a more natural view. That's up to your will and imagination.
Step 6: Some Photos and Videos From Different Stages
Step 7: Source Code
Now, when we are done with a prototype, we are ready to bring it to life with the Arduino code below. I tried to leave as many comments as I could, in order to make the process of code analysis understandable. To be honest, the logic might seem a bit complex from the first sight, but if you dig deeper into the logic of the code, it will look more comprehensive.
Note: Similar to the real chessboard, I abstractly numerated squares as A1, A2, A3, A4, B1, ..., C1, ... ,D1,.., D4. However, in the code, it's not practical to use this notation. Therefore I used arrays and represented squares as 00, 01, 02, 03,10,11,12,13,..., 32,33 respectively.
Thank you for your attention! Test everything and be free to write in the comments about any kind of mistakes I missed, improvements, suggestions etc. Looking forward to hearing some opinions about the project.If you need any kind of assistance with the project, mail me ( firstname.lastname@example.org) or add on skype (tahir.miriyev9r1), so that we can schedule a conversation and discuss things in details. Best of luck!