Voice-chess, a Chess Board With Voice Commands

1,721

16

9

About: I´m a Portuguese guy that loves making projects in the area of electronics! I love Lego (Technic are awesome!). I´m a great reader and my idol is Elon Musk.

Hi! First of all, I wanna thank you just because you are my instructable. This is my first one and I want to share my knowledge and Ideas to the biggest number of people. I want to say also that English is not my mother tongue. Sorry for any mistake or bad grammar :D. So....let´s move on! The Idea I am a chess player with many years of practice. When people ask me "What sport you like to do more?" I always say "chess, of course". Since many years the high-level chess competitions are considered a sport and I love it. You have so much techniques you can use...And this takes me to the problem this instructable tries to solve: the people with incapability, like the ones who lose the hands/arms (it is a big problem) can´t play chess! Well... they can play if the other player moves for them the pieces...But if the 2 players have got some kind of problem? And if the player is playing with himself? Or, if you don´t want to make this instructable not for somebody but just to have a cool and different chess board? (By the way, if you are a lazy person this project is exactly for you!) Because of all of this, I found an interesting solution for this problem. Why we don´t use a voice commanded chess board? It would be stupendous!

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Just One More Word

Since I like to preserve our planet, a big part of this project was made with reused materials. Some of them were going to the rubbish. Therefore, the appearance of this project is not so perfect and the design was compromised.

Step 2: Stuff You Will Need

*Some stuff here is very abstract. Try to use pieces like this ones. These were the ones I´ve used in my project. Dimensions described later.

+Android phone

+Wood base

+Aluminum foil with 0.5mm

+Chess pieces with a circular base

+32 metal (it must be magnetic, ex: iron) washers

+Copper wire (if you haven´t at your home just dissemble a transformer)

+2 Stepper motors (3 is better)

+Batteries or a voltage step down regulator with an external power source for the motors (i don´t recommend to use batteries, although I used. The power consumption is high and after a short while I ran out of battery.)

+Alkaline batteries (9V or more)

+Relay switch

+Arduino Mega (uno is ok too, but I used this one)

+Power supply for the arduino (12V in my case)

+Bluetooth module for arduino (just reception)

+Breadboard (Not exactly necessary)

+2 L298N Driver modules

+Fan (I used 12V to connect with the batteries)

+"Normal" screws

+1 Big Screw

+4 Bearings

+Hollow metal tubes (I used some from an old antenna)

+Cables to wire connections on arduino

+Cables to wire the rest of components

+Rivets

+2 Pulleys

+2 Belts for your motors (in case of using 3 motors pick up one more) +Super glue +2 Switch buttons

+4 Plastic Pieces to make the supports (You will understand later)

+Hollow Tubes (I dismounted an old antenna)

+Microphone to your phone (an external one)

+Rubber

Step 3: Skills and Tools

You should be able to:
+Make wholes in wood

+Cut and bend aluminum plate

+Weld/Solder

+Program in C++ (The basics of arduino)

+Understand the basics of motors and electromagnetic fields

+Cut metal tubes

+Use hot glue (Well....That is easy)

Tools:

+A computer

+Drilling machine

+Hot glue

+Screwdriver

+Fret saw or handsaw (I used both)

+Soldering machine

+Multimeter

+Compass for metal

+Rivet pliers

+Measuring tape

+Scissors for aluminum/metal

+Hammer

+Cutting pliers

+Pliers

*I think it's all here, but I may have forgotten one or two tools

Step 4: The Concept

Now, lets start with the theory. I will describe how the system works: first, we are going to install an android app called "Arduino Voice Control" (I don´t know if it exists on the app store). Basically, with this app, we are going to be able to spell to the smartphone and "translate" our voice to text and send it by Bluetooth to the arduino. It uses the Google voice, so you need a wifi/mobile data connection to use it. Thanks, Google. This process, if you want to understand it better is very simple. Pressing the button, you are activating the micro (for people that cannot do this, we will add a small rubber and put the smartphone on the ground so we may click with the foot). When you talk to your smartphone, it will convert your voice in an audio file that is sent to the Google servers. With the help of clusters (massive computers interconnected), the frequencies of our radio and pre-recorded audio frequencies are checked to see which of them match. If the margin is small than a certain value, the server says that our audio is equal to the pre-recorded (not just one sound pre-recorded, but many are used), so it sends back a text file with the word/phrase we said. It is very simple, but this technology is not super precise and some errors may happen and we will get a different text file than we were expecting. To solute this problem, a led will be added to our project. It will blink when the code is right. Now, we got a string that should be sent to our arduino. We will use a Bluetooth module (I bough this one from ebay but I recommend you to buy 2 because they easily burn if incorrectly connected) and connect it to our smartphone. Our string will be sent by this module to our arduino, via serial communication on 2.4 Ghz band. We now have got, for instance, the string "A2 B6". "A2" is the starting house and the "B6" is the house where we want to move the piece to. The arduino now needs to know if there is any piece in the the end house. To solve this, we are going to create in the beginning an array with all the values of the occupied houses. We will use a number system. 1 = 1, 2 = 2 and so on, but the letters will be A = 10, B= 20, and so on. If the house C3 is occupied, the list will have the value 33 (C=30 + 3=3). With this system we know always what are the occupied houses. Since we want to go to the B6 house, whose value is 26 (B=20 + 6), our arduino will check if there is the number 26 in the list. If is there, so we need to remove the piece, using our motors and let it fall into a box. If there the number 26 is not in our list, so we can move one directly to move the piece. We should not forget to update our list. The starting house value should be deleted from the list and the end house should be added, so the program works well in the other movements. Supposing there isn´t any piece in the end house, we just need to convert our letters from A2 B6 to numbers. A=1, B=2.....So we should move one house to the right, and to two upwards. We will now use our stepper motors to move the right amount of houses. We add a delay() function too, so the program waits to finish the move to continue. After this step is completed, we should activate our electromagnetic magnet. An electromagnetic magnet works with a simple principle: when current pass through it, a strong magnetic field is created. Since on the base of our pieces we will add a iron base, they become magnetic-sensible, and we can use the magnet. Therefore, we will add a relay switch to control this part of the system. Now, we just need to move our piece to the right house,without knock the other pieces. To solute this problem, the pieces will be softly moved to the right and upwards so it just move in the lines of the boards, between the houses, without knocking the other pieces. On the end of the move, the motors move back and left again to take the piece to the center of the house. The relay is turned off, so no current flows in the wire and no magnetic field will be created. The motors will move the magnet to the house A1 again to wait for another command and the LED will be turned off so the players know the arduino is ready to receive another move.

Step 5: L298N Driver

L298N driver module can directly drive motors in a range of 3 to 30V, and provide a 5V output interface to your arduino (My mega do not accept 5V so I didn´t use it). It has maximum amperage of 2A, which is enough to our system. You should notice on your own driver that is written the input is 12V. This is the normal value but there is no problem in using the range of 3 to 30V. Be careful with your finger while using these modules. Since we have a huge amount of current plus voltage, 12 watts in my case, they heat up easily and can hurt you. They are controlled by 4 pins and in the case of stepper motors there is a library that is super easy to work with, making our job a lot simpler.

Step 6: The Stepper Motors

I used 2 MITSUMI (model M42SP-6P) stepper motors in this project. I disassembled them from an old printer that was not working well anymore to reuse them. They are very precise and strong so they are ideal for this project. And the biggest pro point is: They were free and we contribute to save the planet!

The stepper motors have 4/5/6 cables to connect them (different number of cables tell us the motors have a different way to work). My ones have 4. The problem is to find out what cable represents what. With the help of our friend Google, I found, after 5 minutes of research, the pin out description. If you can´t find anything online just pick your multimeter and test 2 of the wires. If the resistance is low you find 2 cables that which make one coil. If is infinite, change the connection of one cable to another and check. Here are the cables of your coil. Now, pick the 2 cables from one coil and connect them to one of the L298N driver output parts. One cable in the GND and the other in the VCC. Repeat for the other 2 cables and after to the other motor/motors. If you are using 3 motors (which is the best), 2 of them will be used to control the x axis. You can connect 2 motors to the same output connectors on the L298N driver without problem. If you could not understand where you should connect the wires just check the wiring diagram that I made.

My 2 stepper motors have a voltage range from 10 to 26V and the normal and tested value is 24V. They use around 0.5mA, so they consume, both, 24Watts on tested conditions. I used a 16V supply because I wanted to decrease the amperage a bit. While doing this project I discovered that this motors (ANY STEPPER) can easily go to 100ºC. You can actually use them to make some toasts when you are playing or boil some water to make tea. Now, without joking, please be careful and do not touch these motors after playing for a while. This can be strange but their normal working temperature is around 90ºC. You may use a fan to cool them or use a weaker power supply to reduce the amperage, like I did. Furthermore, I tested the motors with 24V and they were working in a way a bit "heavy" reducing the precision level. With less voltage they work slower, making your game more precise. Like I said before, we are going to use a l298n driver to control them, using what we call "H-Bridge". In resume, the driver has 2 bridges, one for each coil and the way we close the circuit, since we have 4 switches on each H-Bridge, changes the current flow direction, changing the way we are moving the motor. You can find a lot of cool and better documented information on the web. This is just the principle of an unexplored world.

Note: If your motors are moving in the wrong direction just shift the cables.

Step 7: Some Calculations

Before we can proceed we have to do some math. We cannot do this project without knowing the dimensions that we are going to deal. The first thing to do is measure the diameter of the base of our chess pieces. My ones are relatively small, with a diameter of 2cm. Since we want enough space in the middle of the pieces so other ones can pass in the middle of them while moving without knocking we have to add 1cm in the left and one in the right, making 4cm for 1 house. Since the other house has an 1cm margin too, this makes 2cm exactly to the piece that is moving pass through them. But we need to add another margin, since we don´t want the pieces to scrape and some errors (in the order of milliliters) may occur. 0.5cm on each side seams to be enough. This makes our houses with 5cm side. Now, Each chess board has 8 houses on the x axis and another 8 on the y, so 8*5=40cm. Our board game will have 40cm. We can´t forget we need to write the letters and numbers of the houses on the sides of the board and we need a box to take out the pieces with a ramp. Besides that, we need enough space to the motors and the magnet to move freely to every house. To make sure everything works fine I added 10 cm on each side, making our board game with 60cm. Another thing we should consider is the wood base that will support our entire system. I used one with 65cm to give me a decent margin of work.

Step 8: Pick Your Material. Let´s Start!

First thing to do is get a wooden board with the right dimensions. I had one at my home from old furniture with 65cm side and 2 meters long. I cut it to make a 65cm side square.

Step 9: Make a Square

Find the middle of your base and make a square corresponding with your future game board. In my case it have 40cm side.

Step 10: Base for X Motor

The x motor (or motors, if you are using 2), needs a support to be fixed to the wood base. Pick up a one piece made from aluminum sheet (a square) and make a 90 degree bend with a 3:5 ratio (don´t need to be exact) like in the picture. With your compass make a circle and cut it If you prefer to not use the compass just make a small space so the "screw"(I don´t know what we call the toothed part that moves in the motor) as image 5. Initially I made a circle but I repeated again and made with one square. Make 2 holes and fix, with rivets, the motor(s), using the 2 holes the stepper motor has on its base. If your stepper motor don´t have holes to fix it, you may skip this step and just add a bit of hot glue in the base (ideal for stepper like the NEMA-17 that is a cube).

Step 11: Fix the Motor to the Base

Align the motor with your square. Here, you should be very precise since a one milliliter error can impair efficiency and accuracy when moving the pieces. You should place the motor out of the square you made. Although this picture shows the motor right next to the square, I had to change this while I was doing the project. Because of the supports I had to install to make sure the y motor didn´t swing, the space was not enough. Give a 5 cm margin. You will understand it better after. Make the holes in the wood and use screws.

Step 12: Pulley and Belt

Now, pick up one pulley and your belt. Since our square board has a 40cm side, we made a space of 5 cm in the left side, and a margin to the pulley should be added, we need a belt of around 50cm when stretched out (1 meter in total). By the way, for the y motor the dimensions of the belt are the same. Almost for sure this cable is a bit longer than what we need but it needs to be in tension. Dismount your pulley and attach the belt to it. Find the right place to fix with a screw the pulley. The belt should be parallel to the square. If you are using 2 motors to the x axis repeat the whole process and fix the other stepper on the other side of the square, parallel to this one.

Step 13: Y Axis

To make the base of the y axis I picked up from an old antenna a hollow tube.With the hammer I smashed the tips so I could fix the it to the belt (Don´t fix it now. We still having something to do.).

Step 14: Bearing Guide

Skip this step if using 2 x axis motors.
Since we just have 1 motor, in the other tip of the tube we have to use a bearing to support our tube. To make sure this bearing is always in the right way (we will glue it but is not enough) we have to make a guide to it. I used an old piece of metal that was 90º bended. I cut one of its sides to have a ratio of roughly 1:10. As you can see in the picture, I fixed it with 2 screws and it is parallel with the belt. Give a small margin so the piece is not touching the square.

Step 15: Hot Glue

Now, with hot glue, connect the tube with your bearing (the central part! DON´T GLUE THE PART THAT MOVES! If you do this the bearing will be there almost for nothing) and with your belt. On the side of the belt, right next to it, add another bearing to support the structure. The tube should be in the horizontal. If it is oblique just raise or low the bearing guide you made.

Step 16: Y Motor

Just like we did the support to the x motor, we have to do one for the y axis. Pick a bit of aluminum foil and bend it. You have the pictures to support you. Use 2 rivets to fix the foil to the motor and another 2 to fix the foil to the tube. The toothed "screw" should be out of the square that we made. Use the 5cm margin from the beginning of the project to help you.

Step 17: Pulley and Belt

Now, we have to fix the y axis pulley to support the belt. Using aluminum foil and 2 rivets make a small base so we can fix the pulley, like in the picture. Make a hole in the base to fix the pulley and add the belt. Remember: The belt must be in tension to work well and the pulley should be out of your square. If your belt is too long, you can cut it a bit and glue it again with super glue. Just make sure it is really well glued.

Step 18: Making a Anti-swing System

Since our y axis system is supported by 2 bearings they roll and make the system to swing. We can solve this problem using 2 other bearings and a bit of aluminum foil with the help of 2 small hollow tubes. Fix the aluminum rectangle with 2 rivets 2 the hollow tubes and, with the help of hot glue, fix the bearing in the tubes.The aluminum foil should be at the level of the under belt.

Step 19: Fixing the Anti-swing System

With the help of hot glue, fix the aluminum foil to the under belt. As you can see in the picture, I added another 2 sheets of metal on the other side like on step 14. This serves to stabilize and straighten the tube.

Step 20: Test the System

To make sure everything is ok, lets test the motors. No energy required, use your hands to pull the motors. I added some photos to reference if you want to check.

Step 21: More Metal!

Now, we are going to make a base to the electromagnet. I used a already 90º bended metal sheet. I just had to cut it in one of the tips so it could fit with the motors. I used the spirit level to see if it was parallel to the surface. If it a bit oblique just add some hot glue.

Step 22: A Bit of Welding

Since the cables of my stepper motors were too short, I cut them and I welded some news ones.

Step 23: Preparing the Batteries

I used 2 12V battery to power the motors. That was a HUGE error. Don´t do like me. Pick up a transformer right to the voltage of your motors (use a lower voltage if you could. For example: if the normal voltage is 24V use something like 16V so the motors don´t end heating too much). I had to, every 10 minutes, recharge them since the energy consumption was too high.

Step 24: Eletric Magnets!

Since an electromagnet is one of the core pieces of our pieces, we need to made (or buy, but that´s boring) one. An electromagnet basically consists in 3 parts: An iron core, like a nail with a flat part in the top, Cooper wire rolled on it and a battery. When we plug our battery (Remember: do not use lithium because we are creating a short circuit that can damage your batteries. Use alkaline.) a current flows in our copper wire, creating a magnetic field.

This expression computes the force between a solenoid and another piece of ferromagnetic material separated by a gap of distance g: F = (N*I)2 μ0 A / (2 g2), where: F is the force in Newtons; N is the number of turns, I is the current in amps, A is the area in length units squared, g is the length of the gap between the solenoid and a piece of metal. As we can see, more turns is equal to stronger magnetic fields and the same is thrush to the amperage. If you don´t like equations here is a link to a online calculator. I prefer to use equations. So, resuming, the keys to make a strong magnet are:

  • Batteries in series so we´ve got high voltage = high amperage.
  • More turns is always better

When making your magnet try to roll the copper wire always in the same direction. Rolling the wire in different angles/directions will make your magnet weaker.

Another thing you may notice is that your electromagnet will heat up easily. That is normal. The battery will heat too and, for us, that is a big problem. When doing my research on the web no tutorial (that I saw) mentioned this. That´s a bit weird. What happens is, because we are making a short circuit, the resistance is too low (just the cable), and since our voltage is a bit high (more than 9V) we will have a huge amount of current flowing by the cables, heating them and the battery itself. When we do this for too many time (like this project), the battery can get damaged or even destroyed. Another thing I noticed is: when we use the battery for a while and it warm up the voltage drops (even after disconnecting) and returns to the original value very slowly. Test it at your home! Use the magnet for a while to warm the battery and disconnect the circuit. Pick up your multimeter and check the voltage for a while. The voltage, when the battery is cooling again slowly raises. With a fan is faster. To solve this problem I added a fan to our project to cool down the battery. With a bigger airflow the battery gets time to cool when it is not being used (when waiting a user command for instance). I tested 1 battery with fan and another without fully charged. With the fan the lifespan of the one cooled with the fan was bigger. Therefore, besides extending the lifespan, the voltage is higher, representing a stronger magnetic field.

I made a electromagnet with a 9V battery and around 100 turns. It is in the picture. If your magnet, instead of attract the metal it repulse it, just switch the polarity of the cables.

Step 25: Connect Your Magnet

Use hot glue and connect the magnet to the belt (connect the down side-is more stable). As you can see in the picture, I added a sheet of metal so the magnet does not fall so easily while moving.

Step 26: Hold It!

When testing the system, the magnet often felt, so I added a bit of metallic wire to hold it to the support we made. I used a normal screw instead of the magnet so you can see better.

Step 27: Adding a Button to the Fan

Since we don´t want the fan always turned on, I just added a switch.

Step 28: Preparing the Eletronics...

Positioning everything in the right place. Use screws and the pre-made holes on the boards to fix them or just add some hot glue in their base.

Step 29: Eletronic Schematic

Now, is the time for connections. We´ve got many parts to connect together:

  • Arduino Mega
  • Power source for arduino (I used a powerbank and connected to the USB port of the arduino)
  • Power source for the motors (My case:16V)
  • Another power source

Here it depends of your magnet. Higher voltages = higher magnetic fields = stronger magnet... I used a 9V battery (those ones that are very cheap). I recommend you to use a cheap battery (DO NOT USE LITHIUM) since we are making a short circuit because the amperage is very high (the unique resistance we´ve got is the copper cable, that is very small). The batteries will easily harm up and this kills batteries so make sure to "refresh" your battery. Use a fan, for example and connect it to a different power source.

  • Led with 100ohm resistor to make sure it does not blow up
  • Fan 2 button switches
  • 2 L298N Module Drivers
  • 2/3 Stepper Motors (well....that´s obvious)
  • Relay module

The relay has 3 pins: VCC 5V, GND and one pin for the communication. When we send a signal for this pin the relay turn on or off.

  • Bluetooth module HC-05

This module has 6 pins but we just need to use 4. The VCC 5V, GND, and 2 for the connections: TX and RX. Remember, this module uses serial communication to talk with our arduino.

Now, the wiring. I left here an image of the wiring but it is a bit difficult to understand. Please, do not judge me, but I am bad at using fritzing. If you think it is difficult to understand, I just read the connections I write below.

Arduino

  • GND » LED
  • PIN 2 » 100ohm resistor » LED
  • PIN 7 » IN1 Relay Switch
  • GND » GND on Relay
  • VCC 5V » VCC on Relay
  • VCC 5V » VCC on Bluetooth module
  • GND » GND on Bluetooth module
  • TX0 » RXD on Bluetooth module
  • RX0 » TXD on Bluetooth module
  • PIN 29, 31, 33, 35 » PIN 1,2,3,4 of the l298n driver of x motor
  • PIN 37,39, 41, 43 » PIN 1,2,3,4 of the other l298n driver of y motor

Power supply for fan

  • VCC » VCC of fan
  • GND » Button switch » GND of fan

L298N (2x)

  • VCC » VCC of motor power supply
  • GND » Button switch » GND of Power supply
  • GND » GND of arduino

Relay switch

  • NC » Electromagnet (in)
  • COM » Alkali battery
  • Alkali battery » Electromagnet (out)

Step 30: Connecting Everything

Step 31: How It Is Under the Box

Step 32: Stowage Is Essential

Since we don´t want the cables obstructing the bearing, make sure everything is glued to the wood base or use tape.

Step 33: The Box

I made the box from aluminum foil. I had to bend it and cut it as shown in the pictures. Since our wood base had a side with 65cm, I made the base of the box with 60.

Step 34:

Since we have buttons and a fan, we have to make some holes on the box.

Step 35: Making the Houses

With a permanent marker I draw the houses and the numbers/letters. I made some measurements and I found the center. I just had to make the 40 cm square, like the one I draw on the wood.

Step 36: Hole for the LED

Since we added a led to make sure thee system is working, I made a hole near to the houses on the box.

Step 37: The Box for the "dead" Pieces

Since we don´t want nobody taking out the pieces, our system is responsible for that too. Make some kind of ramp so the pieces will fall. Make sure you bend the aluminum foil near to the center of the "house" (is not exactly a house, but if the board was bigger it would be) just like I did. Add a box so the pieces fall on it.

Step 38: Adding Some Bases

Since we don´t want the screws scratching our tables I added some plastic bases. I used hot glue.

Step 39: Preparing Your Chess Pieces

Pick your 32 washers and, with superglue,glue them to the base of the pieces. This will make them magnetic sensible, and now we can use our electromagnet to push them.

Step 40: Adding a Foot Clicking Feature

Since we want a system for people that can´t play chess by the normal ways, is a bit strange have to click on the phone each time we want to send a command. Because of this, I added a foot clicking feature. I just added a rubber on the top of the screen of the phone (attention: not even all works. There is a special type (I don´t know what to call it) that, if we make pressure, the smartphone recognizes a touch). Now, our android may be on the floor and people can play the game without using their hands. But another problem appears: the microphone of our smartphone can´t recognize our voice from this distance. It needs to be near us. To solve this problem, I bought this microphone and this one. They are pretty much the same thing and they work very well. Just use hot glue to glue them to the box.

Step 41: Programming-The Code

Now, the programming part. Since your project´s dimensions may be different there are some stuff you should change (I marked the value where you must write your own with this symbol: [?]), but I will explain what you need to do later. PLEASE DO NOT COPY AND PAST THE CODE! IT WON´T WORK! Here is the code:

Voice Chess Arduino Code

//This code was written by a person (well....it is obvious. It couldn´t be my dog) under the nickname diyguypt and was
posted in the instructables website. For more info about this project (or myself) just search on google for "Voice-chess,
a Chess Board With Voice Commands By diyguypt". Please respect me and don´t delete this message. If you were in my
position, you wouldn´t want that.
#include
const int stepsPerRevolutionx = [?]; // change this to fit the number of steps per revolution for the x motors
const int stepsPerRevolutiony = [?]; // change this to fit the number of steps per revolution for the y motor
Stepper myStepperx(stepsPerRevolutionx, [?], [?], [?], [?]);
Stepper mySteppery(stepsPerRevolutiony, [?], [?], [?], [?]);
int pecas[] = {1,2,3,4,5,6,7,8,11,12,13,14,15,16,17,18,71,72,73,74,75,76,77,78,61,62,63,64,65,66,67,68};
String voice; //our main command
int relay = [?]; //port of our relay
int x1;
int y1;
int x2;
int y2;
int a; int b; int c; int d; int e; int f; int g; int h;
int led = [?]; //port of your LED
int startvalue;
int endvalue;
int mv = [?]; //number of steps to move one house
int delaytime = [?]; //seconds the stepper needs to move one house
int xbox = [?]; //cords (x) of the box for the "dead" pieces/units in houses
int ybox = [?]; //cords (y) of the box for the "dead" pieces/units in houses
void setup() {
myStepper.setSpeed(30);
mySteppery.setSpeed(30);
pinMode(led, OUTPUT); //setup of our LED
Serial.begin(9600); //serial comunication with our bluetooth module
Serial1.begin(9600); //serial comunication with our computer to check things out
pinMode(relay, OUTPUT); //setup of our relay
digitalWrite(relay, LOW); //our relay should be off
myStepperx.step([?]); //setup to place the motors in the house A1
delay (4000);
mySteppery.step([?]);
delay (4000);
}
void loop() {
while(Serial.available()) {
delay(10);
char c=Serial.read();
if(c=='#')
{break; }
voice += c;
}
if (voice.length() == 4) {
Serial1.println(voice);
digitalWrite(led, HIGH); //turn on the green led to inform the user the message was received
voice[0]=x1;
voice[1]=y1;
voice[2]=x2;
voice[3]=y2;
a = 0;
b = 10;
c = 20;
d = 30;
e = 40;
f = 50;
g = 60;
h = 70;
startvalue = (x1 + y1);
endvalue = (x2 + y2);
for (byte i = 0; i < 25; i = i + 1) {
if (pecas[i] == endvalue) { //commands to take out our piece of the game
myStepperx.step(x2*mv); //to second house position
delay (x2*delaytime);
mySteppery.step(y2*mv/10);
delay (y2*delaytime/10);
digitalWrite(relay, HIGH); //turn on the relay
delay (100);
myStepperx.step(mv/2); //moving a bit to the sides so we don´t end up knocking in the other pieces
delay (delaytime/2);
mySteppery.step(mv/2);
delay (delaytime/2);
myStepperx.step((xbox-x2)*mv); //to the box of "dead" pieces
delay ((xbox-x2)*delaytime);
mySteppery.step((ybox-(y2/10))*mv);
delay ((ybox-(y2/10))*delaytime);
myStepperx.step(-mv/2); //moving again a bit to the center of the house
delay (delaytime/2);
mySteppery.step(-mv/2);
delay (delaytime/2);
digitalWrite(relay, LOW); //turn off the relay
delay (100);
myStepperx.step((x1-xbox)*mv); //picking first piece
delay ((x1-xbox)*delaytime);
mySteppery.step(((y1/10)-ybox)*mv);
delay (((y1/10)-ybox)*delaytime);
digitalWrite(relay, HIGH); //turn on the relay
myStepperx.step(mv/2); //moving a bit to the sides so we don´t end up knocking in the other pieces
delay (delaytime/2);
mySteppery.step(mv/2);
delay (delaytime/2);
myStepperx.step((x2-x1)*mv); //going to second house
delay ((x2-x1)*delaytime);
mySteppery.step((y2-(y1/10))*mv);
delay ((y2-(y1/10))*delaytime);
myStepperx.step(-mv/2); //moving again a bit to the center of the house
delay (delaytime/2);
mySteppery.step(-mv/2);
delay (delaytime/2);
digitalWrite(relay, LOW); //turn off relay
myStepperx.step(-x2*mv); //back to initial position
delay (x2*delaytime);
mySteppery.step(-y2*mv/10);
delay (y2*delaytime/10);
for (byte w = 0; w < 25; w = w + 1) { //remove the initial house from the list of the occuped pieces
if (pecas[w] == startvalue) {
pecas[w] = 0;
}
}
}
else {
myStepperx.step(x1*mv); //to first house position
delay (x1*delaytime);
mySteppery.step(y1*mv/10);
delay (y1*delaytime/10);
digitalWrite(relay, HIGH); //turn on the relay
delay (100);
myStepperx.step(mv/2); //moving a bit to the sides so we don´t end up knocking in the other pieces
delay (delaytime/2);
mySteppery.step(mv/2);
delay (delaytime/2);
myStepperx.step((x2-x1)*mv); //to the second house
delay ((x2-x1)*delaytime);
mySteppery.step((y2-y1)*mv/10);
delay ((y2-y1)*delaytime/10);
myStepperx.step(-mv/2); //moving again a bit to the center of the house
delay (delaytime/2);
mySteppery.step(-mv/2);
delay (delaytime/2);
digitalWrite(relay, LOW); //turn off the relay
delay (100);
myStepperx.step(-x2*mv); //back to the inicial position
delay (x2*delaytime);
mySteppery.step(-y2*mv/10);
delay (y2*delaytime/10);
for (byte t = 0; t < 25; t = t + 1) { //remove the initial house from the list of the occuped pieces
if (pecas[t] == startvalue) {
pecas[t] = endvalue;
}
}
}
}
digitalWrite(led, LOW);
}
voice="";
}

Step 42: Programming-Code Explanation

Code explanation

