Mini Touchless Candy Dispenser

by c26ab1 in Circuits > Arduino

1025 Views, 10 Favorites, 0 Comments

Mini Touchless Candy Dispenser

ChipsInHand.jpg

This instructable shows how to make a mini automatic/touchless candy dispenser. Click here to see it in action!

Ever since I made a candy dispenser out of wood for my cousin's birthday a few years ago, I have been interested in building another, better, cooler one.

Since I have learned how to work with Arduino and c++ I have been enjoying using ultrasonic sensors (which measure distance with sound waves) due to their simplicity and accuracy. For this reason I decided to make my candy dispenser automatic and touchless using an ultrasonic sensor.

This project was a new challenge for me because I did not only have to get the circuit to work, but I also had to figure out an effective and reliable way to dispense candy. I made a few iterations of the project until it got to a point where I was happy with it.

We will 3D print the candy dispenser structure and use an ultrasonic sensor and a servo motor to dispense the candy itself.

Supplies

Electrical Components:

Arduino Uno (other, cheaper boards can be used)

Breadboard

Protoboard

Servo Motor

Ultrasonic Sensor (HC-SR04)


Tools:

Soldering Iron + Solder + Fume Extractor

3D Printer

Hot Glue Gun + Glue Sticks


Other:

Double Stick Tape

Duct Tape

Arduino IDE

2x2' Wood (optional)

Hand Saw (optional)


3D Files:

Candy Dispenser Bottom

Candy Dispenser Top

Servo Attachment

Make Circuit

candy_dispenser_circuit.png

Access the circuit model here: https://www.tinkercad.com/things/1tC46xwL0Rd

You can even test how it works in Tinkercad by clicking "simulate" and then clicking on the ultrasonic sensor and moving the object sensor around. In the Tinkercad design the distance at which the Servo moves is 45cm for simplicity in testing online, but we will actually be moving the servo at 5cm.

  1. Connect 5v from the Arduino to positive on the breadboard, and ground from the Arduino to negative on the breadboard
  2. Connect positive on the servo to positive on the breadboard, ground on the servo to ground on the breadboard, and signal on the servo to pin 9 on the Arduino
  3. Connect positive on the ultrasonic sensor to power on the breadboard, ground on the ultrasonic sensor to ground on the breadboard, trig on the ultrasonic sensor to pin 4 on the Arduino, and echo on the ultrasonic sensor to pin 2 on the Arduino

Code the Circuit

Download the code in the attached file or copy and paste it from Tinkercad into Arduino IDE.

The way the code works is by sending signal to ultrasonic sensor to "shoot out" sound waves, which will bounce off an object and return, and calculate the time in (in microseconds) until the sound waves are received. It then multiplies this time by the speed of sound and divides by two to calculate how far an object is in centimeters. You can read the comments in the code to further understand how it works.

Test the Circuit

Connect your computer to your Arduino and upload the code. Open the serial monitor which will print the distance that the ultrasonic sensor is calculating.

Move your hand around the ultrasonic sensor and watch the numbers in the serial monitor change. When the distance is less than 5, the servo should turn 90 degrees.

Solder

Once you have the circuit working, solder it. You can do this on a protoboard, which I used so I could directly move my circuit from the breadboard onto the same spots on the protoboard.

If you are new to soldering here is a good instructional video: How To Solder on Circuit Boards!

Once you are done soldering, test the circuit once again to make sure it is still working.

3D Print

We have three files to 3D print. We are printing the top and bottom of the candy dispenser separately so that we can fit the servo attachment inside. If you do not have a 3D printer, you can send out the files to be printed here.

Files to print:

Candy Dispenser Bottom

Candy Dispenser Top

Servo Attachment





Assemble

UltraSonicArea.jpg
ServoArea.jpg
ServoAttachment.jpg
ChipsInBowl.jpg

Now that we have our parts 3D printed, and our circuit ready, we can assemble the candy dispenser:

  1. Hot glue the ultrasonic sensor inside the circular holes in the bottom half of the candy dispenser.
  2. Hot glue the servo in the rectangular hole in the bottom half of the candy dispenser.
  3. Fit the servo attachment onto the servo motor.
  4. Duct Tape the wires to the interior of the candy dispenser so they don't interfere with the ultrasonic sensor.
  5. Use double stick tape to attach the top half of the candy dispenser to the bottom so you can still take it apart and access the servo. Align the top half so the funnel in it shoots directly into the open part of the servo atachment.
  6. (Optional) Cut 2x2' blocks of wood to lift the dispenser off its surface and prevent scratching.

Use

ChipsInHand.jpg

Plug the arduino into a power supply and stick your hand under the candy dispenser to receive candy! Enjoy! Watch this video to see it working!

The dispenser works by aligning the yellow servo attachment and has with the funnel in the top green piece of the candy dispenser. The attachment catches candy which is filled in the green piece and as the servo rotates, the candy dispenses by dropping out the front, and the hole in the top green piece is covered with the extension that you can see coming out of the yellow piece. Then once the candy has dispensed the servo rotates back and fills up with more candy.