Ghost Candy Dispenser

by SayaNIGHT in Circuits > Robots

143 Views, 1 Favorites, 0 Comments

Ghost Candy Dispenser

DSC07526.JPG
DSC07520.JPG
DSC07519.JPG
Ghost Candy Dispenser

Hi there! Did you enjoy Halloween in 2024?

Since I'm usually not home during trick-or-treat time, for the past three years, I've been leaving handmade candy dispensers at the front door. Unfortunately, this year's dispenser didn't work well on the day because the battery ran out midway, and the candies often got stuck. So, I modified it to allow switching between USB power and battery power, and improved the mechanism to reduce the jamming problem. In this project, I'll share how to make this year's improved version. I hope this project is useful for next Halloween, or at the very least, that you enjoy reading about it!

Supplies

supplies.jpg

Parts

  1. MCU: M5StampS3 (M5Stack) (×1)
  2. RC servo motor: MG90S (×1)
  3. HC-SR04 Ultrasonic Sensor Module (×1)
  4. 1.5" 4 Ω 3 W speaker and PAM8403 amplifier module (×1)
  5. DFPlayer mini MP3 player (×1)
  6. Micro SD card (×1)
  7. DC-DC converter: Adafruit MiniBoost 5V @ 1A - TPS61023 (×1)
  8. USB-C socket breakout (×1)
  9. 3.7 V LiPo battery (optional)
  10. Power switch: slide, SPDT (×1)
  11. Red LEDs: pre-wired SMD LED, RED (×2)
  12. RGB LEDs: WS2812B breakout module (×10)
  13. Discrete Semiconductor parts: resistors 1 kΩ (×1), 4.7 kΩ (×3), 10 kΩ (×1); diode 1N4148 (×1); NPN transistor 2SC1815 (×1)
  14. Pin headers and sockets
  15. Universal PCB (×1)(depending on wiring)
  16. Screws: M3 × 8 mm with nuts (×2), M2 × 6 mm with nuts (×2), M2 × 8 mm with nuts (×2), M2 × 10 mm with nuts (×2)
  17. Candies: Hi-Chew


Tools

  1. 3D printer: Flashforge Adventurer 4 (Filament: black and white PLA)
  2. Screwdrivers
  3. Soldering tools
  4. Acrylic paint tools
  5. Masking tape (optional)
  6. Double-sided tape
  7. Hot glue gun


Software

  1. Visual Studio Code with PlatformIO IDE (Arduino)
  2. Autodesk Fusion


Service

  1. Freesound

3D Printing

I designed the model using Autodesk Fusion. The ghost part and the Jack-o'-lantern parts were designed using the sculpt (form) mode, while the other parts were designed using the normal solid mode.

Print all parts. I used white PLA filament for ghost.stl, JOLFront.stl, JOLBack.stl, side1.stl, lever.stl, and backBoard.stl. The reason for using white filament is that it reflects the LED light better. The other parts were printed with black filament.

Note that printing ghost.stl and base.stl takes a long time. Printing each the part took over 12 hours, though that depends on your printer and settings.

Painting

painting.jpg

Paint the ghost part and the Jack-o'-lantern parts with acrylic paint. It's a good idea to cover the unpainted areas with masking tape before you start painting.

Candy Cartridge Assembly

Assembly1.jpg

Assemble the candy cartridge. The numbers in the attached figure correspond to the steps below.

  1. Insert the back board and the front board into the side1. Note the orientation of the back board.
  2. Insert the side2 into the previous assembly while inserting and holding the flap.
  3. Insert the bottom into the previous assembly from the front side.
  4. Ensure the flap moves smoothly. If it doesn't, enlarge the holes on the side1 and side2 using a drill bit, or sand the flap.
  5. Insert the part assembled previously into the base until you hear it click.

Designing the Schematic Diagram

schematic.jpg

The schematic diagram is attached. Connect the J1 socket to the J2 pin header when using USB power. Connect the J1 socket to the J3 pin header when using battery power.

Choose a battery with the appropriate capacity depending on your operating time and frequency. For reference, the results of the current measurements are shown below. The measurements were performed at the SW1 point using a digital multimeter.

  1. The current in the standby mode was approximately 285 mA. In the mode, the 10 RGB LEDs were set to full brightness, the two red LEDs were on, the ultrasonic sensor was measuring, and the servo motor and DFPlayer mini were in standby.
  2. The maximum current in the active mode was 350-650 mA when the candy dispensed smoothly. However, if the candy got stuck, the current exceeded 1.2 A. In this mode, the LEDs were the same as in the standby mode, the ultrasonic sensor stopped measuring, and the servo motor and the speaker were active.


For this project, I used my current favorite MCU, the M5StampS3 featuring the Espressif ESP32-S3 chip. Its operating voltage is 3.3 V, while the ultrasonic sensor and the DFPlayer mini operate at 5 V. Therefore level shift is needed to connect them. The resistor R1-R5, diode D1, and transistor Q1 in the schematic are necessary for the level shift between 3.3 V and 5 V.

Wiring

wiring1-2.jpg
wiring3-8.jpg

Wire all the electronic components according to the schematic diagram. Here’s how I approached it, though other methods would also work well. The numbers in the attached figures correspond to the steps below.

  1. Red LEDs Wiring
  2. a. Insert the red LED leads through each ghost eye's hole.
  3. b. Fix the leads inside the ghost using a hot glue gun.
  4. c. Solder and connect the red LED leads via wires to a three-pin header.
  5. the Jack-o'-lantern Wiring and Assembly
  6. a. Insert two M2 nuts into the JOLBack.stl part as shown in the figure. (Tip: Attach a nut to an M2 screw, pull the screw with the nut to set the nut into the hole, and then remove only the screw.)
  7. b. Solder and connect the ultrasonic sensor and the D13 RGB LED via wires to a six-pin header (one pin is not used). Note that the pin header should be soldered after threading the wires through the hole inside the JOLBack.stl part.
  8. c. Attach the ultrasonic sensor with the JOLBack.stl part using two M2 × 10 mm screws.
  9. d. Attach the JOLFront.stl part with the JOLBack.stl assembly.
  10. Switch Wiring
  11. a. Solder and connect the switch via wires to a two-pin header.
  12. b. Insert the wired switch into the base part, ensuring the 'ON' mark on the base part and the orientation of the wired switch match.
  13. c. Fix it using a hot glue gun.
  14. USB-C Module Wiring
  15. a. Solder and connect the USB-C module via wires to a two-pin header.
  16. b. Insert the wired USB-C module into the base part as shown in the figure.
  17. c. Fix it using a hot glue gun.
  18. Battery Wiring (optional)
  19. a. Create wires connecting between your battery and a two-pin header.
  20. Speaker Wiring
  21. a. Solder and connect the speaker via wires to a two-pin header.
  22. RGB LEDs Wiring
  23. a. Solder and connect each of the nine RGB LEDs (D4-D12) via wires, and connect VDD line, GND line, D4's DIN and D12's DOUT to a four-pin header. The D4-D6 LEDs are intended to be attached to the candy cartridge, and the D7-D12 are intended to be attached to inside of the base. Please refer to the figure for each wire length.
  24. b. Attach the wired RGB LEDs to the cartridge and base part with double-sided tape as shown in the figure.
  25. Main Board Soldering
  26. a. Solder the DFPlayer mini, the amplifier, and M5StampS3 onto a universal PCB and wired all discrete semiconductor parts. When reusing the parts, use headers and sockets. This time, they were used only for M5StampS3.
  27. b. Solder the sockets for the pin headers wired in the previous step 1-7 and the servo motor.
  28. c. Cover the back side of the main board with tape to protect against shorts.

Uploading the Code

I'll share my code on GitHub. The code was written using PlatformIO. Download and upload the code to the M5StampS3.

The sound used in the project was downloaded from https://freesound.org/. I used 'Happy Halloween Cute Voices' by NicknameLarry and converted it to mp3 file. Create a folder named 'mp3' on the micro SD card, and store the sound file named 001.mp3 within it. Then, insert the micro SD card into the DFPlayer mini.

Downloads

Final Assembly

Assembly2.jpg

In this step, all parts are assembled into the base part. The numbers in the attached figures correspond to the steps below.

  1. Attaching the Servo Motor
  2. a. Connect the servo motor's connector to the main board and start the program. Confirm the servo motor rotates to 0-degree position. Then remove the connector.
  3. b. Insert two M2 nuts into the nut spaces as shown in the figure.
  4. c. Attach the servo motor and fasten it with two M2×8 mm screws.
  5. d. Attach the lever to the motor horn and fasten it with two M2×6 mm screws and nuts as shown in the figure.
  6. e. Attach the assembled lever to the servo motor and fasten it with the motor screw. Ensure that the lever is outside of the cartridge. This lever position should be set to the 0-degree position.
  7. Attaching the Jack-o'-lantern
  8. a. Attach the assembled Jack-o'-lantern part to the base and fasten it with two M3×8 mm screws and nuts.
  9. b. Paint the visible screws and nuts black using a marker pen or acrylic paint.
  10. Putting All Electronic Component
  11. a. Insert all pin headers and connectors into the sockets on the main board.
  12. b. Place the main board inside of the base.
  13. c. Put the speaker into the front side of the base as shown in the figure.
  14. Loading Candies
  15. a. Load candies into the cartridge. It can store about ten candies. The cartridge is designed to fit Hi-Chew. However, if the candies are the same size, it might work well too.
  16. Attaching the Ghost
  17. a. Cover the ghost on the base while inserting the tree parts inside the ghost into the designated spaces as shown in the figure.
  18. b. Attach the ghost by gently pushing the front and back edges of the ghost inward.
  19. c. To remove the ghost, lift it up while gently pushing the front and back edges inward as in step b.

Have Fun!

You can decorate it at home, use it at events or parties. Enjoy using it however you like!

It might be exciting to increase the variety of sounds or change the way the LEDs lights up.