In this game, players will try to land a ping pong ball into a cup. Make five points to win. The score is tracked using a light sensor, or more specifically a phototransistor.
This experiment can be created without the Education shield. You can download the schematics here, and the Fritzing original files can be found in this Github repository.
Attach the shield onto the top of the board.
Connect five LEDs across the breadboard gap.
Connect a 220 ohm resistor to digital pin 2. Then connect the resistor to the long leg of the first LED.
Connect each of the digital pins 3 through 6 to a corresponding LED following the same method.
Connect the short legs of the LEDs to GND.
Connect the piezo speaker across the breadboard gap and connect one leg to digital pin 8 (it does not matter which one), then the other one to GND.
Connect the light sensor module to the analog module connector, A1 on the shield.
Use the module cable to connect the module to the shield.
Get some tape, scissors and a plastic cup.
Cut a hole in the bottom of the plastic cup so the light sensor fits.
Place the light sensor in the hole.
Tape the sensor to the cup.
Make sure that the sensor is exposed through the hole in the cup.
Check that your wiring is ready and connect the board to the computer.
Find the example LightSensorTest program and open it. You can use this program to calibrate the light sensor and set the threshold value.
Upload the program to the board.
Go to the Serial communication reference and learn how it works. Then open the Serial Monitor.
Check the sensor value when the ball is not in the cub, and write it down.
Place a ping-pong ball in the cup, over the light sensor. Write down the covered value. Average both numbers (uncovered and covered ) for threshold value.
Now that you know the uncovered and average, check that your wiring is ready and connected to the computer.
Find the Basketball program and open it.
Find the syntax line sensor.config( uncovered , threshold ), changing the values in the parameters to the uncovered value and threshold value respectively. Then upload the program to the board.
Time to play basketball!
Find LightSensorTest in File>Examples>EducationShield>Help>LightSensorTest and the game code in File>Examples>EducationShield>Block2-Sports>Basketball