loading

A few months ago I bought a robotic arm of 4dof made in acrylic and this week i decided to program it to play the ancient and famous game Tic Tac Toc against me, and also for participate in the robotic contest. So, if you like this project please voted for it. ;)

Materials:

  • (1) Robotic arm with gripper.
  • (1) Web cam.
  • (1) Arduino One.
  • (1) Board of 3 x 3 squares.
  • Red and white pieces.

The web cam is for the image capture of the board. The image is analyzed by a visual basic program and using the minimax algorihm decides where the computer must place it´s piece. The program sends commands to the arduino one and this moves the robotic arm to the choosen position by the algorithm.

Step 1: The Robotic Arm

I bought the robotic arm here but you can build your own robot.

This robotic arm contains of 3 servos S3003, 1 for the base, 1 for the shoulder and 1 for the wrist. Also uses a servo sg90 for the gripper.

It is controlled by the Arduino One which is commanded by a visual basic program.

Step 2: The Diagram

As mentioned in the first step, 4 servos are connected to the pins 5,6,9 and 10 of the arduino one.

Step 3: The Image Capture

The web cam captures the image of the board and through a procedure in the visual basic program (you have to install the web cam library) , the image is divided into nine squares and each square is traveled for determining if contains red pixels. If so, the pixel is marked with red and later if the amount of points red of the square is greater than 60, then there is a red piece in that square and is interpreted with a "X", which is the movement of the human player.

Step 4: The Logic of the Game

here

The visual basic program determines the position of the computer thanks to an algorithm called miniMax, which is an algorithm used in games of two players and helps to decide the best movement for the computer turn.

Clic here for downloading the full code in visual basic of the project.

Note: the source code of the minimax algorithm used in the program was written by Ralph Main, you can see the article here.

Step 5: The Movement of the Arm

When the Artificial Intelligence of the minimax algorithm decides in which position the piece must be placed, it sends a string with the number of that position to the arduino through the serial port. The arduino receives the data and according to the position calls to the function that contains the movements in angles for moving the robotic arm.

Example of code for moving the arm to the second square:

if (dato=='2')

{

segundaPosicion()

}

......

void segundaPosicion()
{

//Move the base

for(i=180;i>=88;i--)

{ base.write(i);

delay(20);

}

delay(200);

//Moves the wrist to 90

for(i=114;i>=90;i--)

{

codo.write(i);

delay(20);

}

delay(200);

//Moves the shoulder to 160

for(i=140;i<=170;i++)

{ hombro.write(i);

delay(20);

}

delay(200);

//Moves the wrist

for(i=90;i<=102;i++)

{

codo.write(i);

delay(20);

}

delay(200);

//Open the gripper

for(i=110;i>=90;i--)

{

pinza.write(i);

delay(20); }

delay(200);

//Up the shoulder

for(i=170;i>=140;i--)

{

hombro.write(i);

delay(20);

}

delay(200);

posicionInicial(); //Moves to its initial position

}

Download the full code in arduino here

Thanks for watching, comments, sugestions, please let me know it.

<p>The game can detects any color not just red pixels i try another color and the game work will how can make the game only work for red color.</p><p>Sorry for my english.</p>
<p>Nicely done.... good use of VB like it.</p>
Awesome robot x
<p>Very cool Instructable! I love this! Thanks for posting!</p>
<p>Thanks for your comment. </p>
<p>Very nice instructable! </p><p>I noticed in the video that the arm only won because the human played made poor choices (they failed to play the forced winning move on their third turn and failed to block on their fourth turn). I was unable to download the source code, so I only can assume that the game solver is rather easy to beat? This is not bad, because no one wants to play a machine that is unbeatable. I could see where children might particularly find it fun to play against.</p><p>A very nice fusion of mechanics,computer vision, and electronic communication in a fun package!</p>
<p>The source code of the minimax algoritm used in the program was writtten by Ralph Main, you can see the code here for analyzing.</p><p>http://www.codeproject.com/Articles/5359/Yet-Another-Tic-Tac-Toe</p>
<p>Hi, thanks for your comment. In the video i placed the pieces in those posiitons only for demostrating the robot could win. But you can see that the artificial intelligence of the minimax algorithm is very good, because wont let me win when i have the chance of do it, but it is not unbeatable. Sorry for my english.</p>

About This Instructable

5,053views

67favorites

License:

Bio: My name is José Luis Bejarano Vásquez.Tecnólogo en electrónica, estudiante de ing electrónica, desarrollador de software. Aficionado a la robótica. Blogger.
More by sistemasymicros:Localizador / Rastreador En Tiempo Real Con Linkit One Number puzzle with Arduino Speed Math Game with Arduino 
Add instructable to: