Introduction: Pong Tennis With LED Matrix, Arduino and Joysticks

About: Hi, I'm an electronics, 3D printing and design enthusiast from the UK. I enjoy making fun projects based on 3D printing, Electronics, Arduino and Raspberry Pi and post the polished ones on Instructables.

This project is intended for beginners and experienced tinkerers alike. At a basic level it can be done with a breadboard, jumper wires and stuck to to a piece of scrap material (I used wood) with Blu-Tack and no soldering. However on a more advanced level it can be soldered to perf board or a custom PCB.

As this was a lockdown project I didn't have access to any many tools or materials hence why its stuck down to a piece of scrap wood that is slightly too small with Blu-Tack, however despite this it is a fun project that comes together quickly and is made up of commonly available parts that can be found cheaply online.

Step 1: Parts

To make the Pong Game you need;

  • 1x An Arduino (any type will work)
  • 4x MAX7219 8x8 LED Matrices
  • 2x Joysticks
  • 1x Piezo Buzzer (Optional)
  • 15x Female-Female Jumper Wires (3x groups of 5)
  • 15x Male-Female Jumper Wires (3x groups of 5)
  • 18x Male-Male Jumper Wires
  • 1x Breadboard
  • 1x 220Ω Resistor

Instead of an Arduino Uno or Nano board you can use a breadboard based Arduino with;

  • 1x ATmega328p 28pin IC
  • 1x 16kHz Crystal Oscillator
  • 2x 22pF Ceramic Capacitors
  • 1x USB FTDI UART Converter
  • 1x 100uF Electrolytic Capacitor
  • 1x Micro USB Breakout (Optional)

Tools;

  • PC with Arduino IDE (and LedControl Library)
  • Relevant USB Cable for your Arduino
  • Power Bank to power the game away from your computer

Step 2: Wiring

The wiring is very simple as all you need is jumper wires to connect the headers of the Matrices and Joysticks to the Arduino. The only complication is power as the Arduino Uno only has 3 GND connections and one 5v connection. This where the breadboard comes in and acts as a power distribution rail for all the components, If you are using a NANO the breadboard will serve the same purpose as well as allowing you to plug everything in.

For wiring follow these connections.

  • Left Joystick - GND and 5v to their respective power rails. SW - pin 9, VRx - A0, VRy - A1.
  • Right Joystick - GND and 5v to their respective power rails. SW - pin 8, VRx - A2, VRy - A3.
  • Rightmost LED Matrix - GND and 5v to their respective power rails. DIN - 13, CS - 11, CLK - 12. (As per line 25)
  • All the other LED Matrices can be daisy chained off the output of the first one going from right to left so the code works properly.
  • Optional Buzzer - Anode(+) through 220Ω current limiting resistor to pin 10, Cathode(-) - GND.

Step 3: Alternative Wiring

After wiring it with an Arduino UNO to save space I decided to put the Arduino IC from the UNO on the breadboard with a 16Mhz Crystal Oscillator and a pair of 22pF capacitors from each side to ground. I feel this was a worthwhile modification as it makes the project look neater and more finished however you do have to use a USB FTDI programmer to update the program.

Step 4: Code + Explanation

To upload the code to the Arduino download the LedControl library from GitHub here,

https://github.com/wayoda/LedControl and add the Zip file or add it through the Library Manager within the IDE. After that open the attached sketch, select your Arduino in the board and port settings under tools and upload it to the arduino.

Explanation

Line 1: Adds the library

Line 5-23: Sets up all the variables, constants and pin numbers.

Line 25: Sets up the LED Martix and sets the control pins and how many displays.

Line 27: Sets up the Reset Function.

Line 30-35: Shutdown function to turn on/off all the displays together.

Line 38-43: SetIntensity function to set the brightness of all the displays together.

Line 46-51: ClearAll function to wipe all the displays together.

Line 53-64: joystick Function to get the position of the joysticks, map them to the 7 possible bat positions for hitting the ball and then moves the bat to the new position.

Line 67-435: Function that moves the ball to the left player at the specified height and speed, checks whether the player hit it and either carries on and sets the crash status to true or bounces the ball back, adds 1 to the score and increases the speed.

Line 438-811: Function that moves the ball to the right player at the specified height and speed, checks whether the player hit it and either carries on and sets the crash status to true or bounces the ball back, adds 1 to the score and increases the speed.

Line 813-823: Function for displaying a Smiley Face, Tick, Cross or Question Mark to the specified display ( 0 on the right to 3 on the left).

Line 861-979: Function for displaying the numbers 0-9 to the specified display.

Line 981-1047: Function for displaying the score to each players side of the screen.

Line 1049-1064: Function to check if the player is ready.

Line 1066-1076: Setup Section of the code for the code that is run once when the program starts.

Line 1078-1136: Main Loop section for game logic where all the functions are used and where who wins is decided and then it restarts the program after 5 seconds of showing the score.

Step 5: Thanks for Reading

Thanks for reading this Instructable it was a fun lockdown project that came together over a couple days as I learned more about Arduino programming. If you enjoyed it feel free to vote for it in the Arduino contest.