Google+ Facebook Twitter Pin It Reddit

My Story

Arduino Exploration

Building the Connect Four Arduino Video Game

By Teague Chrystie

Something drew me to Arduino. I knew nothing about programming or electronics but I bought a beginners guide and set off to develop an electronics project that combined resistors and code, circuit boards and debugging, motors and scripts. I would set up the circuit and tell it what to do. Arduino, the intersection of coding and electricity, would handle the rest. And for my first project I decided to bring to life a childhood favorite... Connect Four.

This is my journey...

Step One: Decide on an idea

I began the process by defining the scope of the project to a few key requirements. I would focus on a video game with minimalist gameplay and a minimal control surface. I combined those characteristics with my knowledge of woodworking and soon decided to create an antique video game. And while I have little connection to Connect Four — I'm not even good at the game - I found my end goal. I could create a great CGI rendering of the game but had little knowledge of how to proceed in real life.

Arduino Video Game

Step Two: Research, research, research

I buried myself in a beginner's guide to Arduino and dove into Google results to figure out where to start. The Arduino manual led me to LEDs, which would play a big role in this device. A normal Connect Four board features a 7x7 grid, but I would need to do more than light up all 49 LEDs at the same time. Rather I needed to rig the grid so that each of the 49 lights could be turned on individually. More importantly, each of those 49 LEDs needed to be able to send three distinct signals — red, blue and green. In essence, each turn would require 147 signals. Connect Four was a dumb choice, I thought.

Step Three: Fixing the first problem

Unfortunately, rigging 147 signals was the least of my worries. The Arduino Uno's voltage input/output terminal numbers made sure of that. While I could run a wire from each I/O terminal to an LED with, perhaps, 15 LEDs, I would never succeed with the number I needed. For about a week, I struggled to figure out how to solve the issue. That's when I discovered Neopixels, which look like Christmas lights but function as a chain of microchips. In a sense, each Neopixel is like its own Arduino board. Even better for my project, Neopixels can differentiate between Pixel 1 and Pixel 2. So, instead of sending signals to each light individually, I could send signals for all lights into Pixel 1, which would then take the first signal and pass the rest along. I would need only four wires — a red one for power, a blue one for ground, a green one for timing and a yellow one for data. The first time I tried out this potential solution, it worked.

Arduino Video Game

Step Four: Facing the computer

After I ordered the Neopixels, knobs, on/off switch and other needed parts, I looked to the road ahead. Though the knobs fit snugly and the button looked good, I knew I still needed to make a grid of Neopixels, mount the knobs, buttons and toggles and solder various parts. But the most daunting part remained: I needed to teach a computer to play Connect Four.

With no prior experience with code, I knew there were several options to proceed. I quickly ruled out cutting strings of lights into sets of seven. Instead I set up a grid with [rows][columns] for horizontal/vertical, starting from the bottom left corner — so [1][1] would mean "bottom left," [7][7] would mean "top right," [1][7] would mean "top left," and so on. Meanwhile, with a set of instructions, I could tell the Arduino to light up pixel "[7][1]" and it would automatically translate that to "Neopixel 0."

Once turned on, the pixel matrix would display a big "P1" for player one, and three little knobs would be adjusted RGB-style to change P1's color. Once settled upon, player one would press the big red button, and the screen would provide the same opportunity for P2; then, once the big button was pressed again, the game would start. The gameplay would involve a single indicator light at the top of the screen, showing the color of the current player, which could be moved from left to right using a big twisty-knob. Once the light was placed over the desired column, the player would mash the big red button, and that light would "fall" down into place as if it were a tile in a Connect Four frame. The indicator light would re-appear, this time in the other player's color, and the "select, drop, alternate" process would repeat until somebody won.

As I spent more and more time coding, I began to understand the Arduino programming language quite well. I used small pieces of logic to explain to the computer when to let the "tile" drop, when to make them stop and how to let a player win. And, in turn, I was winning my fight to develop a working Arduino system.

Facing the computer

Step Five: Building the box

I knew I could do without a doubt. I drilled holes in a box, attached the knobs, temporarily put in the Neopixels, treated the wood and saw this project come to life. I developed a logo and stained the wood to create an antique look, I was close to the final product. I had my shell, my lights and my code — now I just had to put it all together.

Building the box

Step Six: Let there be light

I needed to take the 120 volts of alternating current from an outlet and transform it into the 5 volts of direct current I needed to power the device I named the CoFoiNo.

The Arduino and the Neopixels are both getting their power straight from the source, in the form of the solid red line. The Arduino takes its share of charge, uses some of it to do its Arduino-ing with, and then uses the rest to power any peripherals it's attached to.

So, Arduino provides power, power goes into button, button is pushed, power is looped back into Arduino. Right? The Arduino measures that signal digitally, which is to say it's only accepting two answers: "on" or "off." Makes sense for a button. Meanwhile — Arduino provides power, power goes into knob, some amount of power gets shaved off and sent to ground, and whatever's left over is looped back into the Arduino.

Once the Arduino has this information — "hey, is the button being pressed?," "hey, how much red, green, and blue is being asked for?," "hey, where's the tile-dropping knob at?" — it can fill in all the variables it needs to run the Connect Four program, which means it's ready to go.

Using an Arduino Pro Mini, which is roughly the size of your Enter key, I got to work soldering. The Arduino could go almost anywhere, but the main question was how best to connect the Neopixel cable to the circuit board; wherever a floppy thing meets a rigid thing, you can count on a point of failure coming to join. I decided the solution would be headers — male headers on the board, female headers on the NeoPixel cable.

The rest of the process — attaching wires, installing resistors, placing more headers — took time but I found answers to minor problems. Soon, I had finished the circuit board. And suddenly, all that was left was to hook up the circuit to the power source and solder the output wires to their controls.

After two months, I was finally ready to plug the machine into a wall socket and flip the switch. And of course, it didn't work. But after one final round of troubleshooting, the CoFoiNo came to life.

On a whim, I moved from a place of no knowledge of circuits or code to a working prototype.

Note from the Author

Here's the article as it's hosted on my website, including the complete manuscript and some of the photos, plus a nice YouTube video demonstrating the finished project. In addition to that, here's the text-only manuscript as a PDF and in RTF, and here's all of the photos I processed.
Teague Chrystie is a visual effects artist living in Los Angeles, California, where his time is mainly divided between three things: days of work on television and movies, nights of work on creative projects at home, and a life of constant cahoots with his girlfriend and favorite living scientist, Cloe. When he's not accidentally soldering himself to things and pretending it was deliberate, he enjoys writing musicals, twisting balloons, throwing unhinged theme parties, and trying to figure out how everything — life, the universe, and all of it — works.