Introduction: Automatic Mahjong Table

About: My github account: https://github.com/praznav Check out my friend Stark's instructables. here is a link to one of his instructables that I worked with him on. https://www.instructables.com/id/Autonomous-Autona…

Mahjong is a fun game!
but setting up the Tiles every single game is tiresome!
how about a table that does it for you!!!!
Here are some professional ones for inspiration:
http://www.youtube.com/watch?v=m5aiwxSfdH0
http://www.youtube.com/watch?v=zdyROHlbCeE

Now, you probably aren't going to make something that nice, or that efficient (I surely didn't), but its something to aspire towards.
A pic of mine is attached.
This project is a huge challenge mechanically. If you are good at using power tools and assembling parts, this is a project for you. The electronics and programming aspects are very basic and any beginner should be able to catch on quickly.

Step 1: Materials

Here are the things you will need to buy:

Materials:
36"x36"x1/4" plywood (or anything relatively sturdy enough to be the table top)
17"x17"x3/8" plywood (or thinner)
Wood for legs however tall you want it to be
Support wood - Lots and lots of 2x4's and 2x2's 
Many 2" screws
Many 1" screws
Many 3" screws (these sizes aren't necessarily required, use what works for you)
Assorted bolts and nuts
Aluminum sheet metal
C channel - the one we bought fit a mahjong tile perfectly
1-2 motors
1-2 servos
Powersupply (we don't go in depth into power bc we just used the arduino power and plugged it into our laptop, but feel free to ask questions regarding using an actual power supply if you want to)
1 L298 H bridge
Perfboard sheet
Solder
Photoresistor
Arduino uno (or comparable microprocessor)
LED's
Resistors
Switches/Buttons
Wire
Felt
Thumb Tacks
Velcro is nice

Tools you need:
Soldering Iron
Drill + drill bits + driving bits
Some type of saw (Table saw, jig saw, or circular saw)
Screwdrivers
Hot glue gun will help

Step 2: Theory

So, basically, the table has to take the tiles in and spit them out in a uniform row with the tiles randomized.
We split this into several smaller steps

1) Randomization
2) Positioning
3) Orientation
4) Stacking

here is a brief overview of each of the steps

Randomization is just making sure the order of the tiles is not preserved from one game to the next. A lot of the randomization is done with dropping the tiles into the hole. However, we dropped the tiles into a spinning barrel to add an extra element of randomization.

Positioning is making sure each tile is in the position that is needed for us to make rows out of them (ie. flattest face down and smallest face forward). This is done by cutting the opening to the barrel into the shape of the smallest face.

Orientation different from positioning. Even if the tiles are in the above position, we need to ensure that the back of the tiles are face up and the front face of the tiles are face down in the rows.

Stacking is constructing the rows out of these mahjong tiles.

Optional step: Raising - if you want to go super above and beyond, try to construct a mechanism to bring the rows of tiles to the top of the table automatically. We thought it was more trouble to build that it was worth, but we challenge you guys to do it!

Step 3: Basic Table Structure

Its a table. That means a flat top and four legs.
We used the 36'' square wood piece as our table top and assembled everything onto it.
Because we thought the legs would get in the way of assembling the tiles mechanism, we put the legs on last at the corners of the table.
The first step in constructing the tabletop is to cut a hole in the center of it. ours was a 10" by 10" hole. This hole is for the mahjong pieces to fall through. Keep the wood cutout of the 10x10 because it will be the flap cover later on.
You can make it as big as you want.

Note: each of our legs is made of two pieces of 30x6x.5 inch plywood crossed (see picture). This adds support, but adding cross braces is the only way to really ensure stability.

Step 4: Randomization

In order to randomize the tiles, we created a large circular bin under the opening.
All the tiles would fall into this bin and the act of falling would be a good randomizer.
Also, the bottom of the bin spins. This mixes up the order of the tiles.
The entire bin is at an angle so that the tiles slide down. At the lowest point of the bin is a hole that the tiles can fall through.
We created a lot of vertical supports extending down from the tabletop to hold all these components in place.
Thin sheet metal is invaluable in this step. It can make a circular bin quite easily and you can put screws and bolts through it easily as well.
Make sure you use a strong motor for spinning the circular base of the bin because it needs to support the weight of all the tiles.
We used a weak motor and as a result, we can only spin a certain number of tiles at a time.
Our next step is to replace that motor with a stronger one.
You will have to figure out most of these measurements yourself. It is a lot of trial and error.
Make sure you have access to the motor wires.
Just look at the pictures and try to replicate.

Step 5: Positioning

