Motion Pong: Li-Dar Controlled Pong Video Game.

by jpderouin in Circuits > Arduino

272 Views, 1 Favorites, 0 Comments

Motion Pong: Li-Dar Controlled Pong Video Game.

IMG_8929.jpeg
Final project Digital drawing.jpg
IMG_8921.jpeg

Created by Jake Derouin and Charlie Nevitt.

Video Demo: https://youtu.be/D977ZQ7Td8E

Motion Pong is a take on the classic video game Pong with the twist that player’s control their paddles using two Li-Dar sensors. Pong is regarded as one of the first ever video games to garner mainstream attention having been released in 1972. In Pong, two players take control of paddles (or bars) on each side of the screen and attempt to hit a ball through the other player’s side of the screen to score a goal. With each successful goal, players can rack up points. In most versions of Pong, players control their paddles with either a physical button, knob, or joystick. In Motion Pong, we shook up the control scheme to allow players to control their paddles by waving their hands in front of a couple of sensors allowing germ free play between any random passerby.  

 

We created Motion Pong with the purpose of bringing the widely familiar Pong experience to a more public and crowded setting like how the original Pong video game was originally delegated to arcade locations only. Specifically, we aimed to create a way for students in our department building to be able to instantly start a game of Pong with their friend’s while also preventing the device from becoming a biohazard due to being in a high-touch environment. By using a unique control scheme with li-dar sensors, we were able to make this goal a reality. 

 

We built this project using an Arduino Nano Every, a laser cut acrylic box, two VL53L0X micro-Li-Dar sensors and a clickable button. The laser cut acrylic box has four holes in it, two for each of the micro-Li-Dar sensors, one for a button to reset the scores to zero, and one for a USB cable connecting the Arduino to the computer. The Motion Pong game was programmed in JavaScript on the p5.js website and the Arduino based code was programmed in C++ on the Arduino IDE (code download links are available below). The Arduino and p5.js were able to communicate with each other via the P5 Serial Control application (running on macOS for this demo). 


Once the project was completed, we were able to put the project on display in the Roser Atlas building at CU Boulder for other students and staff to play. Players would start a game by pressing the reset button and place their hand in front of one of the Li-Dar sensors to move their bar/paddle up and move their hand away from the sensor to bring the bar/paddle back down to the bottom of the screen. The audience loved the unique and control scheme of the game and we were able to step away from our project and watch multiple groups of students figure out how to work the device on their own. In the future we would like to make the paddles move at a distance determined by how far their hand is away from the sensor rather than moving up if a hand is detected and down if not.


Download Links:

Arduino Code: https://gist.github.com/jpderouin/294479875698429c9806bdaea724824c

p5.js Motion Pong Gamę (use a Chromium based browser to access): https://editor.p5js.org/Elirach/sketches/g88vpsdqR

p5 Serial Control App Download: https://github.com/p5-serial/p5.serialcontrol/releases/tag/0.1.2 (The Darwin version is the macOS version).

Special thanks to Robojax for creating a helpful resource that was used to get multiple Li-dar sensors working with the Arduino. This resource can be found at: http://robojax.com/learn/arduino/?vid=robojax_VL53L0X_multiple

Supplies

images.png

Materials Required:

1 x Arduino Nano Every Microcontroller

2 x Micro Li-dar (time of flight) sensors (we used GYUL53L0X but other small form Li-Dar sensors such as VL53L0X should work as well).

1 x 10K Ohm resistor

1 x push button switch

1 x laser cut acrylic box of 4in 3in and 3in dimensions (could be substituted for another material/box size if needed).

1 x breadboard

1 x breakout board

Wires to connect Arduino board to Li-Dar sensors and push button switches. 

Hot Glue.

Computer to run p5.js in browser as well as the p5 Serial Connect App.


Materials Used for aesthetics (optional):

Paint and Spray Paint

Shoebox (for elevating the computer running the p5.js game)

Ping pong ball


Building the Enclosure

Final project Digital drawing.jpg
IMG_8935.jpeg
IMG_2715.png
IMG_8916.jpeg
  1. Find a comfortable distance for both players to put their hands on top of Li-Dar sensors. For us, these ended up being 14 inches apart. See the diagram above for an idea on how users will interact with the enclosure.
  2. Make sure the dimensions of the box can hold the breadboard (2.5 inches).
  3. Find a proper material to use and measure the width for the teeth of the box (.215 inches). We used an acrylic material
  4. To laser cut out box, we measured our box to be 12 inches long, 3 inches wide and comfortably 3 inches tall with a material width of .215 inches, and put these parameters into MakerCase to generate an SVG file.
  5. With the SVG file, laser cut 4 more holes in the box in these locations:
  6. 2 holes for the sensors on the top piece (adjust the size of the holes to accommodate your particular Li-Dar sensor size).
  7. 1 hole for the reset button also on the top piece. (adjust for your particular switch size).
  8. 1 hole for the Arduino USB cable in the center of one of the side pieces. (adjust for fitting a microUSB cable through).
  9. If desired, this is the optimal time where you should paint your enclosure for aesthetic purposes. We spray painted ours black. Ensure that the paint is dry before continuing. 
  10. Assemble the box by hot gluing the corners of each of the pieces to one another. DO NOT GLUE THE TOP PIECE YET (we need this to be able to come off to place in the electronics

Building the Circuit

IMG_8910.jpeg
FNN07MOLBM8LMAO.jpg
Motion Pong Arduino Schematic new export.png
IMG_8905.jpeg

We will now begin building the circuit.

  1. Attach your Arduino Nano Every to a breadboard (preferably half-size with around 30 rows of pin holes). 
  2. With the two Li-Dar sensors, solder wires onto the VIN, GND, SCL, SDA, and X ports on each of the sensors. Ensure that the little black square on the sensor is facing away from the wires (this is the part that measures distance).  
  3. IMPORTANT: Remember to take into consideration the length of the wire needed to attach your sensor from the breadboard that will be placed in the base of the enclosure to the sensor holes in the enclosure. If in doubt, use a longer wire. It is also recommended that you use distinct wire colors for each port and that you repeat that color scheme on the second sensor to prevent later headaches and confusion.
  4. After soldering, connect the wires from BOTH of the sensors to the arduino in the following manner: VIN-5V, GND-Ground, SDA-A4, SCL-A5.
  5. Now connect the X-Pin on one Li-Dar sensor to digital pin 6 and the X-Pin on the other sensor to digital pin 7.
  6. EXTRA HELP: If you are having trouble connecting the sensors correctly please check out this helpful video by Robojax: https://youtu.be/0glBk917HPg
  7. Before continuing, test that your Li-Dar sensors are working properly. 
  8. Download the Arduino Motion Pong code with the link in the project description.
  9. Connect your Arduino to your computer and run the downloaded code on your Arduino via the Arduino IDE. 
  10. Open the serial monitor in the Arduino IDE and verify that you are receiving distance outputs. The numbers should change based on how far you or an object is away from the sensor. 
  11. Troubleshooting: If you receive a message in the serial monitor that says one of the sensors failed to boot, please check your solder job and make sure that your wiring is secure to the sensors and the Arduino.
  12. Take your push button switch and place it on a small breakout board (preferably an area slightly larger than the base of the switch). 
  13. Using wires that are long enough to reach your breadboard and the hole for the switch on the enclosure, solder wires onto the switch breakout board.
  14. Connect the switch to 3v3 and digital pin 12 on the Arduino. 
  15. Add a pulldown 10K resistor connecting digital pin 12 to ground. 
  16. ATTENTION: The following steps need to be done with extra care to ensure that no connections are broken.
  17. Carefully place your breadboard with your Arduino into the base of the enclosure. 
  18. Thread a microUSB cable into the enclosure via the singular cut hole on the side of the enclosure and connect it to your Arduino. 
  19. Stick your sensors to the roof component of the box so they face upward towards the ceiling through the two sensor holes (we used tape reinforced with hot glue to secure the sensors). 
  20. IMPORTANT: Ensure that nothing is blocking the black square on the Li-Dar sensors. 
  21. Similarly, carefully stick the push button switch to the top of the enclosure with the switch facing upwards towards the ceiling. 
  22. Place the roof component on the box (do not hot glue it until you are sure your wiring is correct and secured).
  23. Test your Li-Dar sensors as done in step 5 (you should also see the word “RESET” appear in the serial monitor upon pushing your switch).

Connecting Your Arduino to Motion Pong

Screenshot 2022-12-14 at 10.00.26 AM.png

Now that we have the Arduino working, we can connect it to Motion Pong on p5.js

  1. Download the p5 Serial Control App with the link in this project summary.
  2. Open the p5 serial control app and select the port of your Arduino. 
  3. Select the “console enabled” checkbox. You should see your Arduino’s Li-Dar distance measurements in the text box. 
  4. Troubleshooting: If you are having issues with seeing your Arduino’s output or opening up the correct port, please make sure you have closed the Arduino IDE’s serial monitor.
  5. Next go to https://editor.p5js.org/Elirach/sketches/g88vpsdqR on a Chromium based browser.
  6. In the code, look for the following line: “var portName = '/dev/tty.usbmodem2101';” and change the portName to match that of your Arduino port number displayed in the p5 Serial Control app.
  7. Press the play button. You should now be able to control the pong paddles by moving your hand near the Li-dar sensors to move the paddles up and by moving your hand away the paddles will move downwards.
  8. GO HAVE FUN and please feel free to share these instructables with your friends.