#include
This is the library that will help us a lot when contacting with our stepper motors.
const int stepsPerRevolutionx = [?];
const int stepsPerRevolutiony = [?];
In this 2 commands we are preparing our motors and you must change this according to your motors.
First one is x motor or motors and the latter is responsible for the y. As the name suggests it’s
the number of steps per revolution that ourmotor is rated at. In my case case it’s 200 or 1.8 degrees
per step. If you just have the number of degress per step just do 360/numberofsteps and you will
have the right values.
Stepper myStepperx(stepsPerRevolutionx, [?], [?], [?], [?]);
Stepper mySteppery(stepsPerRevolutiony, [?], [?], [?], [?]);
Here, we are setting up the ports of our motors. Since each L298N driver has 4 pins (6, but we just
use the 4 of the center), on each [?} you should write the number of the port of your arduino that
each pin of the l298n driver is connected to. Write them in order, from the left side of the
driver to the right side.
int pecas[] = {1,2,3,4,5,6,7,8,11,12,13,14,15,16,17,18,71,72,73,74,75,76,77,78,61,62,63,64,65,66,67,68};
The system must have the occuped pieces information so it knows if the house that we are
moving to is occuped or not and if it needs to take it out first. This list is always in update
as the program rolls so the arduino knows what is going on. Since we will do some math later,
we cannot use letters in this list. So I change the letters to multiples of ten. The A line
has a value of 0, the B of 10 and so on....For example: the House B7 has the value 17, because
B=10 + 7. This list represents the initial position of the pieces, when the game is starting.
String voice;
This string is our main command, that comes from our Phone.
int relay = [?];
Setup of our relay. Write the port your relay is connected to.
int x1;
int y1;
int x2;
int y2;
Our string voice will be, after, divided in 4 different comands, representing the 4 letters/
/numbers.
int a; int b; int c; int d; int e; int f; int g; int h;
Declarating the letters of the board so the arduino can change the letters to numbers, after.
int led = [?];
Setup of our LED. Change this for the port which your led is connected to.
int startvalue;
int endvalue;
Some stuff explained later.
int mv = [?];
Here you should pay attention. In this integer we say to our arduino what is the number of
steps to move one house. This value should be tested by you since diferent motors have
different configurations. You can make a simple program in your arduino to get this value.
Just make a program that will order our motors to take just a step. Just one. Repeat this
until you move one ENTIRE house and count the number of times you did it. Voilá! This is
the number you should put here.
int delaytime = [?];
Like the previous command, this one should be tested by you, but with a different approach.
Make a code to move the exact number of steps of the previous integer. Watch your clock
and write here the number of miliseconds to move one house. Remember: Not seconds. Miliseconds.
Add a margin of around 400 miliseconds (up) to make sure everything is fine.
int xbox = [?];
int ybox = [?];
In this 2 commands, we write the coords of the box of the dead pieces. The former is for x axis
and the other to the y. The units should be in houses. For example: My box is on the left side
of the board, near to houses 4 and 5. The x axis corresponds to the one at the left of the "A" line.
So, in the xbox we should write -1 because we are getting out of the board. If the box was in the
right side, this value should be 8, because the A line corresponds to 0, the B to 1 and so on, until
the h that corresponds to 7. If the board had another row, it would be the 8th. For the ybox, I wrote
on my code the number 4.5. Why? Simple. My box was a length of 2 entire houses to make sure that
erros don´t occur.
void setup() {
myStepper.setSpeed(30);
mySteppery.setSpeed(30);
Setting up the speed of the steppers. I tried to change this values but nothing happened (at least for me).
Without this commands the steppers were not working.
pinMode(led, OUTPUT); //setup of our LED
Serial.begin(9600); //serial comunication with our bluetooth module
Serial1.begin(9600); //serial comunication with our computer to check things out
pinMode(relay, OUTPUT); //setup of our relay
digitalWrite(relay, LOW); //our relay should be off
myStepperx.step([?]);
delay (4000);
mySteppery.step([?]);
delay (4000);
Here, you need to change some values. Since your initial position of the motors may not be the house
A1, you can place the motors in the right position here. If you already prepared the motors to be
under the house A1, just delete this 4 lines of code.
}
void loop() {
while(Serial.available()) {
delay(10);
char c=Serial.read();
if(c=='#')
{break; }
voice += c;
Here, we are asking our smartphone the voice command. It will be stored in the "voice" string.
}
if (voice.length() == 4) {
The command must have 4 characters. For instance, if you want to move from A1 to B7 you should say
"A1B7". If the length is not correct, something is wrong and the program will wait for another
voice command.
Serial1.println(voice);
Just to see what is going on the Arduino with our computer.
digitalWrite(led, HIGH);
Turn on the green led to inform the user the message was received and everything was correct.
This led will be on until the program stops the command.
voice[0]=x1;
voice[1]=y1;
voice[2]=x2;
voice[3]=y2;
Splitting the voice string in 4 independent commands.
a = 0;
b = 10;
c = 20;
d = 30;
e = 40;
f = 50;
g = 60;
h = 70;
Changing the letters to numbers so the arduino cam make some math.
startvalue = (x1 + y1);
endvalue = (x2 + y2);
This 2 commands will help us adding and deleting numbers in our pieces list.
for (byte i = 0; i < 25; i = i + 1) {
if (pecas[i] == endvalue) {
Here we see if the house that we want to move the piece to is occuped. Thanks to our list. If
yes, we have to remove it firstly from the board.
myStepperx.step(x2*mv);
delay (x2*delaytime);
mySteppery.step(y2*mv/10);
delay (y2*delaytime/10);
Commands to move our motor to the arrival house.
digitalWrite(relay, HIGH);
delay (100);
Turning on the relay to pick the piece with the magnetic field produced by the eletromagnet.
myStepperx.step(mv/2);
delay (delaytime/2);
mySteppery.step(mv/2);
delay (delaytime/2);
Moving a bit to the sides so we don´t end up knocking in the other pieces. The piece now will move
over the lines of the houses and not in the middle.
myStepperx.step((xbox-x2)*mv);
delay ((xbox-x2)*delaytime);
mySteppery.step((ybox-(y2/10))*mv);
delay ((ybox-(y2/10))*delaytime);
Moving to the box of the dead pieces.
myStepperx.step(-mv/2);
delay (delaytime/2);
mySteppery.step(-mv/2);
delay (delaytime/2);
Moving again a bit to the center of the house, since now we cannot knock other pieces.
digitalWrite(relay, LOW);
delay (100);
Turning off the relay so the piece will fall in the box.
myStepperx.step((x1-xbox)*mv);
delay ((x1-xbox)*delaytime);
mySteppery.step(((y1/10)-ybox)*mv);
delay (((y1/10)-ybox)*delaytime);
Now we can move the piece. Picking it.
digitalWrite(relay, HIGH);
Relay on.
myStepperx.step(mv/2);
delay (delaytime/2);
mySteppery.step(mv/2);
delay (delaytime/2);
Moving a bit to the sides so we don´t end up knocking in the other pieces.
myStepperx.step((x2-x1)*mv);
delay ((x2-x1)*delaytime);
mySteppery.step((y2-(y1/10))*mv);
delay ((y2-(y1/10))*delaytime);
Going to 2nd house.
myStepperx.step(-mv/2);
delay (delaytime/2);
mySteppery.step(-mv/2);
delay (delaytime/2);
Moving again a bit to the center of the house, to the right position of the piece (the middle of
the house).
digitalWrite(relay, LOW);
Relay off.
myStepperx.step(-x2*mv);
delay (x2*delaytime);
mySteppery.step(-y2*mv/10);
delay (y2*delaytime/10);
Now the motors move again back to th initial state, the house A1.
for (byte w = 0; w < 25; w = w + 1) {
if (pecas[w] == startvalue) {
pecas[w] = 0;
}
}
}
On these last lines we delete the value of the initial house from the list, since it isn´t occuped.
else {
The last lines were useful if we had the arriving house occuped. If it isn´t we don´t need to take
any piece out.
myStepperx.step(x1*mv);
delay (x1*delaytime);
mySteppery.step(y1*mv/10);
delay (y1*delaytime/10);
Moving to first house.
digitalWrite(relay, HIGH);
delay (100);
Relay on.
myStepperx.step(mv/2);
delay (delaytime/2);
mySteppery.step(mv/2);
delay (delaytime/2);
Moving a bit to the sides so we don´t end up knocking in the other pieces.
myStepperx.step((x2-x1)*mv);
delay ((x2-x1)*delaytime);
mySteppery.step((y2-y1)*mv/10);
delay ((y2-y1)*delaytime/10);
Moving to the second house.
myStepperx.step(-mv/2);
delay (delaytime/2);
mySteppery.step(-mv/2);
delay (delaytime/2);
Moving back to the center of the house
digitalWrite(relay, LOW);
delay (100);
Relay off.
myStepperx.step(-x2*mv);
delay (x2*delaytime);
mySteppery.step(-y2*mv/10);
delay (y2*delaytime/10);
Moving back to A1.
for (byte t = 0; t < 25; t = t + 1) {
if (pecas[t] == startvalue) {
pecas[t] = endvalue;
}
}
}
}
Remove the initial house from the list of the occuped pieces since it is not occuped anymore.
digitalWrite(led, LOW);
Led off. End of command. The players now know that they can send another voice command.
}
voice="";
}
view rawCode explanation hosted with ❤ by GitHub

