Introduction: Ball Launcher With Temperature Sensor

Previously we had created a CPX Wearable to function as a temperature sensor and timer, and the CPX Device could be secured into the wristband. This time around we wanted to change the wearable aspect of our project, and add a ball-launching feature, but still keep our sensor functionality from before. We wanted to keep the temperature sensor functionality because it was expandable and improvable so we researched that. We also wanted to incorporate a servo motor, this lead us to a tutorial by Adafruit. Adding the temperature sensor onto the ball launcher is doable and provides improvement to the ball launcher.

Supplies

Circuit Playground Express CPX: https://www.adafruit.com/product/3333

USB Cable: https://www.adafruit.com/product/592

Servo: https://www.adafruit.com/product/2442

Wheel: https://www.adafruit.com/product/2744

CD DVD Spindle: https://www.adafruit.com/product/3882




Physical Materials:

  • Some large pieces of scrap corrugated cardboard
  • Scissors and/or box cutter
  • Hot glue & hot glue gun
  • Ping pong balls
  • Alligator clips

Step 1: Install Mu Editor / Configure Circuitpython

Mu Editor Download: https://codewith.mu/en/download

1. Once you have installed the MU Editor, open it and select Circuit Python

2. Connect your CPX Device to your computer

3. On the CPX Device, press the reset button twice (It may take a few tries)

4. Once you do it right the lights on the CPX will blink, and there should be a new drive on your computer called CIRCUITPY

5. In the Mu Editor, select load on the top bar, then the CIRCUITPY drive, then code.py.


This is the file to edit for any code you want to run on the CPX device, selecting save also found on the top bar will save the code and upload it to the CPX



Step 2: Write Temperature Sensor Code in the Mu Editor

For writing the temperature sensor code, it is important to not only try and detect a wide threshold of temperatures but also display it in an efficient way. We decided to use the CPX neopixel lights, but people could use sound if they wanted to or explore other options.


  1. In the code, at the top of the file add the "import from adafruit_circuitplayground import cp"
  2. This allows the user to access the temperature from the CPX device by using "cp.temperature"
  3. Once you have access to the temperature, you may set thresholds/ reactions as you like using if statements
  4. Store the value you get from "cp.temperature" in a variable, and compare it to your desired amount.
  5. For incorporating the neopixel lights use "cp.pixels[x:y] (or [x])" and then set the RGB value with a list of integers multiplied by the number of lights you are turning on (Example: [(255, 125, 0)] * x)
  6. We recommend importing the time module as well and using the "time.sleep(x)" function to set an update rate for the temperature.


(Our temperature code can be downloaded below)


Attachments

Step 3: Ball Launcher Assembly

Once you have materials like cardboard and the hot glue gun, you can start assembling the launcher.

  1. Cut 4 symmetrical pieces for the handles, cut 1 for the back platform, and get 2 tubes for the load/launching tube.
  2. Start by assembling the launcher together, connect the handles to the back platform and front tube, and then add the tube off of the top for loading.
  3. After you have assembled the launcher, add the connector from the circular piece on the servo to the mechanism to push the balls at the base of the front tube.
  4. When connecting the servo, configure the wires in the orders seen in the picture (Vout -> Middle, Ground -> Left, A2 -> Right) and then secure the CPX device to the side of your launcher or wherever you want it.

Step 4: Write Servo Code for Launcher

This code is to be written in the same file as the temperature sensor code

  1. In the same code.py from before, use "from adafruit_motor import servo"
  2. Also, import "pwmio" and "board"
  3. In your while True loop, add "my_servo.throttle = 1.0" to make the servo move. You can add logic to make it move after certain conditions, possibly reliant upon temperature, button input, or other things.