Pong was the first video game to reach the mass market. For the first time in history, the concept of a «video game» was brought into the family home with the Atari 2600 — so it’s only right that we pay a little respect to this historic gem. Now you can live through it (by all accounts, rather boring gameplay), using Arduino and some common components.

I won’t lie — it’s unlikely your daughter will give up her Nintendo DS and it won’t provide hours of fun for the whole family — but this is an awesome and easy project to improve your Arduino code. And if you’re just getting started, don’t forget to check out our Arduino beginner’s guide.

We will make two main controllers, and the video will be output to your TV via a standard composite video cable.

To take this project to the next level, you can 3D print the case. YouTube user PotentPrintables did just that!

Arduino Pong Requirements

  • Resistor 470 Ohm x1
  • Resistor 1 kΩ x1
  • Potentiometer 10 kΩ ( variable resistor) x2
  • Arduino x1 (any version)
  • RCA plug x1 (if you have more than one, you can also connect audio. One for video is the minimum)
  • Button switch x1
  • Resistor ten kOhm x1

Arduino Pong

You can also download the TV Out Arduino library from here — get TVoutBeta1.zip latest release. Place all resulting folders in a directory /arduino/library and restart the Arduino IDE if it’s already open.

TV out testing

Take the RCA plug and remove the outer layer. Gather shielding, rotate and set aside. This is your land. There should be another cable with a plastic shield in the center — again, remove it so that you have a signal line.

Arduino pong game

Solder 470 and 1 kΩ resistors to the center signal line of the RCA plug — this provides the clock signal and the actual video signal combined to create an analog video input. A 470 ohm resistor should be connected to digital I/O pin D07, and a 1k ohm resistor should be connected to pin D09.

These pins are set by the library we’re importing, so you can’t change them. One of your Arduino GND pins should be routed to shield (outside) the RCA.

Arduino pong game

Now you can go ahead and download the example; although both PAL and NTSC are provided, this shouldn’t be a big deal on modern digital TVs — the NTSC demo worked fine for me despite being in the UK. Connect to your TV and you have a beautiful retro 3D cube. Oooooh yeah — are you still excited? I.

Arduino pong game

Test analog potentiometer inputs

Okay, we have TV out working, now let’s look at the controllers. The wiring of the «pots» is not so critical — each should have 3 pins, and the central one almost always produces an output signal. Connect this to A0 and A1 (one for each bank). On one of the side outputs — no matter which one — connect + 5V. The other pin on the other side should go to ground.

Here I put them both on the same breadboard because I only have short wires. For a polished product, you’ll need some old network cable to give you some distance (so you can actually sit on the couch to play).

arduino pong project

Next, download one of the basic example sketches that come with the Arduino — an analog input. This demo will flash the built-in LED faster or slower depending on the input on A0.

It doesn’t test another bank of A1, but if you set up A0 correctly, I don’t see how you would make a mistake on A1, so let’s assume that’s all good and move on.

Add start switch

Finally, we will add a start switch on D02. Refer to the wiring diagram here for instructions on how to do this. This switch will be used to launch the game when in the menu.

arduino pong project

Code Pong

We use the code originally written Lamonica modified duboisvb for two players and updated by me to use the latest beta version of the TV-out library. You can view and download the code from this embed.

This is quite a long but simple code that doesn’t require any explanation from me. Like most games, it depends on the game state (menu, in game, game over) and reads the input values ​​of both controllers and switches every iteration of the loop. Apart from this, there are methods for drawing screen, ball, paddle and game logic.

arduino pong project

Note that the code also includes audio output : I couldn’t find any more RCA connectors to test this, but if you have them, plug the signal pin directly into D11 and you’ll get some nice retro tones.

Arduino Pong

To be honest, I didn’t know the Arduino could even go to TV without some extremely complex coding; The TV Out Library makes this really easy. Even if you’re not into retro gaming, using this basic TV out is a great way to use your existing hardware as a cheap monitoring device. You can, of course, output the color.

Do you think you’ll try Arduino Pong or make your own remake of a retro video game? Let us know in the comments if you have!

Похожие записи