Picture of Arduino and Touchpad Tic Tac Toe
Or, an exercise in input and output multiplexing, and working with bits.  And a submission for the Arduino contest.

This is an implementation of a tic tac toe game using a 3x3 array of bicoloured LEDs for a display, a simple resistive touchpad, and an Arduino to tie everything together.

To see how it works, check out the video:

What this project requires:

Parts and consumables
One perf board (or strip board)
Nine bicoloured LEDs, common cathode
Nine identical resistors, in the 100-220 ohm range
Six identical resistors, in the 10kohm - 500kohm range
One single pole, double throw switch
A bunch of header pins
A bunch of electrical wire
One small square sheet of transparent acrylic, ~ 1 mm thick, 8 cm on the side
Clear sticky tape
Heatshrinks (optional)

All of the above are quite common items, total cost should not exceed USD$20.

One Arduino setup (Arduino Duemilanove, Arduino IDE, computer, USB cable)
Usual electrical tools (multimeter, solder solder gun, wire snips, wire cutter)

Everything Arduino related can be found at http://www.arduino.cc.

On with the build!

Step 1: Wiring up the LED matrix

Picture of Wiring up the LED matrix
For an LED to light, both its leads must be connected.  If we were to dedicate a pair of pins to each of the 18 LEDs (9 red, 9 green), we'd quickly run out of pins on the Arduino.  However, with multiplexing, we'll be able to address all the LEDs with merely 9 pins!

To do this, the LEDs are wired up in a crossbar fashion, as shown in the first figure.  The LEDs are grouped in columns of threes, and their cathodes are grouped in rows of sixes.

By setting a particular anode line high, and a particular cathode line low, and having a high impedance on all the other anode and cathode lines, we can select which LED we want lit up, as there is only one possible path the current can take.

For instance, in the second figure, setting the green anode 1 line high, and the cathode 1 line low, the bottom left green LED lights up.  The current path in this case is shown in blue.

But what if you want to light up more than one LED on different lines?  We'll use persistence of vision to achieve this.  By selecting pairs of LED lines very very quickly, it gives the illusion that all the selected LEDs are lit at the same time.

1-40 of 73Next »
rbusch1 month ago

that is one very well written instructable. great detail and explenations :) excelent job and very cool project!

Chi HinL2 months ago

Sorry, i want to ask how to import those library to the board?

AnnabelleS10 months ago

I'm making this for a science project, and I've looked all over, but I can't find where to get that size and thickness for the transparent acrylic sheet. Does anyone know where I can get one?

origamiwolf (author)  AnnabelleS10 months ago

It's not necessary to use the exact size and thickness I used in the instructable. In fact, any clear, flat material will work as long as it's non-conductive, transparent, and large enough to put the 3x3 grid of LEDs below. So a thin sheet of glass will work, as will a thin sheet of other types of plastic. One place to find these would be in picture frames - you could get a cheap one from a dollar store, and use the glass or plastic that comes with it.

thank you so much!
hccSmarties00711 months ago


Can you please reply to our email..We would of really appreciated.

Raphango1 year ago

Man... really one of the best instructables I've ever seen....


jt_hos1 year ago
Me and some friends just did this today... thanks, I have to say that it's been one of the best Instructables I've seen. I liked very much how you explained everything that was at work within this...
origamiwolf (author)  jt_hos1 year ago
Thank you, I hope you enjoyed building it!
origamiwolf (author) 2 years ago
The black dots show the connections to the cathode and anode leads, it's to make things clearer in a perspective diagram otherwise you can't tell where the wires should connect.
nehcyhtac2 years ago
Hi! We're trying to recreate this concept--we're running into serious problems though. We cannot seem to get the colors to show in order and we cannot seem to get some LEDs to light individually. When using the same button pattern over and over again we see unique patterns in the light grid--no consistency. We're using RGB (10mm) common cathode (4 legs, we've curled up the blue legs).

Please see the following video we made as documentation of the problem:

origamiwolf (author)  nehcyhtac2 years ago
I can't quite tell what's wrong, but one suggestion could be to try a 2 x 2 grid first then work your way up to the 3 x 3.
j416972 years ago
does it work with arduino uno?
origamiwolf (author)  j416972 years ago
I haven't tested it on the Uno, but it should work pretty much the same way.
thepoynt3 years ago
Any suggestions on how to test the touchpad by itself? I haven't built any of the rest of the project, and I'd like to make sure this part works before going on.

