Automated Candy Dispenser

Introduction: Automated Candy Dispenser

"This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida ("

This is an instructable for the construction of a motion-activated candy dispenser.

Required Parts:

3-D Printer (preferably with dissolvable support material)

Arduino Uno


Sonic Sensor (HC-SR04)

Step 1: The Printed Parts

Download and print the attached STL files. The STL file labeled "box" is to be printed at 75% scale. All parts are original except the ultrasonic sensor mount; I found that file from a forum, and I am unsure of the original author.

Step 2: The Program

The program that I used with comments so that it can be reprogrammed is below. The timings I established were made to be used with Peanut M&Ms but can be programmed to fit another candy type easily. The line commented for time would be the primary change one would make as it controls how long the door is open.

Servo myservo;
#define trigPin 3
#define echoPin 2
void setup(){
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
void loop(){
int duration, distance;
digitalWrite(trigPin, HIGH);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
Serial.println(" cm");
if (distance < 10) { //Distance in cm
myservo.write(42); // angle of the servo arm
delay (175); // time
delay (4000); //time between activations

Step 3: The Circuit

Follow the setup established in the arduino code. I have attached a wiring diagram and a picture of the electronic backbone of the project.

Step 4: Assembly

The picture included actually shows the part with significant supporting material still intact. Since I didn't need that space, I simply never removed it. Hopefully the printer you are using has dissolvable support material.

The HC-SR04 bracket fits onto the supporting poles on the underside of the dispenser. It may be secured with an adhesive.

The "door" part snaps onto the servo arm and may be secured by an adhesive.

The completed circuit will all fit inside the 75% scaled "box" part. Drill a hole in the top in order to allow wires out of it.

Finally mount the servo and the sonic sensor to their obvious respective brackets. Mount the servo using an adhesive (I used super glue), or use the slit to attach a rubber band for a less permanent assembly.

Step 5: The Candy


Be the First to Share


    • Fabric Challenge

      Fabric Challenge
    • Sculpt & Carve Challenge

      Sculpt & Carve Challenge
    • Build a Tool Contest

      Build a Tool Contest