Introduction: Automatic Halloween Candy Dispenser
When trick-or-treaters show up at my house they can text, call, or tweet a code displayed on an LCD screen to get their Halloween candy. They can also push the Big Red button.
Once the candy request is made a few "special" effects are triggered by X10 modules. A low laying fog machine is activated and lights turn on while the candy shoots down from my front deck on the second floor.
* Update. Now with video!
Step 1: Materials
- Plastic Bucket
- 3 in. x 60 in. Round Pipe
- 2 Futaba S3003 Servos
- 1 Old CD
- Nuts and bolts
- Plastic Project Enclosure
- Big Dome Push Button
- 16x2 Serial LCD Display
- Snap-In Category 5e RJ-45 Jack
- Size M Panel-mount Coaxial DC Power Jack
- 12 V DC transformer
- Cat 5 Cable
- Aluminum Project Enclosure
- Arduino Duemilanove
- Adafruit Protoshield
- XBee adapter kit
- x10 Firecracker CM17A
- x10 Transeiver
- 1 100k resistor
- X10 Appliance module
- 125VAC/10A DPDT Plug-In Relay (as a switch combined with x10)
-
Styrofoam cooler and dryer hose and Ice to create low laying fog.
(Check my last year Halloween project https://www.instructables.com/id/Halloween-Dropping-Spider/ for more info).
- X10 Appliance module
- Incandescent black light, strobe light, black light bulbs.
Step 2: Candy Dispenser
The first thing was to figure out a good way to hold the candy and dispense it. I used a plastic bucket, a metal ventilation pipe and a CD attached to a servo motor. I figured that by having the candy dispense from the side as opposed to the bottom would allow the candy to move more freely and avoid candy jams.
The ventilation pipe comes in a "U" shape, so I made a "U" shaped cut in the bottom center of the bucket. Notice I did't cut the whole "U", instead I left a piece of plastic in the middle to hold the servo motor that rotates the CD.
After I inserted the ventilation pipe I did a few cuts to allow me to expand the pipe into a sheet form. I used a couple screws and bolts to keep the sheet attached to the bucket. The rest of the space was covered by the mighty duck tape.
I cut the CD to allow the candy flow when rotated. Also I duck taped a continuous servo inside to function as a "shaker."
Step 3: Control Box
The control box is pretty simple. I drilled/dremelled a few holes to attach the big red button, ioBridge LCD screen, power jack and the RJ45 jack.
I really like the use of CAT 5 cable to make things more modular.
Step 4: Main Box
The main loop is waiting for either a physical push of the big red button or to receive a remote serial message. The attached XBee module communicates with another XBee module connected to the ioBridge IO-204 module serial board.
These are the digital I/O pins configuration:
-
XBee Module (with adafruit XBee kit)
- Pin 13 - TX
- Pin 12 - RX
- Gnd and 5v
-
Big Dome Push Button
- Pin 8 - Button NO(normally open) + GND + 100K.
- 5v - COM
-
Servo 1 (continuous rotating servo used for shaking)
- Pin 7 - Data
- Gnd and 5v
-
Servo 2 (used to rotate the CD)
- Pin 6 - Data
- Gnd and 5v
-
X10 C17A (x10 devices controller)
- Pin 3 - DTR line for C17A - DB9 pin 4
- Pin 2 - RTS line for C17A - DB9 pin 7
- Gnd - DB9 pin 5
-
ioBridge 16x2 serial LCD display
- Pin 1 - LCD Data pin
- Gnd and 5v
Attachments
Step 5: Code Generator
Instead, I created a REST web service using of course my favorite web development tool, Oracle Application Express http://apex.oracle.com/ , to make sure a unique and random code was generated each time candy drop request was made from text, call or Twitter.
The REST application is really simple and I recognize it can also be created using any other technologies such as LAMP or even a GCI, or Perl application.
Application Objects:
- 1 Table (ID,CODE,SELECTED)
- 1 Numerical Sequence to generate primary key (ID)
- 1 Trigger before insert record that will get the ID value and append a random number to the CODE column
- 1 public procedure to retrieve the code (where selected = 1)
- 1 public procedure to update the code once is used and generate a new one.
http:/my.apexserver.com/pls/apex/getcode
http:/my.apexserver.com/pls/apex/updatecode?code=XXXX
*If you would like to implement something with a static file instead, I would recommend using http://www.random.org/clients/http/ to get a random number and store it in file, memory, or even the arduino itself.
Step 6: IoBridge Setup
There are two main functions that the ioBridge was used for:
- Request current code
I do a GET call from the arduino to retrieve the current code from my Code Generator service using ioBridge Serial Web Services API.
Arduino code:
mySerial.println("[[[get|http:/my.apexserver.com/pls/apex/getcode]]]"); - Start candy dropping sequence by text, call or tweet.
An ioBridge widget will send a start character via serial message and the candy dropping sequence will start. This widget can be called using the ioBridge Static Widget API.
This URL is called by Twilio and by my custom Twitter alert script.
http://www.iobridge.com/widgets/static/id=[widgetID]
These are the digital I/O pins configuration:
- ioBridge Serial Board
- TX - RX XBee
- RX - TX XBee
- GND and 5v
Step 7: Twilio Setup
Twilio is a web-service API for communication apps. Twilio is as simple as it gets. It only took me a short time to get my SMS and Voice applications up and running! I had tried in the past to create similar applications with other technologies (VoiceXML and even Google Voice) and let me tell you is not that easy.
The voice application answers the phone, plays an intro sound file and asks for the code followed by the # sign. If a code is detected Twilio will do a "GET" action to a PHP file that will lookup the current code from my Code Generator Web Service. If it matches it will call the ioBridge static widget URL and candy will be dispensed.
The SMS application has almost the same PHP code except this time instead of looking for the digits dialed it will look for body of the SMS message.
Check the attached XML and PHP files that generate the TwiML XML.
All in all Twilio is a winner and I have plenty of other ideas for the future.
Step 8: Twitter Setup
Twurl is almost like curl but for Twitter. I did some ugly parsing of the twitter RSS feed to retrieve the tweet sender, but it works!
Here is my bash script
#!/bin/bash
mycode=`curl --silent http:/my.apexserver.com/pls/apex/getcode`
twitter=`twurl /1/statuses/mentions.rss | grep "@tweetfortreat $mycode" | cut -d ':' -f1 | tail -n 1 | cut -d '>' -f2`
echo $mycode $twitter
if [ -n "$twitter" ]; then
iobridge=`curl --silent http://www.iobridge.com/widgets/static/id=[widgetID]`
newkey=`curl --silent -d "code=$mycode" http:/my.apexserver.com/pls/apex/updatecode`
update=`twurl -d "status=@$twitter The code $mycode is correct. Happy Halloween!" /1/statuses/update.xml`
echo $newkey $iobridge
fi
Crontab will only allow you to execute a script every minute and I think is fine for now. Alternatively a while loop could be used instead.
Here is my crontab entry
*/1 * * * * /script_location/HalloweenCandy.sh > /dev/null 2>&1
Step 9: Conclusion and Alternatives
If my Google skills (http://lmgtfy.com/?q=automatic+halloween+candy+dispenser)serve me well there are just not many documented Automatic Halloween Candy Dispensers out there. I did run into this one which I really like but is limited to M&Ms sized candy.I found some inspiration from the dog/cat feeders built using the internet enabled ioBridge http://support.iobridge.com/projects/tag/dog-feeder/.
I hope to see more iterations of the Automatic Halloween Candy Dispenser next year. Please make sure you share all your ideas/improvements in the comments section.
Happy Halloween!

Third Prize in the
Halloween Contest
14 Comments
5 years ago on Introduction
I'm cooking plans for a multi-sensor Hallowe'en candy dispenser robot: it activates via motion sensor, prompts the kids to say "Trick or treat!" then dispenses. One wrinkle I'm trying to plan for is sensing how many kids there are, in order to dispense the right amount of candy. If I had the money, I might try for facial recognition so that the same kids wouldn't come back over and over. :) Or, maybe the easiest thing would be to activate/operate a lever to lift a service plate lid on voice command of "trick or treat": the bowl of candy would be under it, and I would just depend on the honor system. Oh, and a large webcam-enabled Cerberus with glowing red eyes would help keep them honest.
9 years ago on Introduction
If i wanted to make something like this minus the txting/tweeting. what parts could be removed? Thought this might be good to try with my daughters, but just want them to push a button. (that will be hidden or something).
10 years ago on Introduction
I noticed that some kids were really interested in the tech. I took pride in explaining the basics. I hope that some kids may realize that they can do cool things too, instead of wasting countless hours in front a video game or tv.
10 years ago on Introduction
This looks like great fun, and I can see that kids would love it (particularly the button). It's also a great idea if you're going to be out of town, or for activating props.
My problem is how are you going to prevent one kid from standing there pressing the button (or whatever method) and getting all the candy?
Reply 10 years ago on Introduction
I purposely set about 30-45 seconds delay between each time the button could be pushed. Also I was at the house pretty much the whole time. A solution could be to have a counter and track how ofter the button is pushed. In this way you could temporarily "lock" the machine if too many consecutive push are happening.
10 years ago on Introduction
Awesome project but I don't see the tweet/call/text being useful. Kids should not be trick or treating and owning a cell phone at the same time and most parents are not going to take the time to when there is a button.
Reply 10 years ago on Introduction
I am 15, own a cell phone, and trick or treated. Who are you to say because I have a phone I am not allowed to trick or treat?
Reply 10 years ago on Introduction
Never thought of a kid having their parents phone or similar. Duh me!
Reply 10 years ago on Introduction
Wait, do you mean "owning" or simply "having available on one's person at the time"? Crucial difference.
Reply 10 years ago on Introduction
Thanks GTechno13, I did thought of that. I do realize most kids will just push the button and thats great! I love the action-reaction of a hack. I added the web(tweet) and the txt/call thing just for fun. I like to create web and remote controlled physical devices. ie last year people could request a Christmas song online and it was synchronized to lights and transmitted on an FM station in my house (https://www.instructables.com/id/xmas-box-ArduinoioBridge-internet-controlled-Chr/ )
After this I plan in use Twilio to help me automate my home.
Reply 10 years ago on Introduction
You raise some good points, however, many children of trick-or-treating age do have texting cell phones and would get a blast out of texting for the treat instead of hitting the big red button. While only maybe one in 20 might text for it, those that do would be telling all their friends about it and would not soon forget it, maybe even sparking their interest in becoming makers themselves one day.
Best Wishes
10 years ago on Introduction
I liked the idea .. maybe i will build one but not for Halloween!
10 years ago on Introduction
I can see the adults getting a kick out of the tech!
10 years ago on Step 9
This is such an awesome idea but you do realise once word gets out that you have the coolest candy dispenser on the block that kids will be queuing around the block all night LOL
LOL