3D Tic-Tac-Toe on a Led Cube


Introduction: 3D Tic-Tac-Toe on a Led Cube

About: I'm a final grade student from Hungary. I like having fun with arduino, and build robots and stuff. I would like to study engineering later.

Have you ever wanted to play Tic Tac Toe in 3 dimensions at home?

If the answer is yes, this Instructable provides you with every necessary information to build one.

The game is playable on a 3x3x3 led cube. Every point is a single-colour led, each LED must be controlled individually. To play tic-tac-toe at least 3 different signs are necessary, (usually o x and blank) however in a single-colour LED cube that would be impossible.

The solution is led flashing. When the game is started every led turned off, the first player plays with the turned on led, the second player is with the flashing led, so the game is playable that way.

A joystick and a button allow you to choose the LED where you would like to place your "sign".

Of course, you can just use your LED cube as a decoration. A code is provided which makes the LEDs flash randomly like in the video, or one after each other.

Step 1: Gather the Components

The list of necessary components to build the game:

  • 22*30 Universal circuit board (or bigger)
  • Arduino UNO
  • 27 LEDs (I used 3 mm LEDs)
  • Joystick module (KY-023)
  • Button module (KY-004)
  • 20 M-F jumper wires
  • Wire
  • Flexible wires
  • 12 F-F connector

Necessary tools

  • Styrofoam --> It'll make your work easier!
  • Soldering kit
  • Hot-glue gun
  • Pinchers
  • Cable-peeler
  • Ruler
  • Sandpaper (optional)

Step 2: Marking on the Styrofoam

Make 3x3 markings on a styrofoam block and poke holes to the LEDs to fit in. The holes should be 2 cm apart from each other, as we are creating a cube. You should use a ruler to do that.

Step 3: Sandpapering the LEDs (optional)

To achieve a larger level of brightness, you can use a sandpaper to rub the LEDs.

Step 4: Preparing the Wires

The exposed wires should be 4.5 cm long, prepare 24 of them. These are going to be the frame of the cube.

12 flexible wires have to be prepared. 9 of them should be 6-7 cm long. 3 of them should be 12-13 cm. Peel down both ends of the wires.

Step 5: Soldering the LEDs

First of all, we are connecting the negative leads together, this is usually the shorter leg of the LED.

Place the LEDs on the styrofoam which was prepared before. Place the wires as shown in the picture than wrap the shorter leg around the wire. Then solder the LEDs to the wire carefully, after that solder a wire on both sides, this will keep the square together.

It's important that when you are ready with one square, test all the 9 LEDs. It can be done by connecting the wire frame to the ground of the Arduino. Then use a M-M Jumper wire and connect it to the 3.3 V of the Arduino, and touch the other side to the unsoldered leg of the LED, the LED should light up. If no LED lights up, probably one of the positive legs touches the wire frame, you should check these.

You must prepare 3 LED squares.

Step 6: Soldering the Squares Together

This is the hardest part, you should ask for a helping hand at that stage.

Place one square on the styrofoam, then stick a wire next to the LED, in a vertical position. It's important that this wire ONLY touches the positive legs of the LEDs. Wrap the positive leg (the one you haven't soldered yet) around the wire and solder it. Do it with every LED.

Place the second square in the height of 2 cm. Wrap the positive legs around the vertical wires. The square will stay there that way, so you can solder each one after that.

Then place the last square in height of 4 cm. Do the same steps as before.

IMPORTANT: The horizontal wires shouldn't touch the vertical wires.

After you are ready with the step you should check each LED as before.

Step 7: Fixing the Cube to the Circuit Board

Firstly, you must use 9 flexible peeled wires.

Insert one side of the wire through the hole in the circuit board, solder it to the horizontal wire. Do it with all horizontal wires. After that fix the cube to the board, by applying hot-glue.

Secondly, use the 3 longer flexible peeled wires.

Solder them to the squares, and then insert those through the holes (You can use the bigger hole at the corner of the board)

When you are ready with the step you have 12 wires hanging at the bottom of the board. The 3 wires connected to the squares will allow you to choose the LED in the vertical direction. The 9 wires will allow you to choose the column where you would like to light up the LED.

Step 8: Solder the Connectors

Solder the connectors at the top. You should separate the horizontal and vertical ones as I did.

Solder the 9 wires to the connectors, as shown in the picture.

Then solder the 3 wires to the 3 connectors. Connect the wire from the top to the 10th pin, the middle to the 11th and the bottom to the 12th, and solder them there.

Glue the rest of the wires to the board.

Your LED cube is ready, you should try it now.

Step 9: Try the LED Cube

Connect the 1-9 on the LED cube to the D0-D8 in the Arduino (1 to D0, 2 to D1...)

Connect the 10-12 to Arduino as:

  • 10 to D11
  • 11 to D10
  • 12 to D9

Upload the provided code to the Arduino.

The ledRandom() function will make the LEDs flash randomly

The ledSeq() function will make the LEDs flash in a column one after another.

The ledWrite(x,y,z,v) function allows you to write any LED on the cube. x,y,z are the coordinates, they must be between 1-3. v is the state of the LED, when 0 the LED will turn off, when 1 the LED will turn on.

You can light up more LEDs separately. But lightning up a LED makes the one before to turn off. But the delay is only 0.5ms so you'll see them both turned on.

I'll try to improve this part of the program in the future.

Step 10: Connect the Joystick and the Button

The joystick module should be in the same position as the LED cube (as shown in the picture)

Button module:

  • Connect the - to the Arduino GND
  • Connect the + (middle pin) to the Arduino 5V
  • Connect the S (output pin) to Arduino A3

Joystick Module:

  • SW to A2
  • VRY to A1
  • VRX to A0
  • +5V to the Arduino 5V
  • GND to the Arduino GND.

Then fix the modules and the LED cube on a plastic plane, and upload the code to the Arduino.

Step 11: Have Fun :)

Your 3D Tic-Tac-Toe is ready.

Here's a short tutorial how to play:

  • Player 1 plays with the turned on LED
  • Player 2 plays with the blinking LED
  • The LED blinks faster, when you are on that LED.
  • You can choose your LED with the Joystick. Clicking with the Joystick allows you to go down. (from the first level, it'll go to the third)
  • Push the button to put down you sign there. (It will put it where the LED blinks fast)
  • The winner is the one who collects three signs in x,y or z direction. (The diagonals are not included yet)
  • When someone wins at the top the top right corner will light up and if
    • Player 1 wins. First row lights up
    • Player 2 wins. Second row lights up
    • The game will also show you the place where you collected your 3 signs.
  • To start a new game, push the joystick for a few seconds.

Important: Always push the button for a second, and keep the joystick for half a second.

I'm planning to improve the game in the future, by inlcluding the diagonals.

If you have any question write a comment or a message.

Microcontroller Contest

This is an entry in the
Microcontroller Contest



    • Make it Move Contest

      Make it Move Contest
    • Casting Contest

      Casting Contest
    • Woodworking Contest

      Woodworking Contest

    We have a be nice policy.
    Please be positive and constructive.