Introduction: Trick or Treat Candy Dispenser

Have you done trick or treating this year? Where did you leave your candy? The most probable answer is in a plastic bag or lost inside a drawer. Upgrade your Halloween decoration with this intelligent dispenser and surprise your guests with this trick.

This spooky pumpkin detects your hand when its close and delivers a sweet. Transform your usual bucket into this jack-o-lantern and use it for next Halloween. It also includes a couple red and yellow lights that gives it an ideal candle effect.

Step 1: Get the Components

To replicate our design you will need:

• (x1) Plastic pumpkin

• (x1) Arduino One

• (x1) Servo motor

• (x1) Ultrasonic sensor

• (x1) Micro vibrator (mobile phone)

• (x3) Red LED

• (x3) Green LED

• (x1) Cutter

• (x2) Resistors of 220Ω

• (x18) Wire jumpers

• (x10) Orange bubble gum balls

• (x5) Plastic spiders

• (x1) Black cardboard funnel

• (x1) Cardboard tube

• (x1) Protoboard

• Hot silicone

TIP!: If you don’t have or don’t want to by a vibrating motor, you can build your own with a DC motor. A vibrating motor is essentially a motor that is improperly balanced. In other words, there is an off-centered weight attached to the motor's rotational shaft that causes the motor to wobble.

Step 2: Set Up the Hardware

We have included a Fritzing sketch for a better understanding of the design. We have used a breadboard instead of soldering on a bakelite plate because it’s a temporary project and we want it to be demountable.

Connect the sensors to the specified PINS and use the lateral columns for the voltage and Ground connections. We have soldered the LEDs with jumpers so that we can later locate them inside the pumpkin.

Step 3: Upload the Code and Test

Once the connections are made connect the USB A to USB B from the computer to the Arduino UNO and upload the sketch. Feel free to copy, modify and improve on the sketch.

Here is our code for this project:

//#include is used to include outside libraries in your sketch.
#include Servo servo; int vibrator = 10; int trigPin = 11; // Trigger int echoPin = 12; // Echo long duration, cm; int brightness = 0; // how bright the LED is int fadeAmount = 30; // how many points to fade the LED by int led_yellow = 6; // the PWM pin the LED is attached to int led_red = 3; void setup() { pinMode(vibrator, OUTPUT); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); servo.attach(5); pinMode(led_yellow, OUTPUT); pinMode(led_red, OUTPUT); } void loop() { digitalWrite(trigPin, LOW); delayMicroseconds(5); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // Read the signal from the sensor: a HIGH pulse whose // duration is the time (in microseconds) from the sending // of the ping to the reception of its echo off of an object. pinMode(echoPin, INPUT); duration = pulseIn(echoPin, HIGH); // Convert the time into a distance cm = (duration / 2) / 29.1; // Divide by 29.1 or multiply by 0.0343 if (cm < 10) { digitalWrite (vibrator, HIGH); //unstuck candy delay (300); //wait 3 seconds digitalWrite (vibrator, LOW); //stop vibration delay (300); servo.write (90); //open dispenser angle delay (200); //play with this time for more or less candy dispense servo.write (10); //closed dispenser angle delay (200); digitalWrite (vibrator, HIGH); delay (300); digitalWrite (vibrator, LOW); delay (300); } // set the brightness of pin 3 and 6: analogWrite(led_yellow, brightness); //fade analogWrite(led_red, 255 - brightness); //inverted fade // change the brightness for next time through the loop: brightness = brightness + fadeAmount; // reverse the direction of the fading at the ends of the fade: if (brightness <= 0 || brightness >= 255) { fadeAmount = -fadeAmount; } delay(20); // wait for 20 milliseconds to see the dimming effect } // end of the code

Step 4: Mounting the Product

The first step is drilling a hole on the plastic pumpkins mouth and nose. Also cut a partial hole on the cardboard tube with a cutter or a manual saw. Attach your Servomotor so that the horn can rotate inside it. We taped it with duct tape, but for a more professional finish you could use the mounting flange on the side of the motor.

If you’re going to supply the Arduino with an external font make sure to add an extra hole on the back of your pumpkin.

Once we check the mechanism work glue gun both things on their respective holes. Then cut your black board to a cone or funnel shape and attach the vibration motor. Make sure the shaft does not touch it.

Before connecting the upper part of the dispenser to the lower part place all your electronics inside the bucket. Finally duck tape the cone to the tube and the bucket.

Now your dispenser is fully functional. Be creative decorating your pumpkin. We used some black felt for covering up the connections and some spiders for extra fun.

Step 5: Trick or Treat!

Go get some candy and try your new Trick or Treat Candy Dispenser.

Happy Halloween everyone!

Halloween Contest 2019

Participated in the
Halloween Contest 2019