An Arduino-Powered Contactless Candy Dispenser

Halloween is right around the corner, and with COVID-19 still around, it’s important to deliver all that sugary goodness in a safe and socially distant way. Some have suggested using a long section of PVC pipe as a sort of candy slide, and that’s a great idea, but things are always more fun when they’re over-engineered.

One thing I’ve come to learn is that Arduino and Raspberry Pi-powered gadgets make holidays more fun, so I came up with the Arduino-powered contactless candy dispenser.


A distance sensor on the front watches for eager hands or a candy bag to move into position at the bottom of the candy chute. Once activated, a short visual countdown begins, letting the hopeful trick-or-treater know she needs to be patient (I didn’t want the machine to activate upon any incursion into its target zone).

After a brief moment a colorful display on the three eight by eight RGB LED matrices the stepper motor activates, turning a cardboard disk that holds eight candy cylinders. When a cylinder is moved over a hole under the disk, the candy falls out into the eager child’s basket.

Since one cylinder is always open on the bottom, the machine can dispense seven “loads” of candy before it needs to be reloaded. I figure that should let us keep up with demand.

The Parts

The front of the machine (awaiting final decoration). A distance sensor, RGB LED-lined candy chute, and a rotating disk of 8 cylinders (chopped up disposable cups shoved through holes in the disk).
The guts — an Arduino, stepper motor, its controller (the black box on the far side), and the power
  • The brain is a simple Arduino UNO. Any Arduino should suffice.
  • The distance sensor is a common HC-SR04 ultrasonic sensor.
  • The LEDs are relatively cheap 8 by 8 RGB LED matrices.
  • The stepper motor and controller are pretty common Nema 17 motor with a TB6600 controller.
  • I’m using 5V 1.4 amp USB power for the Arduino itself and (separately) for the LED panels, and a 12V 1.5 amp DC power brick for the stepper motor.

Putting it Together

I don’t intend to give a comprehensive guide here, but I’ll explain a few lessons I learned in putting this thing together.

First of all, connect all your grounds together. I was getting very strange erratic behavior from my HC-SR04 when I didn’t have the grounds for the Arduino, stepper motor, and LEDs connected. Common Ground folks.. it’s important.

Most of the build was spent cutting cardboard and figuring out how to get things to move right. I’m using a long carriage bolt to connect the spinning disk of candy cups to the stepper motor. Oh, you’ll need shaft couplers to make that happen. (something like this — get whatever you need for the sizes of the things you need to connect)

The code is pretty simple with the help of some great libraries:

Hope you have a safe and fun Halloween! 🌕

Educational Psychology Ph.D., business analytics nerd, computer scientist, President @MakeStickers

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store