When I was a kid, every year for Halloween — instead of just handing out candy in a bowl — our neighbor would create a magical machine that allowed kids to select one of four types of candy using a Morse code key hooked up to a buzzer. After keying in the code, a light bulb over the selection would illuminate and the candy bar would come flying out of a chute. The premise of “The Machine” was that it was fully automatic (imagine a box about the size of 12-pack of beer, sitting on a table, with a curtain strung up behind it), and they did a great job keeping the story going year after year.
When our neighbor aged out, the responsibility for the Machine was bequeathed to me. It was then that I learned the truth about the man behind the curtain, who had to listen carefully to count the Morse code beeps, manually connect the wires to the right light bulb, and send the candy down the chute. To say this was a life-shaping moment would be an understatement. Ever since, I’ve wanted to make the real, fully automatic Machine.
Now my kids are about the same age I was then, so I decided it was time to make this dream happen. I also saw this project as a great opportunity to again experience the early product development cycle (I spent 10 years at iRobot leading the team that built the first 4,000,000 Roombas, and today through Dragon Innovation and Bolt I help companies like Jibo go from prototype to high-volume production).
Proof of Concept
Originally, our plan was to make the Machine work with no software. This plan changed quickly when we decided it was easier to use stepper motors rather than dealing with brushed motors and gearboxes. Our first task was figuring out the “material handling” for the candy. We landed on a design that used 1½” PVC tubes arranged like a pipe organ, with an actuator wheel made out of pieces of a flat brush from McMaster-Carr wrapped around a wooden dowel.
For the electrical engineering (EE) side, we purchased an Arduino Leonardo microcontroller. (Adafruit and Sparkfun both have amazing libraries and tutorials to help get you rolling with Arduinos.) From here, we built a proof of concept with one candy channel, and were able to prove out the feeder mechanism. Within a few minutes we were able to wire up the stepper motor, and cut and paste some simple code on the Arduino to get it to spin when a button was pressed, accompanied by flashing LEDs of course. (A task for next year is to close the loop and use a sensor to detect when the candy has been vended.)
Once we had locked down the basic concept, I decided to build a solid CAD model to make it easier to quickly iterate with different geometries. We used Onshape, which is amazing software. If you’re designing a public project, like the Machine, it’s free, and it runs in a browser on any device. Once you sign up for Onshape, you can access our CAD model. Then, you can download the STL files. I used materials that were easy to source from Home Depot and McMaster-Carr.
Once the CAD model was complete, I created a Bill of Materials (BOM) using the Dragon Innovation BOM Add-In from Google Sheets (this is one of the free tools we just released to help the community create better BOMs, and I was eager to try it out on my own project). The BOM helps me keep track of the ingredients and also understand the overall material cost. Feel free to check it out.
The next step was to create the candy channels. Using a cutoff saw, I built the vertical supports and sub-bases first, and then added the PVC tubes cut to length, held in place with zip-ties.
To create the activator, I cut strips from a bristle brush and wrapped them around a dowel. The ends were held together using a rubber band that I doubled-up around either end of the bristle bunches. I found this created sufficient friction to hold everything in place, and also leave room for fine-tuning adjustments.
To provide room for the activator to reach the candy, I experimented cutting different geometries in the PVC elbows. I found the best shape was made by cutting a 90° notch in the PVC elbow with a hacksaw.
I created the motor mounts by cutting the aluminum angle to length and drilling out holes to line up with the threads on the motor face. To make lining up the hole pattern easier, I created a 2D drawing in Onshape, printed it out 1-to-1 on a piece of paper, and then taped the paper to the aluminum as a guide.
Once the four channels were complete, I cut out the base, drilled holes for the bolts, and mounted the channels in place using wingnuts. Feet on the bottom provided protection for the counter-top to ensure the bolt heads didn’t rub.
The heart of the electrical system is the Arduino. Using this as the foundation, I soldered on the headers and stacked two of the Adafruit motor shields on top to drive the four steppers (two per shield). For the final layer, I used the Adafruit proto shield and soldered on resistors to limit the current to the LEDs in the buttons, along with jumper wires.
To make the wire harnesses running between the Arduino and motors/buttons, I cut the individual wires to length and used a drill to twist them into a unified cable. For the end connectors, I soldered header pins to the cable and used heat shrink to make sure there were no shorts.
To control the light show, I used a second Arduino, and ran jumper cables across to handle the interprocessor comms.
To debug the software before the final mechanical system was complete, I created a “roadkill” prototype (guts everywhere) which had all of the electronics spinning loose motors. Through the example code and tutorials on Adafruit, I was able to cut and paste to create the control code for a single channel. I then added the necessary loops to account for multiple channels.
Daniel Ozick, who did much of the code for the original Roombas, was invaluable in helping me untangle my code and making it efficient and scalable so we can add in additional candy channels next year if we want to go that route.
We decided to add in a second processor to handle the LED strip, and created a simple communication scheme so they could talk to each other.
Download the code for both Arduinos (machine operation and LED animation, respectively).
System Integration and Tuning
The system went together smoothly. By using cable ties to mount the PVC tubes to the frame, it is possible to adjust the vertical spacing to find the right amount of interference between the brush and the candy. This did require some tweaking. I also found that adding a narrow strip of cardboard vertically inside the tube prevents the candy from overlapping and jamming up. On the software side, it’s necessary to tune the amount of time the motors spin so that only one piece of candy is dispensed on a button press. For the candy, we found that boxed Nerds and Milk Duds were the best, as they tend not to get jammed up and they have regular geometries. “Fun-sized” Snickers, Milky Way, etc. also run smoothly, although it is occasionally necessary to pull out a jam.
Now that we have the basic system working, there are plenty of items we’d like to add for next year, including:
- Building a fancier external enclosure to hide the inner workings of the machine and make it more mysterious.
- Adding sensors to detect when the candy has been vended and close the loop on the motor.
- Adding additional candy channels.
- Adding the ability to handle lollipops and other geometries.
- Adding Photon Particle or Electron to log the amount, type, and time of candy vends — to help plan for the following year.
Overall, this was a remarkably fun project to build with the kids, and a great way to expose them to engineering. The overall material cost was under $450 and it took about a month from idea to “finished” product. We got to touch mechanical, electrical, and software systems, as well as design. Schedule was important, as the due date was fixed. It is remarkable how easy it is today compared to even 15 years ago when we built the first Roomba prototype and had to design everything from scratch with primitive tools. We’re excited for the next wave of the hardware revolution, making it easier to go from a prototype to production.
The last few days have been a sprint to finish the Machine before Halloween (nobody cares about a Halloween Machine on November 1!). We’ve got her working, and are looking forward to Trick or Treat!