loading

How to Build an Arduino Powered Chess Playing Robot

FeaturedContest WinnerContest Winner
Picture of How to Build an Arduino Powered Chess Playing Robot
DSC_7841.jpg
Judging by the sheer number of chess related Instructables, I think it's safe to say the community enjoys the game.  It can be difficult, however, to find someone who plays on the same level you do.  To solve this dilemma, and to increase my playing skills, I built this arduino powered chess playing robot.

The board works like any other xy table, with a few key differences.  First, the x axis has an extra servo attached to it, which raises and lowers a magnet.  The magnet is attracted to pieces on the chess board above, allowing them to move.  Second, embedded in the board are 64 magnetically activated reed switches, allowing the arduino to know the location of each piece. 

What I love about this project is its adaptability.  If you decide you're done with it as a chess board, it can instantly convert into a CNC mill by modifying a few pieces.  I'll talk more about this possibility at the end.

All in all, though I learned a lot from this project and had fun building it, the board was not as successful as I had hoped.  The magnets were way too powerful, so extra pieces would almost always drawn in when they shouldn't have. However, with a few thoughtful changes I think this could have been a better, more functional project.  Until I build another, better board, though, I think this Instructable still serves as a pretty good guide to make your own chess robot.
 
Remove these adsRemove these ads by Signing Up

Step 1: Parts and Materials

Picture of Parts and Materials
b.jpg
c.jpg
d.jpg
You may have many of the parts for this project already, but if you don't, the whole list costs ≈ $350, depending on where you get your parts from.  Many, many of them can be salvaged, so look to recycle before you buy!
  • 1 Arduino Uno or Diecimila
We'll be using this arduino to drive our stepper motors and servos.  You can pick these up just about anywhere online.  I got mine from Adafruit. $30
  • 1 Arduino Mega
This is the most expensive item in the project.  It'll be dealing with the inputs from each chess square to let the computer know where you've moved.  We're using the mega here due to its speed and number of inputs.  Adafruit $65
  • 1 Mux Shield
The mux shield (short for multiplexer) gives us even more inputs for our arduino mega.  We'll need 64 inputs in total, one for each square.  Sparkfun $25
  • Motor Shield
The motor shield will be controlling our stepper motors and servo.  You'll need to solder it together.  Adafruit $19.50
  • 1 Large chess board with pieces
This one is a little more self explanatory.  We want a large chess board here because the pieces need to be able to move in between each other with disrupting others.  Make sure you measure the diameter of the bottoms of the pieces.  We'll need that in a moment.  I'm not sure where mine is from, but you can pick them up from a flea market for a bargain.  The playable area of my board is 24".
  • 64 NO Reed Switches
Reed switches are magnetically activated switches.  They'll help us find the location of moved pieces.  NO stands for normally open, that is, the circuit is disconnected   Digikey ≈$30
  • 16 10K 1/4 Watt Resistors
These are the pull up resistors for the built in digital pins.  The mux shield, luckily, has integrated pull downs, so we don't need to worry about those. Digikey ≈ $2
  • Roughly 90 feet of 30AWG Wire

This is the hookup wire for all of our sensors. Radioshack ≈ $16
  • Neodymium Magnets to fit your pieces
This is where the measurements from the bottoms of your chess pieces come in handy.  You'll need disc magnets to fit underneath each piece.  For proper strength, they should be about 1/8" think.  A great source for these is K&J Magnetics.  ≈ $55
  • 1 Large Neodymium Magnet
This magnet will be attached to the XY table underneath the board, to move each piece around.  K&J Magnetics $19  Note: This was Waaaay too powerful.  It would draw in pieces it shouldn't have.  You'd be better off going with some smaller ceramic magnets, like you'd find at Staples or another office supply store.
  • 2 Pairs of 24" Drawer Bearings
The size of your bearings will depend on the playable area of your chess board.  These allow for the stepper motors to move back and forth underneath the board. Amazon ≈ $30
  • 2 Stepper Motors
Stepper motors can move in very precise increments.  In the late 90s they were in just about every piece of tech you could find.  The best place to get these are in old dot-matrix printers.  You can them at the flea market for next to nothing!
  • 2 Vex Rack and Gear Sets
The rack gears allow the stepper motors to travel on the drawer bearings.  See the Step 4 for a more detailed explanation.  Vex Store $40
  • 1 Standard Hobby Servo
This servo will be raising and lowering the powerful magnet below the board. You can find them at a hobby shop for ≈ $10, or Amazon ≈ $12
  • 1 2' x 2' Perf Board
The perf board is super thin and will be the mounting surface for all of our reed switches.  The price will vary greatly on this one, but I got mine from Home Depot for ≈ $5
  • 1 2' x 2' x 1/2" MDF Board
Similar to the perf board, I got this from Home Depot for  ≈ $5
  • Various lengths of scrap 1"x2" wood
This wood forms the bridge between the X-Axis drawer bearings.  Go behind any hardware store and you'll see dumpsters full of this stuff for totally free!
  • 5 Minute Epoxy
This stuff is a godsend.  It's used for just about everything in this project, from mounting motors to attaching the rack gears.  I'm in love -- and  I picked mine up from Radio Shack for $3
  • 1 Wood Saw
You probably already have this one, but if you don't, I picked mine up at Ace Hardware for $10 a couple of years ago.

Step 2: Design and Code Explanation

Picture of Design and Code Explanation
XY2.jpg
base10.png
base8.png
That parts list is a bit scary if you're not sure what everything is going to do, so here's how many of the pieces will be used.

You can see in the images below that each stepper motor can move freely about its axis thanks to the drawer bearings.  On the Y Axis, each rail is connected with the wooden structure, so that the X Axis may sit atop it. Also on the X Axis is the servo that raises and lowers the powerful magnet, so that it may position itself before moving pieces.

Feel free to download the sketchup file and mess around if you're not sure of anything.

Another interesting element of this design is how to code talks with the arduino and motors.  We need to address each square as a set of coordinates so that we may find slope and distance, however the traditional method of labeling squares A1, A2, etc. doesn't work particularly well in code.  Standard (x,y) coordinates are much friendlier.  Those coordinates, however, need to be in the form of a single number.  What I ended up doing is assigning each square to a number, as you can see in image #3.  Those numbers don't really work as coordinates on an 8x8 chess board, however, because we use a base 10 number system.

To solve that issue, we take the base 10 number of each square and convert it to base 8 using the modulus operator in C.  27, for example, is 33 in base 8, with the first digit being the x coordinate and the second the y.  If you count over three squares and up three squares, voila! You end up on square 27.  This converted coordinate system ends up looking like image #4.


XY.skp347 KB

Step 3: Mounting the Drawer Bearings (Y Axis)

Picture of Mounting the Drawer Bearings (Y Axis)
f.jpg
g.jpg
The drawer bearings are what allow the axes to move in their respective direction.  The mounting instructions may vary slightly depending on the brand, but usually it's as simple as driving a couple of screws.

The only reason I've made this its own step is that aligning the bearings perfectly is key.  Should you fail to do this, and they both point slightly outwards, they'll stop at some arbitrary point and refuse to move once you connect them.  Save yourself a lot of trouble and use something you know is square as a reference for alignment.  The corner of a book is perfect.

Step 4: Building the Motor Mount (Y Axis)

Picture of Building the Motor Mount (Y Axis)
IMG_0260.jpg
IMG_0263.jpg
IMG_0266.jpg
The stepper motors we'll be using have fantastic torque, but are circular.  This means mounting them to our bearings later on will be nearly impossible, unless we build a square mount.  To build one, find a hole saw with a similar diameter to your motor.  You'll want to use a drill press rather than a portable drill for this, so I borrowed my school's.

Once you've cut the hole, slice the circle in half to get two mounts.  This chipped the tips of my semicircle, so I used some 220 grit sandpaper to clean up the edge.

My steppers came with mounting screw holes, which line up well with the wooden frame.  I used the smallest screws I could find.  Mine fit so well that it wasn't necessary, but you might consider adding a bit of epoxy to strengthen the bond.

Step 5: Installing the Rack Gears (Y Axis)

Picture of Installing the Rack Gears (Y Axis)
y.jpg
z.jpg
q.jpg
r.jpg
DSC_7729.JPG
The rack gears are what allow the motor to latch onto a surface to pull itself along.  Your physics teacher probably defined them as a way to convert rotational energy to linear.

Again, we use the epoxy to attach the gears onto the MDF.  In addition to heavily applying epoxy to the board itself, make sure some is spread on the side of the drawer bearing, that way there is stability in two dimensions.  Do your best to prevent epoxy from getting in places it shouldn't be -- you may gum up your motor.

It works out that the rack gears extend a little bit off of each end.  This is a good thing -- it enables the gear to travel the full length of the board without running off.  The stepper motor will be offset just enough that if the gears only covered the board's length the whole motor assembly would get stuck at one end.

Also install the circular gears onto your motor at this time.  Mine had a set-screw, but you may wish to use some JB weld to hold your gear in place.  If you go that route, the joint needs to fully cure before you try to use it, or you risk the gear popping off!

Step 6: Wiring and Mounting the Motor (Y Axis)

The leads that come attached to the stepper motors are very short.  Because the Arduino is mounted off the board, the wires need to be at least the length of one side.  That made mine about 2' 5" long.  Heat shrink tubing is your friend here -- we're using enough power that it might arc if you're not careful.

If your stepper motor has 5 wires, you're all set.  If there are 6, however, it means you have to connect your center taps.  Jason Babcock has a great tutorial on reverse-engineering your motors.  In my case, however, the wires were the same color.

After extending the wires, the center taps go into the center of one of your motor hubs.  The wires from one coil go to one terminal on the motor shield, and from the other coil to the other terminal.  At this time we also hook up our 24v 1A power supply to the motor shield.  If you get the polarity wrong on this, your motor shield is toast.

After trimming the motor mounting block to about 4 inches, it's time to attach it to our bearings.  Mix up the epoxy, and liberally apply it to the area of the bearing the block will touch.

Also, if you have any pets, be sure to animal-proof the room you're working in.  Cats seem to have an affinity for knocking over things that are drying.

Step 7: Mounting the Crossbars (X Axis)

Picture of Mounting the Crossbars (X Axis)
DSC_7748.JPG
DSC_7758.JPG
Atop the Y Axis sits a cross-bar which will hold the X Axis.  To do this, we mount another block on the opposite Y Axis bearing.  This will across from the motor mounting block.

Then we cut two 2' lengths of 1"x2" wood and mount them to the blocks with wood screws.  Make sure these screws are in tight, or the bearings might not move at the same time.  You might consider adding some wood-glue to lock them more tightly in place.  While these cross bars need to be large enough to support our X Axis bearing, we want to use the least amount possible to avoid unnecessary weight.  If the entire X assembly weighs too much, our Y Axis stepper motor won't have enough torque to move efficiently, or, if it's really heavy, at all.

Test that your bearings move evenly with each other.  The crossbars should be as close to perpendicular with the bearings as possible.

Step 8: Mounting the Drawer Bearing and Rack Gears (X Axis)

Picture of Mounting the Drawer Bearing and Rack Gears (X Axis)
DSC_7761.JPG
DSC_7773.JPG
We are going to mount this drawer bearing in the same way we did on the Y Axis.  Using the included mounting screws, attach it to the crossbars, making sure to leave room on one side for the rack gears.

This time, however, we have some options for mounting the rack gears.  We can choose which side to mount them on.  This is going to vary depending on how your motors are placed on their blocks.  Once you've decided where to place them, though, they are glued in exactly the same way as on the Y Axis.  Extend the rack gears slightly off of each end to make sure we have full travel on our steppers.

Again, make sure to try and keep any glue out of the sliding mechanism.  If you do allow some glue to enter the mechanism, all is not lost.  Fortunately for us, drawer bearings come in pairs, so we'll have one left over anyway.  Mount it to the same screw holes and you're set!  Just don't do it again! :)

Step 9: Attaching the Magnet to the Servo (X Axis)

Picture of Attaching the Magnet to the Servo (X Axis)
DSC_7787.jpg
DSC_7790.jpg
DSC_7794.jpg
The chess board needs to be able to move into position and grab a piece.  To accomplish this, we achieve a pseudo Z Axis by mounting a magnet to a servo on top of the X Axis.  Use epoxy to attach your large magnet to a small piece of wood (Jenga blocks work wonderfully).  Once that has dried, attach the wooden block to your servo.  

If you're concerned about the torque of your servo, you might consider adding a counterweight to make lifting the magnet less difficult.

At this time you should also extend the leads on your servo motor.  Do this the same way you did for your stepper, going one wire at a time and covering it with heat-shrink tubing or electrical tape.

Epoxy bonds best when there is a significant weight holding the two bonding surfaces together.  Keep in mind that while 5 minute epoxy dries in 5 minutes, it may not cure for several hours.

Step 10: Wiring and Mounting the Motor (X Axis)

Picture of Wiring and Mounting the Motor (X Axis)
DSC_7823.jpg
We mount and wire our X Axis motor as we did earlier, however we also need to attach our servo assembly.  We need to mount the servo as closely to our motor as we can get without interfering with the gearing.  This way we are guaranteed to have maximum coverage underneath the board.

Using a piece of wire or cotton swab, carefully apply epoxy to the block where you've decided to attach your servo.  If you aren't careful, some epoxy may end up on your stepper motor, rendering it useless.  It's a real pain to clear mixed epoxy out of motors, so it's worth the extra time it will take.  Firmly hold your servo in place for several seconds, and leave it clamped to dry.

Once your servo is mounted, we can attach the motor block to our bearings.  Being cautious as to not get glue in the sliding mechanism and, like earlier, apply the epoxy to the exposed metal the block will touch.

After that is dry, wire the motor like you did before, extending each lead.  This time, however, we'll connect it to the other motor terminal.  Congratulations, the XY Table is done!

Step 11: Wiring the Sensors

Each chess piece has a magnet embedded in its bottom, which makes detecting location really simple.  Underneath each square is a magnetic reed switch hooked up to our Arduino mega.  When a change is detected, the Arduino spits out the coordinates.

Pull up resistors make sure we don't get false readings from our sensors.  48 of the 64 switches won't need pull up resistors, because the multiplexer has them built in.  Unfortunately, we still have to solder 64 sensors.  To make this go a lot faster, tin your wires before you try to solder them to the switches.  Basically, just add solder to the wire alone before soldering with it. Label each switch with tape as it is completed to avoid a wiring nightmare later!

Hook up each switch to the Arduino as you go along.  The multiplexer has a built in ground next to each input, which is really convenient.

To wire the pullup resistors to the built in pins, connect one resistor end to 5V and one to the pin you're using.  Then, skipping the resistor, connect one end of your switch to ground and the other directly to your pin.

Find a comfortable chair, because this is going to take a while!

Step 12: Place the Magnets

Picture of Place the Magnets
DSC_7829.JPG
Each chess piece has a magnet embedded in its bottom to trigger the reed switches.  The only thing that's important here is that every piece on one side of the board has one polarity (like North), and every piece on the other side has the opposite (like south).  If you'd only like the computer to play one color, make sure it is the opposite of the magnet attached to the servo, so they will attract each other.

Other than that, though, this only takes a few minutes.

Step 13: Code, Final Assembly + Reflection

Picture of Code, Final Assembly + Reflection
DSC_7838.JPG
DSC_7840.JPG
The code for this project is surprisingly simple.  It takes the reading from the chess board out of terminal, plugs it into a chess algorithm already built into Mac OS X (look inside the Chess.app bundle), and spits out the coordinates back into the Arduino window with some fancy applescript.  The algorithm is a fantastic open source project called Sjeng, meaning this will work cross platform as well.

The final assembly for this project is fairly simple.  Find something to hold up your sensor grid, and lay that down.  Next, place your chess board and pieces on top.  You're done!  Run the software and give it a whirl.

If you ever get bored of chess, it's really easy to make this into a CNC project.  Replace that magnet with an X-Acto knife, flip the entire assembly upside down, and you have a stencil cutter!  Replace that X-Acto knife with a pencil and you have a draw-bot.  Modify the servo to activate a dremel and you have a CNC machine!  The possibilities are, please excuse the cliché, endless!

Reflection

In retrospect, there are changes I would make to this project if I revisit it. The magnets were waaaaaay too powerful, and would always pieces in that they shouldn't have.  When all the pieces snap together, this would render a game unplayable. The mounting of the gears should be greatly improved;  a few times the gears would pop off due to the heating of the stepper motors.  Proper mounting with screws would fix this.  Second, the board gets (fairly severely) out of calibration after a few moves, presumably due to skipped steps, and must be manually moved back to the origin to avoid misalignment.  Some potentiometers allowing the board to know its absolute position would fix this.  The rails, despite my best efforts, were misaligned, making the last couple rows of squares impossible for the stepper motors, causing them to skip steps and click loudly (bigger steppers would be better).  Sometimes the motors would stop altogether and wouldn't be able to make it in those rear squares.  Aligning the rails better would fix this. Often what would happen was that when the large magnet flipped over, a whole bunch of pieces would get drawn towards it (and it's a real pain to place all the magnets back inside the pieces if you haven't attached them). Ceramic magnets like the ones people stick to whiteboards might work better.  Finally, the code could definitely be streamlined further; I completed this project when I was very new to C and Arduino.

Thoughts on the Epilog Challenge

It's kind of a funny feeling when as a maker you have something that can, well, build other things. An epilog laser would help me in some way with literally everything I make.  With this laser I would, on a regular basis, cut solder stencils for surface mount work, make more elegant housings for my projects, and engrave logos onto personal laptops and cell phones.  As a student, it would provide me with a small extra source of income from engraving the gadgets of others.  Rapid prototyping circuit boards would allow me to take my work to the next level, rather than having to spend several hours etching a PCB just to find out one trace is routed incorrectly.  This laser, combined with help from the awesome community here on Instructables, would help me so much in my pursuit of a career in engineering, my ultimate goal.

I'll leave it up to the merit of my Instructable, though, to decide whether I deserve this laser, not the list of sappy thing's I'd do with it. :D Instructables and Epilog have done something great here, and the projects created by this fantastic contest will set a standard of quality for years to come.


I hope you've enjoyed reading about this project as much as I enjoyed making it.  Make sure to leave a comment if this has inspired you to build anything, I'd love to see what you've made!
1-40 of 59Next »
willyana4 months ago

Hi, i didnt found any video of this working, can you show us?

GiovanniT5 months ago

I am sorry for the stupid question but I am a beginner.

I would like to know were to find this algorithm in the Mac,and how to set up this to recive the imputs from the arduino.

rishilaish5 months ago

why skp file is in tmp format? Cannot download.

What's the accuracy on this?

DJCPU9 months ago
Can you contact me i can't make one but I'd like to buy one 229-412-8125 Gus
paquiton961 year ago

What if it has to move a horse over another pieces?

Lol! Good question!

awesome!!!!!!!!!!!!!!!!!!!!!

tomshirvo1 year ago

That's what people can use VHS tapes for these days. Cool project!!

If at all possible, you really shouldn't cut of jacks like that. Get a socket that fits the plug and use that, its just a better idea because then it will be easier to take it apart to make something else with, or even just to fix it.
NoseyNick4 years ago
Not bad! Personally I'd have saved the cost of the Mega by adding a shift register to the uno though.

Instead of 64 seperate inputs, you'd need 8 row wires, 8 column wires... 2 arduino outputs go to "clock" and "ser" on a shift reg (EG 74HC595) so you can choose to power one row at a time. Connect each square as row-reedsw-diode-col. Then the 8 cols go to 8 arduino inputs... or even through the other type of shift register if you need to reduce that down to 3 pins.

64 diodes and a shift register are much cheaper than a mega, and your wiring is likely to be neater too. Really cool project though, thanks for sharing! Love the XY construction, makes me wonder why this technique isn't used for CNC projects (much? at all?) :-)
Come to think of it... Look up Charlieplexing. This technique is usually used to light LEDs, but can be used for input too - EG https://en.wikipedia.org/wiki/Charlieplexing#Input_data_multiplexing . Your reed switches would need diodes in series (but diodes are REALLY cheap), and the code is more complicated (funky tristate stuff (ab)using IO lines for rows AND columns), but you could read all 8x8 (in fact 8x9) with 9 I/O lines, so an Arduino Uno ought to be plenty.

... oh, and use an electromagnet instead of a Z-axis servo :-)
maxjus (author)  NoseyNick4 years ago
That's a really excellent suggestion! I'll try that should I ever revisit this project. Yeah, I've always wondered why more CNC tables don't use this gearing technique.
akadi2 years ago
wouldn't it have been easier if you just built a robotic arm that can move the pieces and used the same program with the arduino board you could have also used magnets and the other pieces wouldn't get attracted too because the robotic arm is more precise
Ramssess942 years ago
Where i can download the code of XY??
in my computer out korean letters
Vogonslurp2 years ago
Hi Max
I love your project, it's just such a good idea!
I have a question regarding the coding though. What changes have to be made to Sjeng in order for it to function? I'm more of a java person, but I do know a little C. I have Windows, so unfortunately no Mac.
Thanks!
MrRoboBrain2 years ago
Nice project man, good work and idea! My advice for one of the changes would be to change your magnet with electro magnet.
something12 years ago
I was wondering how does the arduino get instructions from the chess engine and how does it send a move please tell me I need to know.
will36752 years ago
Really cool project but what does it do with a piece like the knight that might have to jump over other pieces?
Hello! thats a great project man ! i'm a 4th year mechatronics engineer and i wonder if i can program this arduino on PC cause i don't have mac ! plaz help me with this :) thank you anyway
crabbypup2 years ago
for everyone still looking for the sjeng application, you can find it here: http://sjeng.org/indexold.html

also, where is the code to program the two arduinos? and are the arduinos attached just by USB, or are they wired together first? the 'ible isn't really clear on this. thanks!
diy_bloke3 years ago
impressive. I am not gona build this, but I have been thinking about a raised 4x4 ft plant bed in which individual plants would be watered via a similar setup. Would not be moving chesspieces but a nozzle. This has given me some idea's
amirhemat3 years ago
hello
i am
amir hemat
iran
plz add me
tanx
cheukhengc3 years ago
If the horse need to jump out on the first step, how will it move?
tjesse3 years ago
Can't wait to see what you will do next. How is the laser?
maxjus (author)  tjesse3 years ago
It's pretty fantastic!
but what if your chess set is wood?
mickey12vt4 years ago
That's awesome.
tinker2344 years ago
hey at think geek . com they are selling harry poter chess set be cool to make a program so i can say e4 to ee5 something like that
WizenedEE4 years ago
Why don't use the integrated pull up resistors in the arduino (a digitialwrite on a pin does it) instead of using external ones?

Also, couldn't you use just one arduino? The mux shield can go on top of the motor shield. They both use pin 2, but you can cut the trace and rewire it, and that costs way less than $30. Even better, you could add a fourth multiplexer and use just one uno.

This project is really cool, though.
scottinnh4 years ago
Congrats on a well done and ambitious project.

When will you have the upgraded version which allows 2 player over the Internet? [grin]
sponges4 years ago
Congrats! :)
maxjus (author)  sponges4 years ago
Thanks! I ordered some ferric chloride for my business cards :)
MBurg4 years ago
When a piece is captured do you just remove it from the board? Also can you just lift up your piece and place it on the spot you want to move to or must you drag it on the board? I am guessing the size of the chess pieces matters you want them small enough to move by other pieces. I hope I try this out, also would like to add support to be able to play against people online and be able to use the board just like one of those DGT eboards they don't move the pieces for you tho at what they want for them they should.
grenadier4 years ago
:'(
ben_k4 years ago
Congratulations on winning! Have fun with the laser cutter.
ynze ben_k4 years ago
Congrats! Great idea and I'ble. Have fun laser cutting!
Congradulations...Enjoy your prize....
Awesome! I'd love to see a longer game though! Who ever said you couldn't play chess by yourself!?!? =D
Purple Guy4 years ago
Great, but it would be nice to see some more moves?
1-40 of 59Next »