It is really fun to try to hit a target with a ball and is fun to play it as a game. So, in this Instructable I'm going to show you how to make a nice game which I have made. In this game you have to try to hit a target with a table tennis ball (Ping Pong ball) as many times as you can in 30 seconds. Every time you hit the target you get a point.
I have also built a UI by using "Processing" to display the score.
By the way, this is my first Instructable, so feel free to give suggestions on how I can improve in the future.
Step 1: How the Game Works
The game mainly consists of a cardboard target that you hit with a ball (A Table Tennis/Ping Pong ball - which I will simply refer to as the "ball" in this article). The target works like a switch. When the ball hits the target it closes a circuit, sending a HIGH signal to an Arduino. When the Arduino detects the HIGH on its pin, it increases the score and sends the score to the computer. Using "Processing" the score is shown immediately.
When the game is over (at the end of 30 seconds), the Arduino sends relevant messages which are then shown on the computer screen through "Processing".
Step 2: Material Needed
1 X Arduino (I used Uno)
1 X Piezo Beeper
1 X 10k ohm resistor
Single stranded wire
1 X Table Tennis Ball (Ping Pong Ball)
1 X 18*18 cm piece of cardboard (you can cut it out from a cereal box)
2 X 4*18 cm strips of tinfoil (you can use kitchen aluminium foil)
Step 3: The Target
The cardboard piece, folded in half, is the target that you would eventually hit with the ball. In the natural position, the two flaps would remain "open", that is, they will make a V shape. When the ball hits it, the flaps will close. You would be attaching the tinfoil to the inside of the two flaps so that they will make a contact when the flaps close. When the flaps close and the tinfoil pieces make a contact, Ardunio will get a signal which will be used to adjust the score.
Step 4: Making the Target
Step a) Take the 2 cut out pieces of tinfoil and stick them to the two ends of the cardboard with tape. Make sure you stick the tinfoils on the same face of the cardboard, but two opposite ends - in such a way that if the cardboard is folded in half and pressed, the two tinfoil surfaces will touch each other (refer to fig1).
Step b) Take one fairly long (roughly 1m long) single stranded wire. Cut open the insulation from the ends. Attach one of the ends to one of the tinfoil (I just stapled it, but you can do the way you prefer). Leave the other end as is (it will later be connected to Arduino). Take a second single stranded wire just like the first one and repeat the same process - this time attaching it to the other tinfoil (refer to fig1).
Step c) Fold the cardboard piece in half (ensuring the tinfoils are "inside" and can touch each other when pressed) (refer to fig1). Now, we want to ensure that that in its natural position, the two flaps would remain "open", that is, they will make a V shape. Do this using a piece of string. You can simply loosely wrap it around the folded cardboard and stick it using the tape so that it won't slip off. Ensure that the tinfoils don't touch each other when the folded cardboard is left in its natural position. Ensure that the flaps will close making the tinfoils touch each other when a small force gets applied (such as when it is hit with the ball) (refer to fig2, fig3).
Step 5: Setting the Arduino
Now for the Arduino connections.
Connect the two wires from the target to 5V and pin 12, also connect a 10k resistor between pin 12 and Gnd (pull down resistor). Connect the beeper to pin 13. Please refer to the diagram given above.
Now unzip the file named TTGamev3.zip. It contains the code for Arduino with its folder. Open TTGamev3.ino and upload it to your board. You might get an error saying that it can't recognize #include. If that happens, then click on sketch \ include library\ manage libraries.There on the top left side you will see a drop down menu called topic, click on it and select timing and enter. Scroll down to the 13 library and install it then the program will work.
Step 6: The UI
The terminal which the Arduino provides is good for debugging but not so good as a UI. So, by using the "Processing" language, we will build a UI. The UI will tell when the time starts, the score, also it shows the score visually by showing as many number of balls as the score.
Download processing at this website https://processing.org/download/?processing
Download the file TTUIv2.rar , unzip it and open TTUIv2.pde.
IMPORTANT NOTE: In the code on line 16 you will see: MyPort = new Serial(this, "COM5", 9600);
Now my Arduino is on COM5. Enter in your Arduino's COM(In capital letters).
Step 7: Running the Game
Connect to your Arduino with the USB wire. Hit run at the processing code, after a few seconds a black window will appear . After 5 seconds the beeper would beep and the screen will say "start" (the 5 seconds are there to give you time to get ready). Start hitting the ball at the target. Each time you hit the target, there will be a beep and your score will be updated on the screen. After 30 seconds (when the time is up), there will be another set of beeps and the screen will also show the final score.
ENJOY!!! Also, please let me know if you make any interesting changes.