uoitlogo
Creating with Arduino
arduino_colours

Pong Game

    This version of pong uses a potentiometer as a controller for each player and pushbutton that starts the game. It makes use of Processing to take the inputs from the Arduino and display the result as a game.
pong_game_schematic
This device takes the analog input of each potentiometer and converts it so that it moves a paddle across the window of the game. It has both an Arduino code component and a Processing code component. It demonstrates how to read Serial data in Processing that has been printed by the Arduino. Each input created by the Arduino starts on a new line and has a certain indicator to show processing what input it is. For example, each input from player one begins with “Player 1:” and then the input. This is done so processing can separate the various inputs. It is important to note that the processing code must include the proper serial port of the Arduino being used. This variable can change from one computer to another and should be adjusted accordingly. The example code uses COM4 but this may need to be changed.
This code also makes use of the mapping function in Processing. The map function takes the input from each potentiometer, which varies from 0 to 1023, and converts it to data ranging from 0 to 360 so that the paddle spans the range of the window only.

pong_game_breadboard
Component Quantity Description Where to Buy
10 kΩ Resistor 1 Canada, USA
Potentiometer 2 Canada, USA
Insulated Wires ~12 Kit or M/M Cables
Push Button 1 Canada
Arduino Uno 1 Board with Accessories
step1
First, the Arduino 5V is connected to the bottom row of the bread board and the ground is connected to the row above that. Then first potentiometer is added. The left pin is connected to ground (GND), the center pin is connected to the Arduino analog pin A0 and the right pin is connected to 5V.
step2
The Second potentiometer is added in a similar fashion. The right pin is connected to GND, the middle pin is connected to analog pin A1 and the right pin is connected to 5V.
step3
Finally the push button is added. The left pin of the push button is connected to GND with a 10kΩ resistor and connected to Arduino pin 2. The right pin of the push button is connected to 5V.
step4
To setup the game, first the Arduino code should be run, followed by the Processing code should be run. A window should appear similar to the one on the left.
And game-play should look similar to this:
step5
step6

Source Code: