Arduino Powered Chess Playing Robot

Wonder if anybody here could help me figure out how the wiring of this project has been done. I guess if I got atleast a schematic diagram for this project, I can be able to make this project work (I wish :.) . I got a resource from the internet but I'm a newbie and I still got to learn more. It would be a good start if you could help me out. I'm trying to make a chess playing robot. For the chess sensory board, I need 64 reed switches for each squares of the board. The opponent will be the robot itself and it will move the pieces using motors. I'm having a hard time in how can I be able to connect everything. I guess it would be better posting the link for further understanding. http://www.instructables.com/id/How-to-Build-an-Arduino-Powered-Chess-Playing-Robo/?ALLSTEPS

this is the program for the chess sensory board

#include <SoftwareSerial.h>

//Give convenient names to the control pins

#define CONTROL0 5

#define CONTROL1 4

#define CONTROL2 3

#define CONTROL3 2

#define rxPin 10

#define txPin 11

//Create arrays for data from the the MUXs

//See the Arduino Array Reference: http://www.arduino.cc/en/Reference/Array

int mux0array[16];

int mux1array[16];

int mux2array[16];

int digitalpins[16];

int mux0arraycheck[16];

int mux1arraycheck[16];

int mux2arraycheck[16];

int digitalpinscheck[16];

int descrepicount = 0;

char * squares[] = {"A1","A2","A3","A4","A5","A6","A7","A8","B1","B2","B3","B4","B5","B6","B7","B8","C1","C2","C3","C4","C5","C6","C7","C8","D1","D2","D3","D4","D5","D6","D7","D8","E1","E2","E3","E4","E5","E6","E7","E8","F1","F2","F3","F4","F5","F6","F7","F8","G1","G2","G3","G4","G5","G6","G7","G8","H1","H2","H3","H4","H5","H6","H7","H8"};

int lastprinted;

SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);

void setup()

{

//Set MUX control pins to output

pinMode(CONTROL0, OUTPUT);

pinMode(CONTROL1, OUTPUT);

pinMode(CONTROL2, OUTPUT);

pinMode(CONTROL3, OUTPUT);

for(int i=23; i < 39; i++){

pinMode(i, INPUT);

}

//Open the serial port at 9600 bps

Serial.begin(9600);

Serial.println("Startup");

//Set analog pins to digital input

pinMode(A0, INPUT);

pinMode(A1, INPUT);

pinMode(A2, INPUT);

//Turn on pullup resistors

digitalWrite(A0, HIGH);

digitalWrite(A1, HIGH);

digitalWrite(A2, HIGH);

pinMode(rxPin, INPUT);

pinMode(txPin, OUTPUT);

/*for(int i = 0; i < 16; i++){

digitalpins[i] = 1;

digitalpinscheck[i] = 1;

}*/

}

void loop()

{

for (int i=0; i<16; i++)

{

//The following 4 commands set the correct logic for the control pins to select the desired input

//See the Arduino Bitwise AND Reference: http://www.arduino.cc/en/Reference/BitwiseAnd

//See the Aruino Bitshift Reference: http://www.arduino.cc/en/Reference/Bitshift

digitalWrite(CONTROL0, (i&15)>>3);

digitalWrite(CONTROL1, (i&7)>>2);

digitalWrite(CONTROL2, (i&3)>>1);

digitalWrite(CONTROL3, (i&1));

//Read and store the input

//Since internal pullup is on, the pin goes low on changing, so the value needs to be flipped from 0 to 1 (!)

mux0array[i] = !digitalRead(A0);

}

//This for loop is used to scroll through the SECOND multiplexer

for (int i=0; i<16; i++)

{

digitalWrite(CONTROL0, (i&15)>>3);

digitalWrite(CONTROL1, (i&7)>>2);

digitalWrite(CONTROL2, (i&3)>>1);

digitalWrite(CONTROL3, (i&1));

mux1array[i] = !digitalRead(A1);

}

//This for loop is used to scroll through the THIRD multiplexer

for (int i=0; i<16; i++)

{

digitalWrite(CONTROL0, (i&15)>>3);

digitalWrite(CONTROL1, (i&7)>>2);

digitalWrite(CONTROL2, (i&3)>>1);

digitalWrite(CONTROL3, (i&1));

mux2array[i] = !digitalRead(A2);

}

for (int b = 0; b < 16; b++){

digitalpins[b] = digitalRead(b + 23);

}

//delay(1000); //Wait for the computer to move so we don't detect any false input from the other magnets

//it adds 12 seconds to startup time but that doesn't really matter... we're setting the board up anyway :)

//sets the array to digitalreads of built in mega pins 23 - 39

//This for loop is used to scroll through and store the 16 inputs on the FIRST multiplexer

for (int i=0; i<16; i++)

{

//The following 4 commands set the correct logic for the control pins to select the desired input

//See the Arduino Bitwise AND Reference: http://www.arduino.cc/en/Reference/BitwiseAnd

//See the Aruino Bitshift Reference: http://www.arduino.cc/en/Reference/Bitshift

digitalWrite(CONTROL0, (i&15)>>3);

digitalWrite(CONTROL1, (i&7)>>2);

digitalWrite(CONTROL2, (i&3)>>1);

digitalWrite(CONTROL3, (i&1));

//Read and store the input

//Since internal pullup is on, the pin goes low on changing, so the value needs to be flipped from 0 to 1 (!)

mux0array[i] = !digitalRead(A0);

}

//This for loop is used to scroll through the SECOND multiplexer

for (int i=0; i<16; i++)

{

digitalWrite(CONTROL0, (i&15)>>3);

digitalWrite(CONTROL1, (i&7)>>2);

digitalWrite(CONTROL2, (i&3)>>1);

digitalWrite(CONTROL3, (i&1));

mux1array[i] = !digitalRead(A1);

}

//This for loop is used to scroll through the THIRD multiplexer

for (int i=0; i<16; i++)

{

digitalWrite(CONTROL0, (i&15)>>3);

digitalWrite(CONTROL1, (i&7)>>2);

digitalWrite(CONTROL2, (i&3)>>1);

digitalWrite(CONTROL3, (i&1));

mux2array[i] = !digitalRead(A2);

}

////////////Check if anything has changed...

for (int b = 0; b < 16; b++){

if(digitalpinscheck[b] != digitalpins[b]){

if(lastprinted != b || descrepicount == 0){

Serial.print((squares[b]));

lastprinted = b;

descrepicount = descrepicount + 1;

}

if(descrepicount >= 2){

Serial.println();

descrepicount = 0;

}

}

}

for (int b = 0; b < 16; b++){

if(mux0arraycheck[b] != mux0array[b]){

if(lastprinted != b || descrepicount == 0){

Serial.print((squares[b + 16]));

lastprinted = b;

descrepicount = descrepicount + 1;

}

if(descrepicount >= 2){

Serial.println();

descrepicount = 0;

}

}

}

for (int b = 0; b < 16; b++){

if(mux1arraycheck[b] != mux1array[b]){

if(lastprinted != b || descrepicount == 0){

Serial.print((squares[b + 32]));

lastprinted = b;

descrepicount = descrepicount + 1;

}

if(descrepicount >= 2){

Serial.println();

descrepicount = 0;

}

}

}

for (int b = 0; b < 16; b++){

if(mux2arraycheck[b] != mux2array[b]){

if(lastprinted != b || descrepicount == 0){

Serial.print((squares[b + 48]));

lastprinted = b;

descrepicount = descrepicount + 1;

}

if(descrepicount >= 2){

Serial.println();

descrepicount = 0;

}

}

}

////////////////////////////////////////////////

for (int b = 0; b < 16; b++){

digitalpinscheck[b] = digitalpins[b];

}

for (int b = 0; b < 16; b++){

mux2arraycheck[b] = mux2array[b];

}

for (int b = 0; b < 16; b++){

mux1arraycheck[b] = mux1array[b];

}

for (int b = 0; b < 16; b++){

mux0arraycheck[b] = mux0array[b];

}

//////////////////////////////////////////////

}

/*

//DEBUG

//The following lines are for printing out results of the internal pins

Serial.print("internal pins: ");

for (int i=0; i<16; i++)

{

Serial.print(digitalpins[i]);

Serial.print(",");

}

Serial.println(); //line feed

//The following lines are for printing out results of array0

Serial.print("mux0array: ");

for (int i=0; i<16; i++)

{

Serial.print(mux0array[i]);

Serial.print(",");

Serial.print(mux0array[i]);

Serial.print(",");

}

Serial.println(); //line feed

//The following lines are for printing out results of array1

Serial.print("mux1array: ");

for (int i=0; i<16; i++)

{

Serial.print(mux1array[i]);

Serial.print(",");

Serial.print(mux1array[i]);

Serial.print(",");

}

Serial.println();

//The following lines are for printing out results of array2

Serial.print("mux2array: ");

for (int i=0; i<16; i++)

{

Serial.print(mux2array[i]);

Serial.print(",");

Serial.print(mux2array[i]);

Serial.print(",");

}

Serial.println();

delay(1000);

}

*/

Please chip in. Any help would be highly appreciated. Thank you. God Speed. :slight_smile:

and this is for the code for controlling the motors

/*

Chess XY Table by mJusticz

http://instructables.com/member/mjusticz

Feel free to modify this code to your liking, but, should you distribute this software, credit is appreciated

board layout:

7 15 23 31 39 47 55 63

6 14 22 30 38 46 54 62

5 13 21 29 37 45 53 61

4 12 20 28 36 44 52 60

3 11 19 27 35 43 51 59

2 10 18 26 34 42 50 58

1 9 17 25 33 41 49 57

0 8 16 24 32 40 48 56

these numbers are converted to base 8 which gives us some coordinates

*/

#include <AFMotor.h>

#include <Servo.h>

#include <String.h>

const float PINUMBER = 3.14159;

const float GEARDIAMETER = 1.2; //Gear diameter in inches

const float STEPSPERREV = 48; //However many steps per revolution your stepper motors support. For a 7.5 degree/step motor it's 48

const float BOARDSIDE = 24; //playable area of your chess board in inches

float circumference = (GEARDIAMETER * PINUMBER);

float stepsExact = ((BOARDSIDE / circumference) * STEPSPERREV); //Stores the exact, decimal value number of steps

int stepsforlength = stepsExact; //Rounds to a useful number of steps. Margin of error is 7.5 degrees (depending on stepper), so no big deal if its a little off

int stepsforsquare = (stepsforlength/8); //However many steps there are per square

int changey;

int changex;

int byteReceived = 0;

String laststringcoordinate = "";

String stringcoordinate = "";// stores coordinates as a string rather than a number Eg. A3

int lastintcoordinate, intcoordinate; //this stores our coordinates together in one glob that's easy to search. We then split it up

int lastxcoordinate, lastycoordinate;

int xcoordinate, ycoordinate;

char * squares[] = {"a1","a2","a3","a4","a5","a6","a7","a8","b1","b2","b3","b4","b5","b6","b7","b8","c1","c2","c3","c4","c5","c6","c7","c8","d1","d2","d3","d4","d5","d6","d7","d8","e1","e2","e3","e4","e5","e6","e7","e8","f1","f2","f3","f4","f5","f6","f7","f8","g1","g2","g3","g4","g5","g6","g7","g8","h1","h2","h3","h4","h5","h6","h7","h8","\0"};

AF_Stepper xaxis(STEPSPERREV, 2); //set up our motors

AF_Stepper yaxis(STEPSPERREV, 1);

Servo magnetservo;

boolean upordown;

void setup(){

Serial.begin(115200); //begins our connection for debug

magnetservo.attach(9); //Servo_2 on the motor shield

xaxis.setSpeed(15); //sets stepper speed to 75rpm. You may need to adjust this a little if you're having trouble

yaxis.setSpeed(15);

magnetservo.write(175);

}

void loop(){

if(Serial.available() > 0){

for(int i = 0; i < 2; i++){ //until we have two digits...

byteReceived = Serial.read(); //read the serial port - remember, it comes one digit at a time

laststringcoordinate = laststringcoordinate + byte(byteReceived); //append it to our last string coordinate

//delay(10); //wait for the buffer to fill

}

for(int i = 0; i < 2; i++){

byteReceived = Serial.read();//read the serial port

stringcoordinate = stringcoordinate + byte(byteReceived); //append it to our string coordinate

//delay(10); //wait for the buffer to fill

}

/* if(stringcoordinate.length() > 0 && laststringcoordinate.length() > 0){ //this statement just prints out the coordinates to make sure they're correct

Serial.print(laststringcoordinate);

Serial.print(",");

Serial.print(stringcoordinate);

}*/

//This next chunk of code finds the location of each square in its number form, and converts it to base 8 so we can use coordinates

//it's rudimentary search code -- plugging each possibility into our array until we get a match.

for(int i = 0; i < 64; i++){

if(laststringcoordinate.equals(squares[i])){

lastintcoordinate = i;

}

if(stringcoordinate.equals(squares[i])){

intcoordinate = i;

}

}

/////////DEBUG\\\\\\\\\\

//delay(10);

Serial.print(lastintcoordinate); //let's print our coordinates in int form

Serial.print(",");

Serial.println(intcoordinate);

/////////////////////////

//now we convert those numbers to base 8 to get some useful coordinates

lastycoordinate = lastintcoordinate % 8;

lastxcoordinate = lastintcoordinate / 8;

ycoordinate = intcoordinate % 8;

xcoordinate= intcoordinate / 8;

/////////DEBUG\\\\\\\\\\

//delay(10);

Serial.print("(");

Serial.print(lastxcoordinate);

Serial.print(",");

Serial.print(lastycoordinate);

Serial.print(")");

Serial.print(" to ");

Serial.print("(");

Serial.print(xcoordinate);

Serial.print(",");

Serial.print(ycoordinate);

Serial.println(")");

//////////////////////////

magnetservo.write(175); //puts the magnet down

xaxis.step((stepsforsquare/2), FORWARD, DOUBLE); //Offset to middle of square

yaxis.step((stepsforsquare/2), FORWARD, DOUBLE); //Offset

//delay(1000);

xaxis.step((lastxcoordinate * stepsforsquare), FORWARD, DOUBLE); //goes to our first set of coordinates. Assume we start at 0,0

yaxis.step((lastycoordinate * stepsforsquare), FORWARD, DOUBLE); //goes to our first set of coordinates. Assume we start at 0,0

//delay (3000); //waits for stepper to get to location

magnetservo.write(1); //puts the magnet up

//This code handles a vertical movement of a piece, where dividing to get a slope would give a denominator of 0 and crash the program

//////////////////////////

changey = (lastycoordinate - ycoordinate) * stepsforsquare; //the absolute value function doesn't work properly with math, so we have to store it in variables first

changex = (lastxcoordinate - xcoordinate) * stepsforsquare;

if(lastxcoordinate == xcoordinate){

Serial.println("vertical");

if(ycoordinate > lastycoordinate){

Serial.println("//delay1");

//delay(1000);

yaxis.step(abs(changey),FORWARD,DOUBLE);

//delay(1000);

}

else

if(ycoordinate < lastycoordinate){

Serial.println("//delay2");

//delay(1000);

yaxis.step(abs(changey),BACKWARD,DOUBLE);//we don't want any negative values

//delay(1000);

}

}

else if(((lastycoordinate - ycoordinate) / (lastxcoordinate - xcoordinate)) > 0){ //if we need to go up and to the right or down and to the left...

if(lastxcoordinate > xcoordinate){//...down and to the left

Serial.println("downleft");

yaxis.step(abs(changey), BACKWARD, DOUBLE);

xaxis.step(abs(changex), BACKWARD, DOUBLE);

}

if(lastxcoordinate < xcoordinate){//...up and to the right

Serial.println("upright");

yaxis.step(abs(changey), FORWARD, DOUBLE);

xaxis.step(abs(changex), FORWARD, DOUBLE);

}

}

else if(((lastycoordinate - ycoordinate) / (lastxcoordinate - xcoordinate)) < 0){// if we need to go down and to the right or up and to the left...

if(lastxcoordinate < xcoordinate){//... down and to the right

Serial.print("downright");

yaxis.step(abs(changey), BACKWARD, DOUBLE);

xaxis.step(abs(changex), FORWARD, DOUBLE);

}

if(lastxcoordinate > xcoordinate){//... up and to the left

Serial.println("upleft");

yaxis.step(abs(changey), FORWARD, DOUBLE);

xaxis.step(abs(changex), BACKWARD, DOUBLE);

}

}

else if(lastycoordinate == ycoordinate){ //if we need to go left or right...

if(lastxcoordinate < xcoordinate){ //go right

Serial.println("right");

xaxis.step(abs(changex),FORWARD,DOUBLE);

}

if(lastxcoordinate > xcoordinate){//go left

Serial.println("left");

xaxis.step(abs(changex),BACKWARD,DOUBLE);

}

}

magnetservo.write(175); //puts the magnet back down

xaxis.step((xcoordinate * stepsforsquare), BACKWARD, DOUBLE); //goes to our first set of coordinates. Assume we start at 0,0

yaxis.step((ycoordinate * stepsforsquare), BACKWARD, DOUBLE); //goes to our first set of coordinates. Assume we start at 0,0

//delay(1000);

xaxis.step((stepsforsquare/2), BACKWARD, DOUBLE); //offset back to edge of square

yaxis.step((stepsforsquare/2), BACKWARD, DOUBLE); //offset

}

laststringcoordinate = "";

stringcoordinate = "";

changex = 0;

changey = 0;

xcoordinate = 0;

ycoordinate = 0;

lastxcoordinate = 0;

lastycoordinate = 0;

intcoordinate = 0;

byteReceived = 0; }