After the tiles fall out of the bin, they land in a chute. At the bottom of this chute is a servo with a mechanism to orient the tiles.
The chute stores several tiles so that even if the servo is slow in flipping, tiles aren't falling out.
Tiles can come down the chute face up or face down. **
A photoresistor will be able to distinguish between the back and front of the tiles.
We made our orientation mechanism out of sheet metal so that we could cut out a small hole for the photoresistor to peek through.
Make sure once again that you have access to the wires of the photoresistor. We will go over wiring later.
Also, make sure there is space for an LED near your photoresistor. You need to reflect light off of the tile surface for the photoresistor to read. I used a super bright LED.

If you don't understand fundamentally how the orientation works, watch the video at the end.


** If the hole in your bin allows for tiles of different positions to fall in, the orientation step may be more complicated. You may have to account for 4 different orientations rather than 2. The tiles may fall in on their side. I think if the orientation mechanism is constantly rotating from side to side until it senses a tile, you can solve this problem.

Step 6: Stacking

When the orientation step is done, the tiles literally just fall into a mold which holds 17x2 tiles.
As the tiles slide down to the bottom of the mold, they will form stacks. In order to play the next game of mahjong, you just flip the mold over and lift. The tiles will remain on the table in a perfect stack.

We only created one mold, but in a perfect world, you should have 4. One for each wall of mahjong tiles.
You can also create a mechanism to switch filled molds with empty ones once it gets filled up.

If you truly want to go above and beyond, you can lift the completed walls up to the playing field. We designed a system to do this using pulleys and sliders. However, we never got around to making it because it was so complicated.
If you design a system you think is good definitely tell me about it and if it worked or not. I might attempt to make it myself ;)


note: the first picture is upside down and i can't seem to fix it

Step 7: Programming and Electronics

Totally, we've used one motor for spinning the bottom of the barrel and one servo for orientation.
You may use extra servos for regulation controlling the flow of the tiles. (We initially planned on using 3 servos total)
You may also use extra motors to make a better system for the molds.

Using the L298 chip is quite straightforward. Follow the data sheet. Im not going to draw a schematic. http://www.tech.dmu.ac.uk/~mgongora/Resources/L298N.pdf
It allows you to control the motor very easily with the arduino.

Follow the arduino instructions for using a photoresistor. http://playground.arduino.cc/Learning/PhotoResistor
Make sure you have the input wire between the two resistors for greater accuracy in sensing.
Do many tests with multiple tiles so that you know the difference in values between face up and face down tiles.

Wiring the LED is simple as well. You need one resistor.
Use http://led.linear1.org/1led.wiz to figure out what size.

Servos can be wired very intuitively as follows:
Red to 5V
Black to gnd
Yellow to signal pin

I recommend testing it all on a breadboard before soldering it on.
I've added a picture of me testing the L298 H bridge chip.

Programming isn't that bad either. There are three things that the Arduino must do:
- Rotate the motor back and forth.
- If statement to switch between face up tiles and face down tiles.
- The servo spins opposite ways for either case.

I found it better to rotate the bin motor in the following pattern:
Clockwise 5 seconds
CounterClockwise 5 seconds
Clockwise .3 seconds
CounterClockwise .3 seconds
Clockwise .3 seconds
CounterClockwise .3 seconds
Clockwise .3 seconds
CounterClockwise .3 seconds

This lets a tile get into the hole and then switches directions rapidly to get it through.
Im not going to upload my code for two reasons. 50% because I lost it and 50% because I want you all to have to pleasure of coding and testing it yourselves. ;)

Step 8: Final Thoughts and Tips

We had some decent success with our table.
Each step works really well individually.
However, putting it together usually causes mayhem.
We also have some consistency issues with the orientation step. If tiles came down the chute too fast, they could very easily slip out of the mechanism (as you will see in the video).
One thing that really helps aesthetically is adding felt to the top of the table.
Also, make your chute much smaller than we made ours.
The tiles usually don't come out of the bin fast enough to overload the sorting mechanism. A bigger problem is the speed that each tile picks up from sliding down the chute.
You can add a switch to turn it on. This is more convenient than plugging in the power supply to turn on the table.
Also, add a few LED's around the table so you know if it's on.
Another fun addition you can do if you want is to add an automatic dice roller. This is just a motor attached to a container with dice in it. I recommend green poker table felt as opposed to red felt.

In the video, we don't spin the bin base both ways. We just got lucky with zero jamming. However, spinning the base both directions does fix any jamming issues. (the video was one of our preliminary tests)
In the second video, the LED isn't lit up. We didn't need it then.
Feel free to ask any questions or leave any comments.

This project isn't really difficult in programming or electronic work. This project is a mechanical challenge.

If you have suggestions about things we could try to improve consistency and decreases errors, please leave a comment or message me.
THANKS for reading and good luck, have fun!

Arduino Contest

Participated in the
Arduino Contest