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

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.

<p>that is one very well written instructable. great detail and explenations :) excelent job and very cool project!</p>
<p>Sorry, i want to ask how to import those library to the board?</p>
<p>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?</p>
<p>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.</p>
thank you so much!<br>
<p>Hello </p><p>Can you please reply to our email..We would of really appreciated.</p>
<p>Man... really one of the best instructables I've ever seen....</p><p>Congratulations!!</p>
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...
Thank you, I hope you enjoyed building it!
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.
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). <br> <br>Please see the following video we made as documentation of the problem: <br>http://www.youtube.com/watch?v=HlCw08GTqDo&amp;feature=plcp <br> <br>PLEASE HELP!
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.
does it work with arduino uno?
I haven't tested it on the Uno, but it should work pretty much the same way.
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.<br><br>btw, great project idea - I'm enjoying building it!
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.
made the keypad and got it to work.........
Great to hear that!
I have a question where can i find the switch you ask for and does it have to be a throw switch?
It has to be a switch that allows two states. You can get these switches online, from places like element14 or Mouser.
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?
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.&nbsp; The i % 3 and i / 3 code segments convert this single digit into the row and column coordinates.<br>
So then, what must be changed for 2 lead LEDs to work instead of the 3 lead ones?
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.<br><br>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.
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.<br><br>Thanks for everything.
Hi aldrome,<br><br>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.<br><br>-- Wolf
can I use arduino uno?
Sure, this should work on the Uno as well.
thanks for the info<br>!
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.<br><br>Example: <a href="http://elm-chan.org/works/capsens/report_e.html">ChaN's Simple Touch Sensor</a>
Thanks, yes, that's a more likely explanation as you can sometimes get each intersection to trigger without a firm touch.
I've problems with downloading the .pde files.<br>any solution to download them proper?<br>they all got a .tmp extension<br>
Just rename the .tmp to .pde.
you have a great idea in that game
I really enjoyed this instructable.<br> <br> A few comments however.<br> 1.&nbsp; I see that the random number sequence is always the same.&nbsp; You need to add a random seed.<br> 2.&nbsp; The computer is very easy to beat since it does not take a winning move or try to block the user's winning moves.&nbsp; These changes make the computer more difficult to beat but not impossible, so playing is still fun.<br> <br> 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).<br> <br> 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.&nbsp; 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.&nbsp; This works so long&nbsp;as the person can't see what the chicken is packing at and assumes it is a similar display/keyboard they are presented with.&nbsp; Very funny seeing kids getting beat by a chicken!<br> <br> If there is community interest we could always make the 'impossible to beat the computer' version but where is the fun in playing that?&nbsp; :-)<br> <br> Best Wishes
Great job! :) <br> <br>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. <br> <br>Such algorithms exist already, but it would be fun to see it on an Arduino. :)
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.<br>Thanks
Not quite sure what you mean, as the diagram in this step (step 1) already shows how the LEDs are connected. <br><br>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?
Sure, yes, any kind of button switch would work.
Very good idea.
Dear Author,<br /> <br /> Had a few questions popping in my head..! Since Arduino is popular BECAUSE it's an open-source platform, can we say the same about all the instructables out here using the arduino board? Who owns the IP..the guys at instructables.com or the individual author? What if I were to publish an article in a mag about this touchpad tic-tac-toe..whose permission do I take..if at all I need one?<br /> <br /> Thanks. Hope to hear from you!<br />
IANAL, but I believe using an open source platform does not automatically mean that the work that comes out of it is open source.<br /> <br /> The <a href="https://www.instructables.com/tos.html" rel="nofollow">Instructables ToS</a> states that the author owns and is responsible for their instructable.&nbsp; So one would need to get permission from the author to publish their work in a mag.<br /> <br />
is this needed<br /> when I ran this in circuir wizard it was the only way I could get it to work<br /> what is your suggestions<br /> keven
Ok, are you familiar with controlling a single LED with the arduino?&nbsp; If not, you should learn a bit more about that first.<br />
<a href="http://yfrog.com/6rcircuitdiaj" rel="nofollow">http://yfrog.com/6rcircuitdiaj</a><br /> here is the link<br /> can you tell me why I can't attached it in instructable ?<br /> thank you for your persistance
Not sure why an image can't be attached, maybe you'll need to check on the community pages...<br /> <br /> Anyway, I can't quite understand your circuit...for instance, why's there -12V going into pins 2, 4 and 8?&nbsp; <br />
Hi its keven again<br /> i have tried to attached the image to this email and for some reason it will not<br /> I haved uploaded it to ImageShack<br /> file name is circuitdia.jpg<br /> please see if you can see it<br /> the circuit is a simplfied version of the actual one<br /> each led in the circuit represents 24 led with resistors and a 12v+ power supply <br /> I hope this helps<br /> keven
You'll need to post the full link to your imageshack upload, not just the filename.<br />
Hi again<br /> it's Keven<br /> I have been trying to teach myself in trying to control 12volt led circuit through the Arduino without success<br /> can you help<br /> I have included the circuit I have been trying to use and still with no avail<br /> where am I going wrong?<br /> I would appricate any help you can give<br /> i will wait for your reply<br /> keven

About This Instructable




More by origamiwolf:Solar Eclipse Viewer from Reading Glasses and Cardboard 5-minute, no-solder Bristlebot Dog collar from a lanyard 
Add instructable to: