Introduction: Arduino Based Bi-color LED Matrix Pong Game

We have created two game project instructables so far using the jolliFactory Bi-color LED Matrix Driver Module D.I.Y kits we designed. This LED Matrix module is designed to be chain-able so you may daisy-chain the modules together to the number of modules you need to suit your project.

You may check out these two game project instructables with the links below:

Project to build a 2 LED Matrix tall Tetris game can be found at https://www.instructables.com/id/Arduino-based-Bi-color-LED-Matrix-Tetris-Game/


Project to build a 2 LED Matrix tall Snake game can be found at https://www.instructables.com/id/Arduino-based-Bi-color-LED-Matrix-Snake-Game/

Pong is one of the first computer games ever created. We came across a couple of Pong game projects built using potentiometers to control the paddles. Potentiometer is not expensive, easy to work with and thus is a great choice as an input device for Pong game projects.

We have a few of these interesting Rotary Encoder - Illuminated (Red/Green) purchased from Sparkfun lying around for quite a while. As of writing this instructable, this part is available from Sparkfun (Part number: COM-10596) for U$2.95. You may check this part out at https://www.sparkfun.com/products/10596

For this instructable, we will be building yet another Pong game using two of the Bi-color LED Matrix Driver Modules daisy chained together driven by an Arduino Nano. Here, we will be using the Rotary Encoder - Illuminated (Red/Green) as the input device to control the game paddle.

Rotary Encoder is much more challenging to implement as an input device as compared to the humble potentiometer. However, we would like to experiment with something new here and hope that those who have not dabbled with rotary encoders before will learn more about them.

To build this project, basic electronics knowledge with electronics component soldering skill and some knowledge on using the Arduino are required.

You may view the following YouTube video to see what we are building.

Step 1: Overview of Rotary Encoder

Rotary encoder may look like a potentiometer but they are totally different components.

There are two main types of rotary encoders: absolute or incremental encoders.

Absolute Encoders output the rotational angle using an absolute code. The rotational position can be detected by reading the code.

Incremental Encoders output a pulse string according to the rotational displacement of an axis, and information such as speed, distance, and relative position could further be derived from it.

The rotary encoder we will be using here is an electro-mechanical, incremental (24 pulses) component that has full shaft rotation which can turn infinitely with no end stops unlike potentiometers (some potentiometers do come with no end stops). It is especially cool because it has a red/green LED built in, as well as a push-button which can be activated by pressing on the rotating shaft end. It is designed to be a PCB through-hole component and not panel mountable or suitable for breadboard prototyping (unless you do not mind bending the pins apart and cut/bend the two mechanical side tabs).

The device has 7 pins - three on one side and four on the other. The side with three pins is for the encoder: signal A, ground (labelled as C), and signal B. The side with four pins is for the push-button, Red LED and Green LED.

The two encoder outputs A and B, are called quadrature outputs, as these output signals are 90 degrees out of phase.

Check out article at http://bildr.org/2012/08/rotary-encoder-arduino/ for detail on how we use these encoder outputs to manipulate the game’s paddle.

Step 2: Building the Arduino Bi-color LED Matrix Pong Game

We will be building a two LED Matrix long Pong game here driven by an Arduino Nano. This project uses two of the Bi-color (Red and Green) LED Matrix Driver Module kits from jolliFactory. Each of these modules uses two MAX7219 Display Driver ICs to drive a Bi-color LED Matrix. These ICs are excellent because they take a lot of work off the micro-controller and simplify the wiring and logic design.

You can find this Bi-color LED Matrix Driver Module kit from here

This kit comes with all through-hole components and someone with basic soldering skill should be able to assemble it without much difficulty.

See the following YouTube video on how to assemble the LED Matrix Driver Module Kit:

For the game audio, we will be using an 8 ohms 0.5 watt speaker to be driven directly from one of the Arduino’s digital pins through a 100 ohms resistor. Basic sound tone is used for this project and sound volume should be sufficient for a hand-held game with this simple setup.

One incremental rotary encoder is required to manipulate the Pong game paddle.

Step 3: Wiring

After all the kits are completed, they are connected together with the micro-controller as shown below (LED Matrices not installed for better view). We use one 8 ohms, 0.5W speaker for the game audio output and one rotary encoder for game control. One Arduino Nano is used here to drive the electronic circuit setup.

Note the use of a 12Kohms pull-down resistor on the LOAD input pin. When power is first applied to the micro-controller or when they are reset, their I/O lines float. The MAX7219 can see this as valid data and display garbage until the micro-controller gains control. The pull-down resistor mitigates this issue.

Except for the two Bi-color LED Matrix Driver modules, we hook up the entire circuit on a small piece of perf-board around 60mm x 60mm.

See our completed circuit on perf-board. Note that the rotary encoder is not able to be properly mounted onto the perf-board as the encoder pin positions are not perf-board and bread-board friendly and we have to cut away the two mechanical side tabs.

We at jolliFactory have come out with a bare interface PCB board to build this project if you prefer not to mess around with too much wiring. The interface PCB board is also suitable for building some of our other instructable projects. If you are using this interface PCB board for some of our older instructables with speaker for audio output, do remember to change the digital pin from D9 to D8 in the sketches downloaded from these instructables to drive the speaker.

You may find our bare interface PCB board at https://www.tindie.com/products/Nick64/jf-interface-board-1-bare-pcb-board-with-headers/https://www.tindie.com/products/Nick64/jf-interface-board-1-bare-pcb-board-with-headers/.

See the completed circuit built using the interface PCB board. Now the rotary encoder fits just right on the PCB.

Notice there is a transistor soldered at Q1. For this project, there is no need for this transistor. However, if you need higher volume for the speaker, you may solder a 2N2222 transistor at Q1 and a resistor at R1 (100 ohms and above) and then connect the speaker instead to J6 via another 100 ohms resistor. This is a very rudimentary method just to increase the volume of the speaker for simple beeps and sounds. For better sound quality, you may like to employ some kind of audio amplifier circuit in your design.

Step 4: Programming the Arduino Board

For this project’s arduino sketch, to display the scrolling message, we adapted the codes from one of our instructables. You may check the project out at https://www.instructables.com/id/Arduino-SPI-7-Bi-color-LED-Matrix-Scrolling-Text-D/

To control the game’s paddle, we adapted the code for the rotary encoder from the article at http://bildr.org/2012/08/rotary-encoder-arduino/


The Arduino board needs to be loaded with the Arduino sketch to run the display.

We used Arduino IDE V1.03 for our project. Download the Arduino sketch below for this project.

Download jollifactory_Pong_2LEDMatrix_SinglePlayer_V1_0.ino

The Pong game sketch we have here is quite basic without any game levels. You may amend and enhance the sketch to your liking.

Step 5: Enclosure and Assembly

As this project is also simply built for the FUN factor with no intention of using it for long, we did not build a proper enclosure for it.

What we have here is just a blue tinted acrylic protective cover with a hole for the rotary encoder shaft protruding out for game control. We did not even secure the modules to the enclosure as they fit quite well in the acrylic protective cover.

The pictures show the various stages of assembling the sub-modules together.

Comments

author
thappasahil (author)2016-03-16

Do you have the code for the single colored matrix as well?

author
jefyjefin (author)2014-12-12

nice one. i would like to do this for exhibition

author
Veda88 (author)2014-10-27

Hi, do you have schematics of the pcb?

Thanks!

author
Veda88 (author)jollifactory2014-10-27

I see, thanks, but that is only the controller board. I am also missing schematics for this module:
https://www.tindie.com/products/Nick64/60mm-x-60mm-bi-color-led-matrix-driver-module-diy-kit/

author
jollifactory (author)Veda882014-10-28

Not exactly a schematics for the LED Matrix module PCB but should provide you with sufficient info on the PCB wiring connections. Check out the block diagram for the PCB from

http://jollifactory.blogspot.sg/2013/08/bi-color-led-matrix-driver-module-diy.html

author
ibenkos (author)2014-10-18

Smart idea! Thanks for shearig :)

author
MsSweetSatisfaction (author)2014-10-18

Wow this is so neat! I love the concept of updating an old game! Thanks for sharing!

About This Instructable

15,543views

135favorites

License:

More by jollifactory:IKEA Frame Hack > sLOMO (Slow Motion) FrameJolliCube Audio/Music VisualizerJolliCube (8x8x8 LED Cube) with MD_Cubo library
Add instructable to: