During the pandemic, my wife and I walked around our neighborhood on Halloween and noticed a lot of socially-distanced trick-or-treating. A bunch of folks were dropping candy down to kids through PVC pipes. Seeing that, I was immediately struck with the image of this machine completely finished. I worked for next year to get it working, and tweaked it on and off against since last Halloween.

It's powered by a raspberry pi running pygame. There are three stepper motors attached to fans at the end of PVC pipes. Each pipe is loaded with a different size of candy, from fun size all the way up to full-size bars. When kids press the button on the front, the wheel on the screen spins and picks a prize at random (based off the distribution calculated from the amount of candy we bought and the number trick-or-treaters we expect). Then, the three stepper-powered fans spin just enough to allow the correct number of pieces to fall through and into the kids' buckets.

There are also some really cool (and sometimes spooky) sound effects that play as the kids wait in line for their turn.

Speaking of lines, last year, this thing was an absolute hit! We had a line down the block all night. Since the machine kept up with stats for me, I saw at the end of the night that we had 445 total spins, and gave out 846 candies.

Since people liked it so much, I was inspired to add more this year. To avoid re-soldering, I did a little classic over-engineering: I added a new rpi zero to act as a wifi access point and an MQTT broker then connected it up the main rpi as well as an esp32 that I programmed using esphome (go check it and home assistant out if you haven't already!!).

On the esp32, I hooked up some individually addressable lights that do some really cool effects as the wheel spins, the candy is dispensed, and randomly in concert with the spooky sound effects. I also added a light to the tray the candy comes out of that turns on so kids can see the candy falling.

Finally, I was able to add a bunch of new music, backgrounds, and sound effects this year. I'm really looking forward to seeing how excited kids are this year!!

Again, you can find a lot more, including source code and videos on my site: https://nathanorick.com/how-i-built-my-halloween-candy-machine/