Have you contacted the instructable project person with your questions?

yes, but there is no response. can you help me?

You need to be able to wire two stepper motors to a motor shield, and a servo, and 64 reed switches to a multiplexer.

You should be able to find examples of all of those things being done separately.

If you can't do any of them and aren't good enough at Googling to find examples then I suspect you are going to find this project very difficult and you might want to do something easier first - if it involves multiplexers, servos or stepper motors then it will get you closer to being able to tackle this project.

How about adapting this?
http://www.kitsusa.net/phpstore/html/OWI535-ROBOTIC-ARM-EDGE-1680.html
Puts the motor part into a nice assembly with gripper, without the complexity of having to make a CNC machine.
The site has other versions also.

For now, we'll try to control the motors using arduino and the reed switches. Its too complex to assemble everything at once. But I still wish to have a diagram. =(

By the way, is it easier if we are going to use a robotic arm instead?

Thanks so far :slight_smile:

I guess arm vs table depends on how big you want to make things.
Having the pieces move by magnet/electromagnet seems doable - getting the right magnet strength to only move the intended piece seemed to need working out. I guess having pieces spread out helps with that.
With a prebuilt-arm to start, at least the mechanical stuff has been worked out already so you're not taking on quite as much tasking to start. Still have to control four/five motors - spin left/right, main arm up/down, finger arm up down, and pincer open/closed - but limit switches should be in place.

And you could always program in some taunting kind of actions later ...

Robot arm hacked for Arduino!

Another interesting looking one

We actually want to make little changes in the project. Out XYZ table will be at the top of our sensory board so we would not have any problem with the magnets. We consider using ceramic magnets because neodymiums are way powerful and expensive.

I will still consider your suggestion guys, and still open for more suggestions though.
Thank you very much.