WebUSB Enabled Candy Dispenser With Pomodoro Timer

by ChingusBcMingus in Circuits > USB

40 Views, 0 Favorites, 0 Comments

WebUSB Enabled Candy Dispenser With Pomodoro Timer

candy machine.png
WebUSB Candy Dispenser Demo
A Nigerian Prince Has Forced Me to Make a WebUSB Candy Machine

First video is a quick demo of the dispenser while the second one is an arguably cringe "ad" for the dispenser.


There are two things that I have a real hard time with, staying focused and not eating an entire bag of candy in a few minutes, this project aims to solve both of those problems with a little bit of style!

The candy machine will connect to my website where it's running my version of a Pomodoro timer (more info on that is on my 'site) and will dispense candy after an interval of your choice. This solves my problem of focusing by giving me a system that is effective and rewarding (as well as somewhat addicting) and solves my problem of poor conservation of candy by limiting myself artificially while also adding to the rewarding-ness to the Pomodoro timer.

I highly recommend this project to anyone who has trouble focusing (or at least just the Pomodoro timer), my productivity has vastly improved with it and this project is my weird way of sharing this knowledge with everyone, hope you enjoy!

Supplies

20260324_205907.jpg
20260413_151148.jpg
20260413_150842.jpg
20260413_150340.jpg
20260413_150537.jpg

For this project we'll need:

  1. Access to a FDM 3D printer and some filament (I used PLA but any standard filament should work just fine)
  2. An Arduino Leonardo, or any one of these boards (they should work, but I haven't tested them so I'm not sure). The project does have mounts for the Leonardo, but just ignore them if you don't have a Leo
  3. SG90 Servo motor with its corresponding screws and a dual-sided arm/horn
  4. Few jumper wires to connect said servo (the smaller the better)
  5. Mason jar, or this 3D printed "jar"
  6. A web browser that supports WebUSB, which is pretty much every modern day Chromium-based browser (sorry Firefox users), see if your specific browser works here
  7. Arduino IDE version 1.6.11 or higher
  8. A internet connection to connect to my beautiful website
  9. Last but not least, your choice of smaller candy (jelly beans, M&Ms, Skittles, ect.)

Printing Everything Out

20260413_151030.jpg
20260413_150911.jpg
20260413_150929.jpg
20260413_150949.jpg

Printables.com edition (includes STEP editions of the models): https://www.printables.com/model/1688998-webusb-enabled-candy-dispeser


The title says it all, just print everything out!

The trunk will need supports everywhere (you could get away with not printing supports for the roof part of the model, if you have enough faith in your printers bridging abilities that is) and the candy machine will only need support on the bottom back part where the trunk is suppose to slide in, everything else can be printed with no supports.

Credits and shout-out towards Carl Belcher on Printables for making the original candy machine model, this project would probably not be possible without them.

Programming the Board

Screenshot_20260413_150459.png

While everything is still printin', why don't we program the board? We'll use the native Arduino IDE as that is what I'm familiar with and it works well with most boards.

In order for WebUSB to work with your computer, we need to do some special setup on your computer. I know that sound intimidating, but it's not that bad. Its quite simple really, so simple in fact that I won't tell you what to do, instead this will, do both the changing the USB_VERSION and downloading the library. Yeah, I'm not gonna explain how to do it when someone already did it, call it lazy but I didn't have to write all that :]

On top of that, we'll also need the servo motor library, so download it if you don't already have it and you should be good to go ahead and flash the code to your board.

Eagle-eyed viewers may notice that this code is not much different than the demo code provided here, and you'd be right! I just messed with the demo until I was able to move a servo with it and for it to "communicate" with my website, so it may not be the most efficient of code. Feel free to mess with it if you wish.

Downloads

Setting Up the Servo

Screenshot_20260409_172132.png
20260413_151316.jpg
untitled.gif
servo spin.gif
20260413_151741.jpg
20260413_151814.jpg

Connect the servo's PWM pin (it will probably be colored orange or yellow) to pin 9, power (red) to 5v, ground (black) to GND.

If you need to change the PWM pin on the board itself for whatever reason, change the number on line 23 in the .ino file to another number that correlates to a pin that supports PWM, for example if you want it to be on pin 10, change the "9" to "10" (without the quotes, of course).

When the servo is powered up without it communicating with my website, it'll default to rotating the motor somewhere in the middle, we don't want that, so please go to my website, then go into "Settings" and under "WebUSB Options" click "Connect", the motor will move into place if it successfully connected and if the servo is wired correctly, you'll hear it move into place. If not, check the connections and maybe re-flash the code.

Next, with the servo still connected to the board and the board is connected to my website, you'll want to attach the servo arm as shown in the photo, then attach the knob you 3D printed earlier to the arm. Make sure the divot is facing upwards so you won't have to fix it later.

All Together Now!

20260413_153710.jpg
20260413_153725.jpg
20260413_153923.jpg
20260413_153807.jpg
20260413_153755.jpg
20260413_154000.jpg
20260413_154132.jpg
20260413_154142.jpg
20260413_154152.jpg
20260413_154158.jpg
20260413_161519.jpg
20260413_161521.jpg
20260413_161524.jpg

Disconnect the servo motor from the board, don't worry, we'll put it back in soon. Weave the cable through the servo mount located in the trunk and place the servo with the arm towards the top into the mount, be careful that you don't pinch the cable as I broke one of my servos doing that (I did also increase the tolerances for the mount since then so that probably won't happen with you, but I would still keep an eye out for it). Optionally, screw in the servo to the mount (glue will work too, but good luck trying to get it back out), it should work just fine without it being screwed in, but you will need to push it back in from time to time and if you have the screws, you might as well, right?

Wire the servo back up and then slide the board into the trunk. If you are using an Arduino Leonardo, it'll fit snugly into the bottom of the trunk with the screw holes fitting nicely into the little pegs, if not, just try to fit your board in there somewhere. Finally, slide the trunk into the candy machine itself, making sure the bottom and the knob slide right into the machine. Don't forget to add the pin to the front of the device to keep everything in!

Connect your board to your computer and go back to my website to test it out. Connect your board to the page (the connect button is under Settings => WebUSB Options => Connect), fill the machine with some of your candy and hit the "Servo Test" button (right next to the Connect button). If candy successfully dispensed, that means everything is working correctly and you're ready to use your machine!

Using Your Candy Machine

Screenshot_20260413_222346.png

By default, the machine won't dispense anything until you tell it when it should dispense. Under "WebUSB Options" in the "Settings" tab, there are 3 check boxes correlating to when the machine will dispense candy. For example, if the top one is checked, it'll dispense after a focus has passed, change these values to whatever works for you, I won't judge.

The machine may jam occasionally, I don't have a fix for this, sadly, so if this does happen to you, just try shaking the machine around a little bit to free it from its jam and hit the "Servo Test" button to reap your rewards.

Thank You and Goodbye!

servo wave.gif

Thanks for checking out this project! I really hope that it can provide you with any sort of use, or all of this work would've been in vain!! (I'm kidding, I had quite a bit of fun making this :] )

If you find any bugs in the webpage portion of this or have any suggestions for either the Instructables itself (this is my first time making one of these, so I'm expecting a few ways I can improve) or the webpage, feel free to either leave a comment here (at least I'm pretty sure you can leave comments here, like I said, I'm new here :p) or to email me at important.buffing672@passinbox.com .

Thanks again and I hope you have a good morning/evening/night!