Tic Tac Toe Arcade Game with Raspberry Pi

tic tac toe arcade game circuit layout
Final layout of my tic tac toe game

In the event of the Raspberry Pi’s 4th (1st) birthday, I’ve been working on a tic tac toe arcade game using the Raspberry Pi’s GPIO with Python. Basically, a human player battles against the computer on a 3×3 LED grid. The player uses a pushbutton 4-way keypad with a ‘select’ button to play. I also added a speaker and coded some neat sound FX!

Below is a demo of the game:


parts to tictactoe arcade game raspberry pi
Parts used for the tic tac toe game

The hardware for this project is pretty basic:

  • Raspberry Pi
  • 9x green LEDs
  • 5x pushbuttons
  • Speaker
  • Trim potentiometer
  • 9x 330Ω resistor
  • 5x 10kΩ resistor
  • Adafruit Pi Cobbler with ribbon cable

    wiring diagram
    Wiring schematic for tic tac toe made with Fritzing

LED Grid Diffuser

In order to make the playing experience more pleasant, I designed a 3×3 grid LED light diffuser and 3D printed it so as to make the light from the LEDs less blinding. It also keeps the LEDs lined up nice and covers some of the wires up too!

Computer AI

This was actually my first experience dealing with any computer AI, and I discovered that it is quite fun! I designed it so it has four logical steps:

  1. First, if there’s any move where the computer will win (i.e. the computer already has two in a row), the computer will play that move.
  2. Second, if the player could win on the next turn, the computer will block it.
  3. Third, if the center of the board hasn’t been played, the computer will play the center.
  4. Finally, if none of the options above are applicable, the computer will play a random move not already played.


For the software, click here. It’s written in Python 3 with the RPi.GPIO library, and it’s actually the longest bit of code that I’ve written as of yet. 🙂

Here’s an extra video with more info about the project:

building the tic tac toe game
Building the final prototype for the tic tac toe game
closeup of tic tac toe circuit raspberry pi
Closeup of LED grid and buttons

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s