btw, great project idea - I'm enjoying building it!
origamiwolf (author)  thepoynt3 years ago
Connect multimeter probes to a row wire and a column wire, and set it up the measure resistance. If the ouchpad is workig correctly, you should see a dip in the resistance when you touch the row and column intersection. Repeat this for each pair of row and column wires.
robot13983 years ago
made the keypad and got it to work.........
origamiwolf (author)  robot13983 years ago
Great to hear that!
bmorgan63 years ago
I have a question where can i find the switch you ask for and does it have to be a throw switch?
origamiwolf (author)  bmorgan63 years ago
It has to be a switch that allows two states. You can get these switches online, from places like element14 or Mouser.
Keanan3 years ago
I notice in the code it has i % 3. I assume this is for the double anode/ one cathode for the LEDs you are using. So how would one change the code to accommodate for dipole LEDs instead of tripole?
origamiwolf (author)  Keanan3 years ago
No, the i % 3 comes from the way the matrix is addressed. Instead of storing two coordinates (ie row, column) for each LED, each one is simply labelled with a digit between 1 and 9.  The i % 3 and i / 3 code segments convert this single digit into the row and column coordinates.
So then, what must be changed for 2 lead LEDs to work instead of the 3 lead ones?
origamiwolf (author)  Keanan3 years ago
With a dipole LED, you just need to flip the HIGH and LOW digital states on the anode and cathode lines to access the two colours.

Let's say you have one row line and one column line, with the dipole LED across them. Then, if the row line is set to HIGH and the column line is set to LOW, it will turn on one LED colour. To get the other colour, the row line is set to LOW while the column line is set to HIGH.
aldrome3 years ago
Hi, I really like your idea!! And i was wondering if it is really importat that The red and green anode lines go into the PWM pins of the Arduino, I mean, why do they have to be PWM?, can they be the normal pins like number 2 or 13? It's because I'm trying to mix this with another idea I have.

Thanks for everything.
origamiwolf (author)  aldrome3 years ago
Hi aldrome,

I used PWM here because I wanted the LEDs to fade out. You can use the normal pins as well, but the LEDs will just have two brightness levels - on, or off.

-- Wolf
jwoo20234 years ago
can I use arduino uno?
origamiwolf (author)  jwoo20234 years ago
Sure, this should work on the Uno as well.
thanks for the info
skylen4 years ago
So it sounds like this touchpad matrix uses capacitive sensing, rather than resistive touch operation. When a finger is placed on the intersection of a row wire and a column wire, it increases the capacitance between the wires, causing the LOW level on the column wire to couple more strongly to the row wire, resulting in the touched row dropping in voltage more quickly than if it were not pressed.

Example: ChaN's Simple Touch Sensor
origamiwolf (author)  skylen4 years ago
Thanks, yes, that's a more likely explanation as you can sometimes get each intersection to trigger without a firm touch.
artecx4 years ago
I've problems with downloading the .pde files.
any solution to download them proper?
they all got a .tmp extension
origamiwolf (author)  artecx4 years ago
Just rename the .tmp to .pde.
you have a great idea in that game
maewert4 years ago
I really enjoyed this instructable.

A few comments however.
1.  I see that the random number sequence is always the same.  You need to add a random seed.
2.  The computer is very easy to beat since it does not take a winning move or try to block the user's winning moves.  These changes make the computer more difficult to beat but not impossible, so playing is still fun.

I updated the code to correct these two items and to make it work without your special hardware (i.e. you can play with a standard Arduino and a serial monitor or with your led touchpad).

This could be the start of the old 'tic-tac-toe playing chicken' seen in some county fairs where the person plays against the chicken.  When it is the chickens 'turn' the door to the chicken food is opened and the chicken appears to be thinking then pecks a selection.  This works so long as the person can't see what the chicken is packing at and assumes it is a similar display/keyboard they are presented with.  Very funny seeing kids getting beat by a chicken!

If there is community interest we could always make the 'impossible to beat the computer' version but where is the fun in playing that?  :-)

Best Wishes
origamiwolf (author)  maewert4 years ago
Great job! :)

Yes, the code in my instructable is very minimal, and there's so much that can still be done. For instance, instead of having it rigidly rule based, it would be possible to code up a learning algorithm. So initially, the computer plays randomly, but each win or loss will strengthen (or weaken) particular moves.

Such algorithms exist already, but it would be fun to see it on an Arduino. :)
Adi00054 years ago
This is the first time I am using bicoloured LEDs. So I was wondering if you could include a diagram of led matrix of arrangement of the bicoloured Leds.
origamiwolf (author)  Adi00054 years ago
Not quite sure what you mean, as the diagram in this step (step 1) already shows how the LEDs are connected.

Here, I'm using an LED with 3 terminals - one red anode, one green anode, and a common cathode.
This will be my first project with arduino. It don't looks hard. Can i don't use ''touchpad'' but just buttons in matrix?
origamiwolf (author)  kristiansmic5 years ago
Sure, yes, any kind of button switch would work.
1-40 of 73Next »