The process of building the automated candy dispenser was a roller coaster and definitely an example of the Pareto principle, where 20% of the details took 80% of the time.
I learned a lot through the experience and hope to have made a lot of kids happy. On the technical side, I learned about Arduino boards, basic programming, libraries, shields, and their IoT Cloud and Web Editor. I also learned about some of the capabilities and limitations of Alexa Routines and Skills. On the non-technical side, I learned that it's important to know what you're good at and not to be afraid to ask for help for other things (the software, electronics, and programming took me a few hours, but all the mechanical/building/cutting/drilling was a lot more tricky and new for me so I needed to ask for help from family with all that); I also learned that duct tape can do a lot but not everything, and if something doesn't work with duct tape to try a better (ideally mechanical) method.
Below you can read about the engineering process I went through, some of the design decisions, review of prior art, and areas for future work that I identified.
I started the design/engineering process defining the goals/objectives. I wanted to be able to dispense new, wrapped candy in a fully automated fashion with no human intervention and no human touching any of the candy at any time close to when it's dispensed.
I started to review the prior art and existing open source designs. I found a lot of helpful links on the Internet, especially the first one which goes through their engineering process and includes a parts list:
https://barkersrandomprojects.com/projects/candyDispenser (huge thanks to them for their guidance and support and answering questions)
I liked many of the elements of these other designs and took bits and pieces as inspiration for my design.
I decided to build a door opening and closing mechanism and have the candy fall out with the help of gravity. I realized (as did the Barkers team) that there would be jamming of candy, but I decided this wasn't a big deal; worst case it would mean variability in dispensing quantity, which could be solved by just having a larger reservoir of candy.
I looked around the house for reservoirs/hoppers and found a poster tube that could hold the candy. I did some quick experiments to see how fast candy would slide down it. I then asked around for a suitable Arduino servo motor and was recommended this one:
I also ordered some different chutes to test with from Home Depot:
To run the brain of the whole thing, I ordered an Arduino IoT kit, which included the microcontroller and a bunch of helpful accessories. Using their IoT Cloud and Web Editor and their own Arduino Alexa Skill, I was able to quickly program the microcontroller to connect to Wi-Fi and operate the servo motor when activated via Alexa. This article was a helpful inspiration:
With the software "done," I started working on the stuff that was harder for me: all the mechanical building stuff.
At first I duct taped the motor to the tube and screwed in a small piece of particle board. Below is my "v1" of the dispenser.
This version performed really poorly. There was jamming all over, and the motor kept moving and shifting, which prevented the door from operating as desired. I was almost ready to give up, but then I realized I should talk to some family members who have a lot more experience actually building real world (as opposed to software) things. I learned that building the assembly out of wood and screwing/clamping things down much more securely would address the shifting and door reliability issues. Also, constructing a door out of wood would make it operate more securely too.
With a lot of help, we were able to to build a much better v2:
I did some calibration of the optimal angle and door opening timing, which was easy to quickly iterate on with the Arduino. The main metric I was optimizing for was the # of dispenses before running out of candy (my optimal was about 20 for a full load of the pipe).
Here is a video of our first time testing the v2 with multiple dispenses in a row. The door was still too large, which resulted in chucking candies backwards, but that was easily fixed with trimming down the size of the door.
This is the core of the design we ended up going with. We added some spray paint and connected it to the chute with a simple funnel made out of a thick paper. We tied the whole thing down to a chair and balcony railing.
I considered a few other possible designs which I spent some time investigating as risk reduction steps in case the door mechanism didn't work out. First off, I looked into robotic arms/claws (even Arduino sells one) with the idea that an arm could pick up the candy and drop it into the chute. I was even thinking of controlling it with computer vision, maybe even with Google Coral. However, I realized there too could be risks with this related to the mechanical gripping/friction issues and also issues with candy not being uniform and kind of getting stuck in whatever hopper it was being scooped up/grabbed from.
A second design we thought of and actually started to build was based on vending machines which use coils/augers to push items forward. I ordered on eBay a few vending spiral coils and even a motor that connects to a cotter pin, and we put those into a poster tube, and that also seemed to do the job. This design might even better than the door mechanism since it dispenses candy in a more uniform fashion, but we didn't finish it so we don't know if there would be problems with loading in to the coil from the hopper or how to control how long to turn the coil when dispensing (or maybe you could sense a successful dispensing via an IR break sensor).
Running the dispenser all day for Halloween showed me some areas for future improvements. First of all, I would've wanted some way to know how empty/full the dispenser was and get a notification when it was totally out of candy. I did set up the Alexa Routine to notify my phone when it ran, and I kind of just kept track mentally of how much candy should be there. Also, it would be nice to have a "loading mode" where candy can be loaded or unloaded without the motor being connected and without the candy just falling straight out (maybe like with a manually operated second door).
Overall, this was a fun project, and I learned a lot about Arduino, Alexa, and building mechanical contraptions. I hope all this info is helpful to others looking to build automated candy dispensers in the future.