LED Gumball Machine

Pages
Contributors: Nate
Favorited Favorite 0

Introduction

Do you need an LED? The answer is always yes. But what if you need one right now? Build yourself an LED gumball machine and never run out again!

Gumball machine filled with LEDs

Approximately 3,000 red 5mm LEDs ready to blink

This machine was created for the BTU Lab at CU Boulder because students constantly needed LEDs but filling parts bins always seemed to fall to the tragedy of the commons. We’d put 1,000 LEDs into the bin and they’d be gone in less than 2 weeks.

Dispensing LEDs

With the LED Gumball dispenser the LEDs last for more than a semester. It’s amazing how much a 15 second pause will cause people to think twice.

Suggested Reading

What is an Arduino?

What is this 'Arduino' thing anyway?

Pulse Width Modulation

An introduction to the concept of Pulse Width Modulation.

Switch Basics

A tutorial on electronics' most overlooked and underappreciated component: the switch! Here we explain the difference between momentary and maintained switches and what all those acronyms (NO, NC, SPDT, SPST, ...) stand for.

Hobby Servo Tutorial

Servos are motors that allow you to accurately control the rotation of the output shaft, opening up all kinds of possibilities for robotics and other projects.

SparkFun Inventor's Kit Experiment Guide - v4.0

The SparkFun Inventor's Kit (SIK) Experiment Guide contains all of the information needed to build all five projects, encompassing 16 circuits, in the latest version of the kit, v4.0a.

And if you really want to get geeky, have a look at this posting on state machines. State machines are a good way to change between the states 'wait for user to press button' to 'ignore buttons and don't dispense right now'.

Hardware Overview

Here’s the list of parts for this project:

SparkFun RedBoard Qwiic

SparkFun RedBoard Qwiic

DEV-15123
$19.95
4
Servo - Generic High Torque Continuous Rotation (Standard Size)

Servo - Generic High Torque Continuous Rotation (Standard Size)

ROB-09347
$13.95
6
SparkFun ProtoShield Kit

SparkFun ProtoShield Kit

DEV-13820
$10.95
1
Wall Adapter Power Supply - 5V DC 2A (Barrel Jack)

Wall Adapter Power Supply - 5V DC 2A (Barrel Jack)

TOL-12889
$5.95
16
Metal Pushbutton - Momentary (16mm, Red)

Metal Pushbutton - Momentary (16mm, Red)

COM-11966
$5.95
6

A proto shield works great. We used an old shield we had lying around but you can use any shield that has a few GPIO broken out that you can solder to.

You’ll of course need a gumball machine. We haven’t verified the continuous servo works with different brands but we’re pretty confident this Gumball Machine will work with this tutorial.

Tools

The tools for this project are pretty common. You may or may not have the various tools around so double check that you have access to the follow:

Hook-Up Wire - Assortment (Solid Core, 22 AWG)

Hook-Up Wire - Assortment (Solid Core, 22 AWG)

PRT-11367
$16.95
30
Solder Lead Free - 100-gram Spool

Solder Lead Free - 100-gram Spool

TOL-09325
$7.95
7
Weller WLC100 Soldering Station

Weller WLC100 Soldering Station

TOL-14228
$44.95
1
Wire Strippers - 22-30AWG

Wire Strippers - 22-30AWG

TOL-14762
$12.95

Continuous Rotation Servo

The magic of the LED Gumball Machine is the fact that a continuous rotation servo mates utterly fantastically with the dispensing cogs within the machine.

Head of servo lining up with cogs on bottom of bowl

A high torque continuous rotation servo is just the ticket for getting electronic control of the dispenser mechanism.

Most servos come with a variety of control horns. These are the plastic bits of different shapes that you screw into the servo to connect the servo to your application. In this tutorial we’ll want the star control horn (highlighted below). Out of complete luck, this horn has roughly the same pitch as the teeth on the gumball machine.

Various servo control horns

The servo has quite a lot of torque and we want that applied to the dispenser mechanism. We mounted the servo with zip ties and hot glue. First, use zip ties to roughly mount the servo in place. Once you get the alignment between the servo head and dispenser gear use hot glue to solidify everything in place. This combination creates the right combination of rough alignment and rigidity so that as much of the torque from the servo is transferred to the dispenser.

Mounted servo with zip ties and hot glue

Button

We chose a momentary light up button.

Single button where knob should be

This fit superbly into the existing hole where the twist knob originally resided. Once mounted, it was a small matter to figure out which pins illuminated the LED and which pins shorted together when the button was pressed.

Wiring behind the momentary button

RedBoard

To tie it all together we used a RedBoard and an old MIDI shield. The MIDI part is not important. Instead, the row of breakout pins at the edge of the board made it easy to solder the handful of wires from the servo and button onto the board and then plug the shield onto the RedBoard.

All parts wired together

This was a more resilient connection method than point soldering to the SMD pads on the I/O of the RedBoard. We could have also used a the Proto Shield or an Arduino Pro Mini but we had these parts lying around.

RedBoard with shield connected to servo and button

Power

The servo requires a fair amount of current at 5V so we used 5V 2A wall supply. The power cable was routed up through the pedestal column and through the mounting plates to plug into the Arduino.

Gumball Machine

Obviously you’re going to need a gumball machine.

Gumball machine filled with LEDs

These are amazing little machines that are well designed for rough use and easy maintenance. We aren’t charging money for the LEDs so we used the area where quarters usually get stored for our electronics.

Cavity showing electronics inside machine

Be sure to get a machine with a metal base and a hollow post. The metal base makes your installation last much longer (students are only slightly less tough on equipment than hyenas) and the hollow post allows us to route power up through the base. I had to enlarge a few holes to ½” in order to allow the DC barrel plug through.

Software

We want the gumball machine to dispense LEDs when the button is pressed, that’s straightforward enough. But we want to avoid dispensing all the LEDs. Also, we don’t want someone to stand in front of the free machine and continually hit the ‘gimme’ button. We implement a timeout of 15 seconds that prevents users from activating the servo constantly. You can get the software here.

Dispensing with PWM

Almost all servos operate on PWM. Before installing the continuous servo in our machine we found the servo responded in the follow ways:

  • gumballServo.write(95); - Stops movement of continous servo
  • gumballServo.write(200); - Servo turns CCW rapidly
  • gumballServo.write(10); - Servo turns CW rapidly (but not used)

Our gumball dispenser was designed to operate clock wise so we only operate our servo counter clockwise.

Handful of LEDs

The dispenser was designed for gumballs obviously so when dispensing LEDs the number of LEDs that actually come out varies wildly. In general the user gets 1 to 5 LEDs when the servo is activated for 1 second. This works well. In the eventual case that LEDs fail to dispense, the user just has to wait 15 seconds to try again. Since we're not charging anything this is an acceptable outcome.

language:c
gumballServo.detach(); //Be sure the servo won't move

After dispensing we detach the servo. This turns off the PWM signal going to the servo guaranteeing the servo won't move. We noticed the servo jittered or moved very slowly at 90 (when it shouldn't be moving) so this extra step insures the LED Gumball Machine won't slowly disgorge itself onto the carpet overnight.

Along those same lines of concern, we noticed that the dispensing mechanism will sometimes bind up causing the servo to draw significantly more current for a short period of time. This can cause the power supply to shut down, causing the Arduino to reset. You'll see at the beginning of setup()

language:c
gumballServo.attach(GUMBALL_SERVO); //Be sure the servo won't move
gumballServo.write(95); //Stop movement on continous servo
gumballServo.detach(); //Be sure the servo won't move

The above code is the first thing the Arduino runs and insures any previous servo movement is stopped. This helps prevent weird rolling reset situations where the servo causes a brownout and as the Arduino comes back on line the servo begins moving, causing a brownout, etc...

Button Monitoring

The button shorts to ground when pressed so we use the internal pullups to pull the button pin high when the button is not pressed.

The button has a built in LED so we connect the +/- pins on the back of the button directly to a PWM enabled pin and Ground. The LED measured 12mA at 5V, well below the 20mA max so we didn't need a resistor.

language:c
//Check if we are allowed to dispense
else if (millis() - lastDispenseTime < minTimeBetweenPresses)
{
    Serial.println("Uh-huh Mr. Eager. Wait your turn.");
    while (digitalRead(BUTTON) == LOW) delay(10); //Wait for user to stop pressing button
    return; //No soup for you!
}

In the code above, we check to see if enough time has passed since the last button press for us to vend again.

language:c
unsigned long minTimeBetweenPresses = 15 * 1000; //Make users wait this amount of ms between dispenses

We found 15 seconds (15,000 milliseconds) between vends was enough time to dissuade students from taking all the LEDs.

Resources and Going Further

We hope you've enjoyed reading about our LED dispensing gumball machine. If you liked this one, there's tons more!

Light

Light is a useful tool for the electrical engineer. Understanding how light relates to electronics is a fundamental skill for many projects.

Switch Basics

A tutorial on electronics' most overlooked and underappreciated component: the switch! Here we explain the difference between momentary and maintained switches and what all those acronyms (NO, NC, SPDT, SPST, ...) stand for.

Processor Interrupts with Arduino

What is an interrupt? In a nutshell, there is a method by which a processor can execute its normal program while continuously monitoring for some kind of event, or interrupt. There are two types of interrupts: hardware and software interrupts. For the purposes of this tutorial, we will focus on hardware interrupts.

SparkFun Troubleshooting Tips

Not working as expected? In this tutorial, we will be exploring a few general troubleshooting tips and possible solutions that frequently come up with SparkFun's Technical Support.

HMC6343 3-axis Compass Hookup Guide

How to hook the HMC6343 -- a high-end, tilt-compensated compass module -- up to an Arduino. Never get lost again!

MPU-9150 Hookup Guide

A basic guide to get started with the MPU-9150 9 Degrees of Freedom Breakout.

Internet of Things Experiment Guide

The SparkFun ESP8266 Thing Dev Board is a powerful development platform that lets you connect your hardware projects to the Internet. In this guide, we show you how to combine some simple components to remotely log temperature data, send yourself texts and control lights from afar.

Qwiic Distance Sensor (RFD77402) Hookup Guide

The RFD77402 uses an infrared VCSEL (Vertical Cavity Surface Emitting Laser) TOF (Time of Flight) module capable of millimeter precision distance readings up to 2 meters. It’s also part of SparkFun’s Qwiic system, so you won’t have to do any soldering to figure out how far away things are.