Introduction: Automated Candy Dispenser

"This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (www.makecourse.com)"

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

Servo

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.

#include
Servo myservo;
#define trigPin 3
#define echoPin 2
void setup(){
myservo.attach(9);
myservo.write(0);
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop(){
int duration, distance;
digitalWrite(trigPin, HIGH);
delayMicroseconds(100);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
Serial.print(distance);
Serial.println(" cm");
if (distance < 10) { //Distance in cm
myservo.write(42); // angle of the servo arm
delay (175); // time
myservo.write(0);
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

Enjoy

Comments

author
JokerBLeamC (author)2015-08-11

i want to saw

author
JokerBLeamC (author)2015-08-11

can it use real

author
seamster (author)2014-12-11

Very nice! Hope you got a good grade!

About This Instructable

880views

8favorites

License:

More by DoItForMake:Automated Candy Dispenser
Add instructable to: