Close
0%
0%

IoT-Based Snack Vending Machine with ESP32

The machine uses an ESP32-WROOM-32 as the main controller, driving a custom PCB we laid out in KiCad.

Public Chat
Similar projects worth following
0 followers
We’ve all been there—standing in front of a vending machine at 2 AM, staring at rows of identical candy bars, wondering why nobody’s built a machine that actually knows what you want. So we built one.

This wasn’t a theoretical exercise. A gym chain in Bangalore approached us with a specific problem: their members wanted healthy post-workout snacks, but the existing machines were stocked with junk nobody wanted. Worse, inventory was a guessing game—half the time, protein bars were out of stock while chips sat unsold for weeks.

We designed and shipped a fully functional prototype in 12 weeks. Here’s how it works.

Project Overview

The machine uses an ESP32-WROOM-32 as the main controller, driving a custom PCB we laid out in KiCad. It connects to a cloud backend via MQTT over WiFi, handles payments through UPI and NFC, and personalizes recommendations based on user profiles. We shipped three units to the client for beta testing.

Features

- User recognition via NFC wristband or QR code – Members tap their gym ID band or scan a QR on their phone. No app install required.

- Personalized snack recommendations – Based on purchase history, workout type logged in gym’s system, and time of day. Morning crowd gets oats bars; evening lifters get protein shakes.

- Real-time inventory tracking – Each of the 24 slots has a load cell. When a product drops below threshold, the system flags it automatically.

- Dynamic pricing – Slow-moving items get discounted after 6 PM. Fast-movers stay at full price. All managed from a web dashboard.

- Remote lock/unlock – If a slot jams, we can disable it remotely. No field visit needed.

- Temperature control – Two zones: ambient for bars, refrigerated (4°C) for shakes and yogurts. Controlled via DS18B20 sensors and a Peltier module.

- OTA firmware updates – ESP32 pulls new firmware from an S3 bucket. We’ve pushed 7 updates since deployment without touching a single machine.

- Usage analytics dashboard – Graphs showing hourly sales, popular slots, revenue per machine, and member preferences. Built with Grafana.

Advantages

- No cash handling – UPI and NFC only. Reduces theft risk and maintenance.

- Zero inventory waste – Dynamic pricing clears slow stock. Client reported 94% sell-through rate in first month vs industry average of 72%.

- Member retention tool – Gym saw 18% increase in member check-ins after installing machines. People came for the snack recommendations.

- Remote management – One technician can oversee 50 machines from a laptop. No on-site visits unless hardware fails.

- Low power consumption – ESP32 in deep sleep draws 5 µA. Whole machine runs on 12V DC, pulling 45W peak (mostly from Peltier cooler).

- Customizable slot layout – We used 3D-printed dividers (PLA, 0.4mm nozzle) so slots can be resized for different product dimensions.

- Data-driven restocking – Backend predicts when each slot will run out within ±2 hours accuracy. Client sends one restock run per day instead of two.

- Open-source friendly – All firmware is on GitHub (MIT license). Client can fork and modify.

  • 1 × ESP32-WROOM-32
  • 24 × HX711 + 5kg load cell
  • 1 × PN532 Application Specific ICs / Telecom ICs
  • 1 × RS232 Connectors and Accessories / Connector Tools
  • 3 × DS18B20 Sensors / Temperature, Thermal

View all 17 components

  • Real Video

    Himanshu Dada29 minutes ago 0 comments

  • About Project

    Himanshu Dada32 minutes ago 0 comments

    We don’t do flashy branding here. The client’s gym logo appears on the e-paper display during idle mode. Our logo—a simple circuit trace forming a “D”—is etched into the PCB silkscreen and embossed on the steel enclosure door. That’s it. If the machine works, people don’t care about logos.

    How It Actually Works 

    The ESP32 runs three main FreeRTOS tasks:

    1. Sensor polling task – Reads all 24 load cells via two HX711 multiplexers (we used 74HC4051 analog muxes to save GPIOs). Polls DS18B20s every 5 seconds. Updates e-paper display every 60 seconds (e-paper is slow, but it draws zero power otherwise).

    2. Payment and dispense task – Listens for NFC tap or QR scan. Sends member ID to cloud via MQTT. Cloud returns available balance and recommended items. ESP32 lights up the corresponding slot’s RGB LED green. User presses physical button to confirm. Stepper motor rotates dispensing wheel 180 degrees. Product drops. Load cell confirms weight change. If no change detected (jammed), retries twice then marks slot as faulted.

    3. Cloud sync task – Publishes inventory levels, temperature, and fault status every 60 seconds. Listens for OTA update commands, pricing changes, and remote lock commands. Runs on a 30-second watchdog timer—if it misses a heartbeat, the machine goes into safe mode (no dispensing, only reads).

    The PCB we designed in KiCad has screw terminals for every sensor and motor connection. No JST connectors that can vibrate loose. We learned that lesson on an earlier project.

    The One Thing That Almost Broke Us

    Load cell calibration. Twenty-four load cells, each with a different zero offset and sensitivity. We tried auto-calibration with known weights—too slow. We tried factory calibration values—too inaccurate.

    Solution: We wrote a calibration routine that runs during manufacturing. Place a 100g reference weight on each slot, press a button, firmware stores the offset and gain in NVS (non-volatile storage) on the ESP32. Takes 3 minutes per machine. Accuracy is ±2g. Good enough to detect a missing 50g protein bar.

    Conclusion

    This wasn’t a moonshot. It was a straightforward ESP32 project with careful attention to mechanical reliability and power management. The client got working machines in 12 weeks. Members get snacks they actually want. The gym chain is planning to deploy 50 more units across their locations.

    The full design files—KiCad schematics, Fusion 360 models, firmware source, and PCB Gerbers—are available on our GitHub. If you’re building something similar, start with the load cell calibration routine. That’s where the pain lives.

    Want the Gerber files? Email us. We’ll send them over. No NDAs, no sales pitch. Just a zip file and a note saying “good luck.”

    If you're considering a personalized vending machines deployment, start with the user profile system. The hardware is straightforward. The firmware is manageable. But the personalization logic — that's what drives adoption.

    We shipped fully assembled prototypes to the client within 8 weeks of kickoff. PCB, enclosure (3D printed in PETG for the first run), firmware, and cloud backend. If you need a vending machine for gym that actually sells product, the recipe is simple: ESP32, MQTT, and a recommendation engine that learns from real behavior.

View all 2 project logs

Enjoy this project?

Share

Discussions

Does this project spark your interest?

Become a member to follow this project and never miss any updates