Introduction: Gumball Machine

To build our 3D-printed gumball machine, we first designed the main body in Tinkercad, including the slot where the candy would be dispensed. We created a compartment for a servo motor so it could rotate and open the dispensing slot whenever it was activated. After printing the parts, we assembled the machine and tested how well the servo moved the opening. In phase 2 of the project, we improved the design by making the entire gumball machine larger so it could hold more candy and operate more smoothly. We also upgraded the code by switching from Adafruit Maker Code to CircuitPython, which gave us more control and allowed the servo to run with smoother, more reliable motion.

Supplies

Step 1: Download

  1. To download the gumball machine design from Tinkercad, open the project and click the Export button in the top right corner. Choose the STL file option, since that is the format needed for 3D printing. After the STL version of the gumball machine design finishes downloading to your computer, open MakerBot and import the file by clicking Add File or by dragging the STL directly into the program. Once the model appears in the workspace, check the print settings and make sure supports are turned off, because the gumball machine design does not need any supports to print correctly. After confirming the settings, the file is ready to be sliced and sent to the 3D printer. Do the same for the extension piece.
  2. Websites used:
  3. TinkerCad for gumball machine, TinkerCad for extension
  4. MakerBot

Step 2: Printing

  1. After the gumball machine file is sliced and saved onto the USB drive, remove the USB from the computer and insert it into the USB port on the 3D printer. On the printer’s touchscreen, select Print, then choose the gumball machine STL file from the list that appears. Once you start the print, the machine will heat up, laying down the melted filament layer by layer until the entire gumball machine design is completed. When the print is finished and the build plate cools down, gently remove the gumball machine pieces by lifting off the tray.


Step 3: Coding

  1. Adafruit Makecode Coding
  2. Visit the site Adafruit Makecode
  3. Connect your CPX to your computer and connect it to the servo

Construct the blocks as followed

  1. The provided code will:
  2. Cause the motor to rotate clockwise 120 degrees when a loud sound is made near the CPX
  3. Cause the motor to rotate clockwise 120 degrees when a light is shined onto the sensor
  4. Cause the motor to rotate clockwise 120 degrees when it’s shaken

After sensor is triggered, it rotates 120 degrees, holds for a second, and returns to the initial position

CircuitPython Coding

  1. Follow these instructions to install CircuitPython onto your CPX: https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython
  2. Connect your CPX to your computer and save code.py onto it
  3. Copy the provided code below and paste it into code.py file on Mu Editor
  4. The provided code will:
  5. Cause the motor to rotate clockwise 120 degrees when button A/B is pressed
  6. Cause the motor to rotate clockwise 120 degrees when a light is shined onto the sensor to pass threshold of 150
  7. Cause the motor to rotate clockwise 120 degrees when it’s shaken past the threshold of 20
  8. Light up red when inactive and green when active
  9. After sensor is triggered, it rotates 120 degrees, holds for a second, and returns to the initial position


Attachments

Step 4: Assembly

  1. Next step is Assembly
  2. Assembling the gumball machine involves putting together several printed parts in a way that supports both the structure and the servo mechanism. The large main body acts as the core of the build, and the separate flat front face is attached to it using glue and tape. The build also includes an extension piece that sticks out from the base and rises upward, creating a platform where the servo can hang above the rest of the machine. The servo itself rests on that extension and overhangs the build, while a separate rotating piece with the slot fits onto the servo’s wings. When the servo turns, the slotted piece mounted to its wings twists open and the gumballs drop through the opening.

Step 5:

  1. Finally connect the servo to the CPX with the clips
  2. Run the code and test the sensors