Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
Bettesworth Construction
Arduino

Build an Arduino-Powered Candy Vending Machine

A reliable Arduino candy vending machine starts with the mechanics: choose one consistent candy format, prototype a gravity-fed hopper, and use a servo-driven pusher before adding coins or multiple selections.

By Bettesworth Construction Team 8 min read

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build the machine around a gravity-fed hopper and a mechanically constrained one-item dispenser. For a first version, use a pushbutton to trigger a positional servo and sliding pusher; add tokens, coins, displays, or multiple candy types only after the mechanism dispenses reliably.

This is a tabletop prototype, not a commercial vending machine. Its reliability depends more on candy dimensions, hopper geometry, and power delivery than on complex Arduino code.

How the machine works

Button / token / coin
          ↓
       Arduino
          ↓
 Servo or stepper → dispenser mechanism
          ↓
       Candy chute
          ↓
 Optional delivery sensor → Arduino

Candy rests in a hopper. Gravity moves the stack toward a retaining ledge, while a servo-driven gate or pusher releases the bottom item. The item falls into a chute, and the actuator returns to its home position.

A sliding pusher is the most practical general-purpose design. SparkFun documented a similar gravity-fed chocolate dispenser with a servo-driven sliding mechanism and first prototyped it in cardboard: see the project documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
ELEGOO UNO R3 Project Super Starter Kit with PDF Tutorial for Beginners
  • TURN CODE INTO REAL-WORLD RESULTS — Follow 22+ guided lessons to make LEDs blink, read temperature and distance, move servo and stepper motors, control an LCD and respond to joystick or IR input; ideal for a family weekend build, homeschool unit, coding club or STEM classroom
  • MORE PROJECT VARIETY IN ONE ORGANIZED KIT — Includes the UNO R3 controller, LCD1602 with pre-soldered header, breadboard power module, ultrasonic and DHT11 sensors, joystick, IR receiver and remote, SG90 servo, stepper motor, relay, DC motor, fan blade, displays, LEDs, buttons, resistors and jumper wires
  • START WITHOUT SOLDERING — Plug-in modules, a solderless breadboard and the pre-soldered LCD help beginners focus on wiring, code and testing; the illustrated component list makes it easier to find each part and move from one lesson to the next
  • LEARN THE LOGIC, THEN CREATE YOUR OWN — Use Arduino IDE and the included example code to understand digital input and output, analog sensing, timing, motor control and display functions, then change thresholds, speeds and sequences for alarms, environmental monitors, reaction games and motion projects
  • CLEAR SETUP SUPPORT FOR FIRST-TIME BUILDERS — Download the latest tutorial and code, select the UNO board and correct computer port, check component polarity and breadboard rows, and keep power-module input at 9V or below; younger learners should work with an experienced adult

Choose the candy first

Do not design for “any candy.” Measure a particular item and define its maximum width, thickness, length, weight, wrapper friction, and tendency to bridge or rotate.

Candy Suitability Main problem
Gumballs Excellent Needs a compatible pocket wheel or chute
Uniformly wrapped bars Good Wrapper friction and hopper clearance
Wrapped hard candy Moderate Irregular shapes can jam
Loose small candy Poor Several pieces may fall together
Sticky or heat-sensitive candy Poor Adhesion and deformation
Large candy bars Possible Needs a strong pusher or spiral

Make the dispensing channel only slightly wider than the chosen item and prevent two items from passing side by side. A “one piece” claim is meaningful only for the dimensions and mechanism you have tested.

Recommended parts

Required

  • Arduino UNO-compatible board
  • 180-degree positional hobby servo
  • Separate regulated 5 V supply sized for the servo
  • Pushbutton, jumper wires, and a breadboard or prototyping board
  • Hopper, retaining ledge, pusher channel, and chute
  • Rigid construction material such as acrylic, plywood, foam board, cardboard for a prototype, or suitable 3D-printed parts

The Arduino UNO R4 Minima is a suitable current choice: Arduino lists its UNO form factor and 5 V operation, with broad hardware compatibility with UNO R3 accessories. AVR-specific libraries or code may still require changes. An UNO R3 also works with conventional Servo-library sketches. Prices and availability change, so check the official store before buying.

Optional

  • IR break-beam sensor for delivery confirmation
  • Status LED and buzzer
  • Token or coin acceptor
  • Keypad and LCD or OLED display
  • Second actuator for another candy column

Select the dispensing mechanism

Sliding pusher: best first build

  1. The bottom candy rests on a retaining ledge.
  2. The servo drives a flat paddle forward.
  3. The paddle pushes one item into the exit chute.
  4. The servo retracts and the next item settles into position.

This works best with small packets or bars of consistent size. Use a short, guided pusher rather than relying on the servo horn alone.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
ELEGOO UNO R3 Project Most Complete Starter Kit, Compatible with Arduino
  • 30+ Guided Electronics Projects: Start with LEDs and build toward LCD1602 displays, RFID access, motion detection, distance sensing, motor control and environmental monitoring for STEM learning, coding clubs, classrooms and hobby projects
  • 200+ Components Across 63 Types: Includes an ELEGOO UNO R3 controller, LCD1602, RC522 RFID, RTC, HC-SR501 PIR sensor, ultrasonic sensor, DHT11, GY-521, MAX7219, keypad, joystick, relay, SG90 servo, stepper motor, breadboard and more
  • Begin Without Soldering: Pre-soldered modules, a solderless breadboard, organized storage case and small-parts box reduce setup time and help beginners move from lesson to lesson while keeping LEDs, ICs, wires and sensors easy to find
  • Learn, Modify and Create: Program the ELEGOO UNO R3 board with Arduino IDE using the included PDF tutorial and example code, then adjust sensor thresholds, timing, display text and motor behavior to turn guided lessons into original projects
  • Flexible Power and Project Setup: Includes a 9 V, 1 A power supply, breadboard power module, 9 V battery and USB cable to support controller, breadboard and module experiments without sourcing basic setup accessories separately

Rotating pocket wheel

A wheel with a pocket captures one gumball or similarly uniform item and rotates it to the outlet. It provides positive metering, but the pocket must match the candy closely. SparkFun’s gumball project used a continuous-rotation servo to turn the original machine’s dispensing cog.

Spiral coil

A rotating helical coil gives a familiar vending-machine appearance and suits uniform packages, especially in multiple columns. It is harder to fabricate accurately and can leave an item partly supported at the edge. Use a stepper or geared DC motor with the appropriate driver and position or end-stop feedback; a standard positional servo is usually not the right actuator.

Choose the actuator

Actuator Best use Trade-off
180° positional servo Pusher, flap, or gate Simple, but limited travel
Continuous-rotation servo Pocket wheel or cog Controls speed and direction, not exact angle
Stepper motor Indexed wheel or coil Repeatable, but needs a driver and homing
Geared DC motor Coil or conveyor Powerful and inexpensive, but needs feedback

As SparkFun explains, a positional servo moves to a commanded angle, while a continuous-rotation servo responds mainly with speed and direction. A specific high-torque continuous-rotation servo, for example, is specified by SparkFun for 4.8–6.0 V operation and up to 66.7 oz-in torque at 6 V; those figures do not apply to every servo.

Build the hopper and chute

  1. Measure the candy envelope. Record the largest item dimensions and allow enough clearance for wrappers without allowing double feeds.
  2. Prototype in cardboard. Build only the hopper, retaining ledge, pusher channel, and chute. Test 10–20 pieces manually before making the finished enclosure.
  3. Guide the pusher. It should travel straight and expose only the bottom item.
  4. Provide a real home position. The pusher must retract far enough for the next item to settle. A physical guide or stop is preferable to software timing alone.
  5. Mount the servo rigidly. A flexible mount changes the travel distance and wastes torque. Hot glue is acceptable for an early prototype, but use brackets or screws for repeated operation.
  6. Make refilling and clearing easy. Include a removable lid or access panel and avoid hidden cavities where wrappers can accumulate.

Wire the Arduino safely

Function Pin
Servo signal D9
Dispense button D2
Optional delivery sensor D3
Status LED D13
Optional buzzer D8
5 V regulated supply positive  ─── Servo V+
5 V regulated supply ground    ─── Servo GND
Arduino GND                    ─── Common ground
Arduino D9                     ─── Servo signal
Arduino D2                     ─── Button terminal 1
Arduino GND                    ─── Button terminal 2

Use INPUT_PULLUP, so the button reads HIGH when idle and LOW when pressed. Do not make the Arduino’s 5 V pin the default power source for a mechanically loaded servo. Use a regulated external supply, connect its ground to Arduino ground, and use short, suitably thick motor wiring. If motion causes resets, add a large electrolytic capacitor near the servo supply and correct the power system rather than simply increasing software delays.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
REXQualis Super Starter Kit Based on Arduino UNO R3 with Tutorial and Controller Board Compatible with Arduino IDE
  • The most economical kit comes with everything compatible with Arduino to starting programming for beginners .
  • This is the upgraded starter kits come with a 9V 1A Power Adapter (At least $5.99 on amazon) to replace a 9V Battery , and the Lcd1602 module come with pin header(not need to be soldered by yourself).
  • Include High Quality Base Board base on Arduino UNO R3 compatible with Arduino IED and Sensors, Servo, Motor, ULN2003 driver board, lcds, etc.
  • Free PDF Tutorial and Datasheet are available to download from our official website or you can contact our customer service.
  • All of the Components and Integrated Circuits are individually packaged and labeled, and packing in a plastic box which is bigger enough for you.

A bare DC motor or stepper motor must use a suitable driver. Never connect either directly to an Arduino GPIO pin.

Upload a first servo test

#include <Servo.h>

Servo dispenser;
const byte SERVO_PIN = 9;
const int HOME_ANGLE = 10;
const int PUSH_ANGLE = 80;

void setup() {
  dispenser.attach(SERVO_PIN);
  dispenser.write(HOME_ANGLE);
}

void loop() {
  dispenser.write(PUSH_ANGLE);
  delay(450);
  dispenser.write(HOME_ANGLE);
  delay(1000);
}

Run this before attaching the pusher. The angles are starting values, not universal settings. Move the servo through safe positions, then adjust the linkage in small increments. Never command the servo to fight a hard stop for an extended period.

Add the dispense button

#include <Servo.h>

Servo dispenser;
const byte SERVO_PIN = 9;
const byte BUTTON_PIN = 2;
const int HOME_ANGLE = 10;
const int PUSH_ANGLE = 80;
bool busy = false;

void setup() {
  dispenser.attach(SERVO_PIN);
  dispenser.write(HOME_ANGLE);
  pinMode(BUTTON_PIN, INPUT_PULLUP);
}

void loop() {
  if (!busy && digitalRead(BUTTON_PIN) == LOW) {
    busy = true;
    dispenseOne();
    delay(250);
    busy = false;
  }
}

void dispenseOne() {
  dispenser.write(PUSH_ANGLE);
  delay(450);
  dispenser.write(HOME_ANGLE);
  delay(650);
}

The busy flag prevents a second request during the cycle, while the final delay provides basic debounce and settling time. Tune both delays to the mechanism. A production-quality prototype should replace the blocking delays with a non-blocking state machine, but this guarded sketch is adequate for initial mechanical testing.

Tune one-item dispensing

Test in stages:

  1. Run 20–50 empty cycles. Check alignment, binding, servo temperature, loose screws, and Arduino resets.
  2. Test one candy at a time.
  3. Test a partially filled hopper.
  4. Only then test a completely loaded hopper.

Adjust servo angles, pusher thickness, hopper slope, chute width, travel distance, and settling pauses. If two items emerge, narrow the throat or add a retaining ledge. If nothing emerges, do not keep increasing servo force: check for bridging, insufficient slope, an undersized opening, sticky wrappers, or a slipping horn.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Add delivery confirmation

Mount an IR break-beam sensor across the delivery chute, after the item leaves the hopper. The emitter and receiver must be aligned so the candy interrupts the beam. Adafruit describes this arrangement in its break-beam sensor documentation.

Rank #4
Arduino Starter Kit R4 [K000007_R4] – Learn Electronics and Coding with the UNO R4 WiFi Board, 13 Guided Projects in a Printed Book + Growing Resources Online, Official Certification Voucher
  • LEARN ELECTRONICS AND CODING FROM SCRATCH: Start your maker journey or enhance classroom learning with the Arduino Starter Kit R4 – no prior experience required. Includes a printed project book and all components for 13 hands-on tutorials, as well as access to a growing repository of projects that will be added over time.
  • POWERED BY THE ARDUINO UNO R4 WIFI BOARD: Discover modern connectivity and performance with the Arduino UNO R4 WiFi, featuring built-in Wi-Fi and Bluetooth and full compatibility with the Arduino ecosystem.
  • CERTIFICATION VOUCHER INCLUDED: Once you’ve mastered sensors, motors, displays, and logic through the projects, take the official Arduino Fundamentals certification exam with the voucher that comes with your kit.
  • BONUS DIGITAL RESOURCES: Register your kit online to unlock extra projects, multilingual lessons (Italian, German, French), and exclusive online content designed by the Arduino team.
  • DESIGNED FOR LEARNING AND TEACHING: Ideal for classrooms, labs, or self-learners. Combine hands-on experiments with clear explanations and an AI coding assistant to support you as you grow.

A robust cycle is:

Request received
→ actuator moves
→ actuator returns home
→ item detected
→ vend complete

If the beam is not interrupted within a timeout, stop and report a jam or empty hopper. Do not automatically dispense another item, particularly if the machine has accepted a coin or token. Detection can vary with alignment, distance, ambient light, and wrapper material; shield the sensor and test it with the actual candy.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Add tokens or coins

A token input preserves the vending-machine experience without the accounting and safety problems of real money. A coin-operated version should implement a transaction state:

IDLE
→ coin detected
→ credit increased
→ selection accepted
→ credit checked
→ dispense
→ delivery confirmed
→ credit deducted
→ IDLE

Many coin acceptors output pulses, but pulse count, timing, voltage level, accepted-coin programming, and wiring vary by model. The Arduino Forum example illustrates pulse counting; it is not a universal wiring specification.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Handle coins inserted during a vend, multiple pulses from one coin, invalid coins, stuck acceptors, remaining credit, power loss, and no-change operation. Counting pulses is not the same as validating payment, issuing refunds, or protecting a customer from a failed vend. For an unattended public machine, payment, electrical, accessibility, consumer-protection, and food-handling requirements need separate review.

Best Value
SunFounder Elite Explorer Kit with Original Arduino® UNO™ R4 WiFi, Powered by Arduino, RoHS Compliant, Bluetooth IoT ESP32 LCD1602 OLED, Super Starter Kit, Video Courses for Beginners & Engineers
  • All-in-One Starter Kit for Beginners: Part of the Powered by Arduino program, this kit includes an original Arduino UNO R4 WiFi, 300+ high-quality components, 50+ hands-on projects (30 basic, 13 fun, and 8 IoT), and 100+ free video lessons co-created with renowned educator Paul McWhorter. Designed for beginners ages 8+, it provides a complete, step-by-step path to learn Arduino, electronics, coding, and IoT. RoHS compliant for added safety and quality, it also makes a thoughtful gift for tech enthusiasts, students, and aspiring makers for birthdays, holidays, and special occasions
  • Powerful Arduino Uno R4 WiFi Board: Upgraded from the Arduino Uno R3, the Arduino Uno R4 WiFi features a 32-bit processor, more memory, and built-in WiFi and Bluetooth, enabling connection to third-party apps for more interactive and practical projects.
  • 300+ Components for Endless Possibilities: With 300+ components and sensors, this kit is perfect for portable projects. It features step-by-step tutorials, open-source code, and compatibility with other Arduino boards like Uno R3 and Nano, offering endless customization and learning opportunities.
  • Engaging Projects for Every Skill Level: Featuring 50 projects (30 basic, 13 fun, 8 IoT) with IoT app integration like Arduino IoT Cloud , this kit supports Arduino C++ programming, making it perfect for students, teachers, and engineers to learn, code, and create at any skill level.
  • Dedicated Support for Beginners: Alongside online resources and video tutorials, SunFounder provides technical support and troubleshooting forums to help beginners solve programming challenges with ease.

Expand to multiple candy types

For four selections, the simplest arrangement is four separate hoppers and four servos. It is straightforward to debug but increases wiring, power requirements, and software states.

Other options include four helical coils with motor drivers, a mechanically indexed selector, or a rotating carousel with position sensing. The larger Arduino-documented DIY vending machine used multiple storage spaces, continuous-rotation servos, a stepper-driven product mechanism, and an elevator, demonstrating how quickly a multi-product build becomes more complex: Arduino’s project overview.

Troubleshooting

Two candies dispense

  • Narrow the chute and opening.
  • Add a retaining ledge or pocket wheel.
  • Reduce pusher travel.
  • Restrict the machine to a more uniform candy.

No candy dispenses

  • Look for hopper bridging.
  • Check pusher travel and servo-horn attachment.
  • Increase the hopper slope modestly.
  • Remove sticky or oversized items.
  • Redesign the throat instead of forcing the actuator.

The Arduino resets

  • Use a separate regulated servo supply.
  • Connect grounds together.
  • Inspect connectors and wiring.
  • Add local supply capacitance.
  • Size the supply for startup and stall current, not average current.

The servo chatters

The mechanism may be forcing the servo against a stop, the supply may be unstable, or the commanded angle may be too close to its limit. Reduce the angle, improve alignment, add compliance, and move the physical stop.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A continuous-rotation servo will not stop

Continuous-rotation servos differ in their neutral setting. Calibrate the actual stop command for your unit rather than assuming a nominal center value.

Useful upgrades

  • OLED or LCD selection display
  • Buzzer and status LEDs
  • RFID or supervised token input
  • Low-stock sensor
  • Stepper-driven indexed carousel
  • Wi-Fi monitoring with an UNO R4 WiFi
  • Removable, cleanable chute

The UNO R4 WiFi is useful when remote status or web control is genuinely needed, but connectivity adds software scope and is unnecessary for a standalone dispenser. A basic button-operated machine is easier to test and safer to demonstrate.

Safety and construction limits

  • Guard moving linkages and keep fingers away from pinch points.
  • Insulate electrical connections and provide strain relief.
  • Use a fuse or current-limited supply for larger installations.
  • Remove wrapper debris and make refill and cleaning access easy.
  • Do not describe unfinished plywood, hot glue, or an arbitrary 3D-printing filament as food-safe.
  • Do not operate an unattended real-money machine without appropriate compliance review.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

More from the Site Office

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.