Step 43: The App

The app I used was the "Arduino Voice Control" available on the playstore. After install it and when ready to use the board, make sure the language is English and connect your cellphone to wifi and to your bluetooth module. It would show in the available bluetooth devices the HC-05 or HC-06. Connected to it. If it asks you a code is the 1234 or 0000, but it depends from the manufacturer. When you want to send a command just click on the microphone and do not click again,because it will cancel the command.

Step 44: How It Looks Like

Step 45: How to Play-small Guide

A small guide if you don´t understand something on the rest of the instructable.

  1. Turn on the 2 button switches
  2. Turn on your arduino power source
  3. Connect to internet your smartphone
  4. Connect to your Bluetooth module (The name is HC-05 or HC-06)
  5. Click on the button of the app when ready to send a command
  6. Speak your command (for example: A1B2)
  7. Wait
  8. The LED will turn on in a few seconds to show the arduino received the message
  9. When the LED turn off you can send another command
  10. Enjoy!

Step 46: Testing the System

*Sorry for my bad spoken English :D

Step 47: Conclusion

So....Thanks for reading my instructable. If your have any questions or tips just write below on commentaries. Normally, when I make a project, in the end, I try to reflect about how did it go and what could I do to improve it. Here is a small list of things you can change:

  • Instead of using a smartphone, use a proper module. Yeah! There are modules to send command by voice but they are a bit expansive and they work by a different way.
  • Buy a decent Bluetooth module from a well-know shop, not ebay. My bluetooth module burned out and I had to wait for a new one to continue this project. If you are buying on ebay buy 2 or 3 modules.
  • If you don´t like our planet and want to contribute to the deforestation, buy some wood and make a nice design to the board.
  • Instead of using a relay and a electromagnet, we could use a permanent magnet and, with the help of a selanoid valve, we could rise or fall it, when we want to move a piece. We don´t waste batteries but errors will appear easily.
  • Instead of using a LED, you may use a LCD to show what move is going to be done. I could have done this, but I still thinking the led is enough. Is just an idea.

Until the next project!

Games Contest

Participated in the
Games Contest

Be the First to Share

    Recommendations

    • CNC Contest

      CNC Contest
    • Make it Move

      Make it Move
    • Teacher Contest

      Teacher Contest

    9 Discussions

    0
    None
    ergaar

    20 days ago

    Hi,
    Learned new things about "how to think" besides "how to make" from this.

    One question I have,
    What would be the errors for using permanent magnets instead?

    0
    None
    diyguyptWingletang

    Reply 22 days ago

    I'm glad you liked. Your project seems to be very interesting and that was a really good idea to add to my project. Thanks!

    1
    None
    Wingletangdiyguypt

    Reply 22 days ago

    Will look forward to your next Instructable. BTW I have voted for your voice chess in the games contest. Good luck!

    0
    None
    diyguyptWingletang

    Reply 21 days ago

    Thanks! I will try to get a free time to make it.

    1
    None
    jessyratfink

    23 days ago

    What a fantastic first ible! It's a great project and I like that you tried to reuse a lot of items :)

    1 reply
    0
    None
    diyguyptjessyratfink

    Reply 23 days ago

    Thanks for the compliment! Reusing materials and recycling is the topic of the day. I think everybody should make something to make our planet a better place.