Wiznet makers

Benjamin

Published June 18, 2026 © MIT license (MIT)

122 UCC

11 WCC

14 VAR

0 Contests

0 Followers

2 Following

Original Link

How Does a Smart Vending Machine Authenticate Purchases Over Ethernet with WIZnet W5500?

Four AVR microcontrollers and a WIZnet W5500 Ethernet chip power this cashless vending machine; 10 units were deployed at Rajasthan IT Day 2017.

COMPONENTS Hardware components

WIZnet - W5500

x 1

Provides the machine's wired Ethernet link. Runs a WebSocket client over hardware TCP/IP (SPI) to authenticate purchase codes with the cloud server and receive dispatch commands.


PROJECT DESCRIPTION

📌 Overview

Rhitvik is an embedded systems engineer who, while developing a startup in India, designed and built a cashless vending machine from scratch using AVR microcontrollers and custom PCBs. The project reached production: 10 units were deployed at Rajasthan IT Day 2017 and shown at the Jaipur Literature Fest 2016, and the startup placed third at the Startup Inspire competition at the Indian Industrial Fair 2016, competing against 102 teams from across the country.

The machine lets a user pay through a mobile app, receive a one-time code, enter it on the machine's keypad, and collect the dispensed product. Every purchase code goes over the network for authentication: the WIZnet W5500 Ethernet chip opens a WebSocket connection to a cloud server, sends the code, receives the dispatch command in return (which shelf, which quantity), and signals the local controller to run the motor. That network path is the only link between the machine and the outside world, making the W5500 the single Ethernet gateway for the whole system.

Smart Vending Machine Gen-2, a compact wall-mounted cashless vending unit with keypad and display The Smart Vending Machine Gen-2: a wall-mountable cashless vending unit that authenticates purchases over a WIZnet W5500 Ethernet link.

System Configuration

The machine uses four separate AVR microcontrollers, each with a dedicated job, coordinated over a shared 4-bit parallel bus. The W5500 handles the Ethernet link over SPI and runs the entire cloud communication independently of the other MCUs.

  • ATmega328PU: master communication controller, connects to every other subsystem including the Ethernet controller, motor driver controller, sensor grid controller, and HMI.
  • ATmega16: HMI controller, reads the PIN code entered on the keypad and drives the status display.
  • ATmega32: motor and sensor controller, drives the motor that ejects the product and reads from the IR sensor grid to confirm a successful drop.
  • ATmega8: IR sensor grid controller, monitors 16 IR sensors across the product slots and sends alerts on tampering.
  • WIZnet W5500: hardwired TCP/IP Ethernet chip connected to the ATmega328PU over SPI; runs the WebSocket client that authenticates purchase codes with the cloud server.
  • Libraries: Arduino Ethernet library for W5500 DHCP and socket, WebSocketClient by Pablo, AESLib for optional encryption, ArduinoJson.

System Architecture and Data Flow

System architecture: four AVR microcontrollers connected by a 4-bit bus, with the ATmega328PU bridging to the WIZnet W5500 over SPI and then to the cloud via TCP/WebSocket Generated technical diagram: the W5500 is the sole Ethernet gateway between the local four-MCU cluster and the cloud server; each MCU handles one dedicated role.

The purchase flow runs through a state machine:

  1. User enters PIN on the keypad connected to the ATmega16 (HMI).
  2. ATmega16 transmits digits to the ATmega328PU over a clocked 4-bit parallel bus.
  3. ATmega328PU passes the OTP to the W5500 over SPI.
  4. W5500 sends the code to the server via WebSocket (TCP, port 4500, DHCP address).
  5. Server replies with a dispatch command: O <orderId> <quantity> <shelf>.
  6. ATmega328PU commands the ATmega32 (motor controller) with the shelf number, via the same 4-bit bus.
  7. ATmega32 runs the motor for the chosen slot until the IR sensor grid (ATmega8) confirms the product has dropped.
  8. ATmega328PU sends dispatch ACK to the server over the WebSocket connection.

If the PIN is wrong the server replies with an error event and the machine resets. If the Ethernet connection drops, the W5500 re-initiates DHCP and re-opens the WebSocket before the next request.

Inside the Machine

Interior of the Smart Vending Machine showing the motor rack, IR sensor grid, and control boards mounted inside the chassis Inside the Smart Vending Machine: motor rack (bottom), IR sensor grid (product slots), and the control board assembly.

The physical design is compact and wall-mountable. Each product slot has a dedicated motor and a pair of IR sensors to confirm whether the product dropped successfully. The IR grid is driven by the ATmega8 and feeds status back to the ATmega32 motor controller, which closes the feedback loop without involving the cloud until confirmation is needed. Power comes from a modified PC power supply unit, providing 5V for the MCUs and 12V for the motors.

⚙️ Role of the WIZnet W5500

The W5500 is the only external network interface in the machine. No cellular or Wi-Fi is used; the machine assumes a wired Ethernet connection at the installation site, which is typical for fixed wall-mounted equipment in commercial or institutional settings.

The Arduino Ethernet library uses the W5500's hardware TCP/IP stack to handle DHCP, TCP connection management, and socket operations via SPI, so the ATmega328PU does not run a software network stack. The WebSocket handshake and message framing layer runs on top of the Arduino Ethernet client, leaving the W5500 to handle the IP-layer work in hardware. This matters for a low-power AVR: offloading TCP/IP to the W5500 leaves the ATmega328PU free to manage the 4-bit inter-MCU bus, parse server messages, and coordinate the dispatch lifecycle.

The state machine in the Ethernet controller code (SocketClient_Ethernet_StateMachine_polled.ino) reflects this cleanly: the W5500 handles connectivity, and the application layer above it handles only machine state (register, send OTP, wait for order, command machine, send ACK).

From Gen-1 to Gen-2, and Into the Field

Smart Vending Machine Gen-1, an earlier version of the cashless vending unit The Smart Vending Machine Gen-1, the first version deployed in the field; the Gen-2 brought a more compact and refined mechanical design.

The project went through two hardware revisions. Gen-1 established the architecture and was the version shown at Jaipur Literature Fest 2016 and used for the Startup Inspire competition. Gen-2 refined the mechanical chassis and control board layout, and was the version deployed in quantity at Rajasthan IT Day 2017. Custom PCBs for the control board, the sensor RX board, and the sensor TX board were all fabricated, with Gerber files and pick-and-place data included in the repository.

The scale of the deployment is notable: 10 machines running simultaneously at a government technology event, distributing goodies and gifts to participants, is a meaningful real-world test for an embedded project that started as a startup idea.

Where It Fits and What It Does Not Cover

This project is a complete embedded reference for a cashless IoT vending machine: custom PCBs, firmware for four AVR MCUs, Ethernet socket client code, inter-MCU bus protocol, IR sensor grid, and motor control. It is well-suited as a starting point or reference for anyone building fixed-network embedded machines that need a simple cloud authentication or command loop.

The server-side code (the backend that receives OTPs, verifies them against purchases, and replies with dispatch commands) is not in the repository. The machine is also designed for a fixed Ethernet connection only; a site without wired Ethernet would need an additional gateway or a different network interface. The IR sensor feedback prevents false dispatch acknowledgments, but the code does not include a full inventory management layer.

Related WIZnet Maker Projects

Cashless and IoT-connected vending machines are a recurring theme on the Maker site. These three projects connect to the same problem space from different angles.

MDB Arduino Cashless connects a vending machine to a cashless payment system using the MDB (Multi-Drop Bus) protocol and a WIZnet Ethernet chip. Where this project builds the entire machine from AVR MCUs up, Hannah's project focuses on adding a cashless payment interface to an existing vending machine over MDB, which is the industry-standard protocol between vending machines and payment terminals. The two complement each other: one for building a machine, one for connecting an existing one to a payment network.

Easymeal IoT MDB Router is an IoT gateway that bridges a vending machine's MDB bus to the cloud using a WIZnet W5500. Where Rhitvik's machine is a standalone unit with its own controller, Easymeal connects existing vending machines to cloud services through their MDB ports. Both use the W5500 for the Ethernet link to the cloud, but the Easymeal project targets the retrofit case and uses the MDB protocol for machine communication.

Vending Machine / Cashless Device Implementation covers cashless payment implementation for vending machines, which is the same problem this project solves from the user-facing side. Comparing the two shows different approaches to the same cashless purchase loop, useful context for anyone designing a similar system.

❓ FAQ

Q. What does the WIZnet W5500 do in this vending machine? The W5500 is the Ethernet gateway for the whole machine. It connects to the cloud server over TCP using a WebSocket client, sends the purchase PIN entered by the user for authentication, receives a dispatch command (shelf number and quantity) back from the server, and confirms successful delivery. No other part of the machine communicates with the outside world.

Q. Why does the machine use four separate AVR microcontrollers instead of one? Each MCU handles exactly one task: ATmega16 reads the keypad and drives the display, ATmega32 controls motors and reads the IR sensor grid, ATmega8 monitors 16 IR sensors, and ATmega328PU coordinates all of them and bridges to the W5500 over SPI. Splitting the workload like this keeps each MCU's firmware simple and makes it easier to debug and replace individual subsystems.

Q. How does the machine confirm that a product was successfully dispensed? The ATmega8 runs 16 IR sensors, one for each product slot. When a motor runs and a product falls, the IR beam is broken. The ATmega8 signals the ATmega32 motor controller, which stops the motor and reports success to the ATmega328PU master. Only after this confirmation does the machine send the dispatch acknowledgment to the server.

Q. Is there a mobile app for this machine? Yes. The purchase flow relies on a mobile app: the user browses inventory, selects a product, pays through the app, and receives a one-time code. The app itself is not in this repository, which contains only the firmware and hardware files for the machine.

Q. Can this machine be expanded to more product slots? The README notes that the system can be expanded to control up to 256 motors by modifying the sensor communication bus and adding more ATmega32 units. The 4-bit parallel bus and the W5500 Ethernet interface are not the bottleneck; the limit is the sensor bus addressing and the motor driver count.


한국어 (Korean)

📌 개요

Rhitvik은 인도에서 스타트업을 운영하던 임베디드 시스템 엔지니어로, AVR 마이크로컨트롤러와 커스텀 PCB를 이용해 현금 없는 자판기를 직접 설계·제작했습니다. 프로젝트는 실제 양산까지 이어졌습니다. 2017년 Rajasthan IT Day에 10대가 배치됐고, 2016년 Jaipur Literature Fest에서 전시됐으며, 스타트업 팀은 2016 인도 산업 박람회 'Startup Inspire'에서 전국 102개 팀 중 3위를 차지했습니다.

구매 흐름은 모바일 앱에서 결제 후 일회용 코드를 받아 기기 키패드에 입력하면 제품이 배출되는 방식입니다. 인증 과정은 전적으로 네트워크를 통해 이루어집니다. WIZnet W5500 이더넷 칩이 WebSocket 연결로 클라우드 서버에 코드를 전송하고, 배출 명령(어느 선반, 몇 개)을 받아 로컬 컨트롤러에 전달합니다. W5500은 이 시스템의 유일한 이더넷 게이트웨이입니다.

스마트 자판기 Gen-2, 키패드와 디스플레이가 달린 벽걸이형 현금 없는 자판기 스마트 자판기 Gen-2: WIZnet W5500 이더넷 링크로 구매를 인증하는 벽걸이형 현금 없는 자판기.

시스템 구성

이 자판기는 각자 전담 역할을 맡은 4개의 AVR 마이크로컨트롤러가 4비트 병렬 버스로 협력합니다. W5500은 SPI로 이더넷 링크를 담당하며, 클라우드와의 통신을 독립적으로 처리합니다.

  • ATmega328PU: 마스터 통신 컨트롤러. 이더넷·모터 드라이버·센서 그리드·HMI 컨트롤러 모두와 연결.
  • ATmega16: HMI 컨트롤러. 키패드에서 PIN 코드를 읽고 상태 디스플레이를 구동.
  • ATmega32: 모터·센서 컨트롤러. 제품을 배출하는 모터를 구동하고 IR 센서 그리드로 배출 성공 여부 확인.
  • ATmega8: IR 센서 그리드 컨트롤러. 제품 슬롯 전체 16개 IR 센서 모니터링, 외부 조작 시 경보.
  • WIZnet W5500: 하드웨어 TCP/IP 이더넷 칩. ATmega328PU와 SPI로 연결, 클라우드 서버와 WebSocket으로 구매 코드 인증.
  • 라이브러리: Arduino Ethernet(W5500 DHCP·소켓), WebSocketClient by Pablo, AESLib, ArduinoJson.

시스템 아키텍처 및 데이터 흐름

시스템 아키텍처: 4개 AVR MCU가 4비트 버스로 연결되고, ATmega328PU가 SPI로 W5500에 연결 후 TCP/WebSocket으로 클라우드로 연결 생성된 기술 다이어그램: W5500이 로컬 4-MCU 클러스터와 클라우드 서버 사이의 유일한 이더넷 게이트웨이입니다.

구매 흐름은 다음 상태 머신으로 동작합니다:

  1. 사용자가 키패드에 PIN 입력 - ATmega16(HMI)이 읽음.
  2. ATmega16이 4비트 병렬 버스로 ATmega328PU에 전달.
  3. ATmega328PU가 OTP를 SPI로 W5500에 전달.
  4. W5500이 WebSocket(TCP, 포트 4500)으로 서버에 코드 전송.
  5. 서버가 배출 명령 응답: O <orderId> <수량> <선반>.
  6. ATmega328PU가 ATmega32에 선반 번호 전달.
  7. ATmega32가 모터를 구동, ATmega8 IR 센서로 제품 낙하 확인.
  8. ATmega328PU가 서버에 배출 ACK 전송.

기기 내부

스마트 자판기 내부: 모터 랙, IR 센서 그리드, 제어 보드가 케이스 안에 장착된 모습 자판기 내부: 모터 랙(하단), IR 센서 그리드(제품 슬롯), 제어 보드 조립체.

컴팩트한 벽걸이형 디자인으로, 각 슬롯마다 전용 모터와 IR 센서 쌍이 있어 배출 성공 여부를 확인합니다. 전원은 개조된 PC 파워서플라이로 MCU용 5V와 모터용 12V를 공급합니다.

⚙️ WIZnet W5500의 역할

W5500은 자판기의 유일한 외부 네트워크 인터페이스입니다. 셀룰러나 Wi-Fi는 사용하지 않습니다. Arduino Ethernet 라이브러리가 W5500의 하드웨어 TCP/IP 스택을 이용해 DHCP, TCP 연결, 소켓을 처리하므로 ATmega328PU에 소프트웨어 네트워크 스택이 필요 없습니다. 저전력 AVR에서 TCP/IP를 W5500에 오프로드하면 MCU는 MCU 간 4비트 버스 관리, 서버 메시지 파싱, 배출 생명주기 조율에만 집중할 수 있습니다.

Gen-1에서 Gen-2, 그리고 현장 배포

스마트 자판기 Gen-1, 현장 배포된 초기 버전 Gen-1: 2016년 Jaipur Lit Fest와 Startup Inspire 경진대회에서 선보인 초기 버전. Gen-2는 기계 설계와 제어 보드 레이아웃을 개선해 2017년 양산 배포됐습니다.

Gen-1이 아키텍처를 확립하고 Jaipur Literature Fest와 Startup Inspire(3위)에서 전시됐으며, Gen-2가 기구부와 제어 보드를 개선해 Rajasthan IT Day 2017에 10대 배포됐습니다. 저장소에는 제어 보드, 센서 RX 보드, 센서 TX 보드 모두의 Gerber 파일과 pick-and-place 데이터가 포함되어 있습니다.

활용처와 한계

이 프로젝트는 현금 없는 IoT 자판기를 위한 완결형 임베디드 레퍼런스입니다. 커스텀 PCB, 4개 AVR MCU 펌웨어, 이더넷 소켓 클라이언트 코드, MCU 간 버스 프로토콜, IR 센서 그리드, 모터 제어가 모두 포함됩니다.

한계: 서버 측 코드(OTP 검증 및 배출 명령 백엔드)는 저장소에 없습니다. 유선 이더넷만 지원하므로 배선이 없는 현장에는 별도 게이트웨이가 필요합니다.

관련 WIZnet 메이커 프로젝트

MDB Arduino Cashless - MDB(Multi-Drop Bus) 프로토콜과 WIZnet 이더넷으로 기존 자판기에 현금 없는 결제를 추가하는 프로젝트. Rhitvik의 프로젝트가 자판기 전체를 직접 만들었다면, 이 프로젝트는 기존 자판기에 결제 인터페이스를 추가합니다. 둘은 서로 보완합니다.

Easymeal IoT MDB Router - WIZnet W5500으로 기존 자판기의 MDB 버스를 클라우드에 연결하는 IoT 게이트웨이. 레트로핏 방식으로 W5500 이더넷 링크를 활용하는 점은 같지만, 자체 제작 기기가 아닌 기존 자판기 연결에 초점을 맞춥니다.

Vending Machine / Cashless Device Implementation - 자판기 현금 없는 결제 구현 프로젝트. 사용자 측에서 같은 현금 없는 구매 루프를 다른 방식으로 접근한 사례입니다.

❓ 자주 묻는 질문 (FAQ)

Q. 이 자판기에서 WIZnet W5500은 무엇을 하나요? W5500은 자판기 전체의 이더넷 게이트웨이입니다. WebSocket 클라이언트로 클라우드 서버에 연결해 사용자가 입력한 구매 PIN을 전송하고, 배출 명령(선반 번호·수량)을 받아 로컬 컨트롤러에 전달하며, 성공 배출을 ACK로 확인합니다. 기기에서 외부와 통신하는 유일한 컴포넌트입니다.

Q. 왜 AVR MCU를 4개나 분리해서 사용하나요? 각 MCU가 딱 하나의 역할만 담당합니다. ATmega16은 키패드·디스플레이, ATmega32는 모터·IR 센서, ATmega8은 16개 IR 센서 모니터링, ATmega328PU는 전체 조율과 W5500 SPI 브리지입니다. 이렇게 분리하면 각 펌웨어가 단순해지고 서브시스템별 교체·디버깅이 쉬워집니다.

Q. 제품이 정말 배출됐는지 어떻게 확인하나요? ATmega8이 각 슬롯의 IR 빔을 모니터링합니다. 모터가 돌아 제품이 떨어지면 IR 빔이 차단됩니다. ATmega8이 ATmega32에 알리면 ATmega32가 모터를 멈추고 ATmega328PU 마스터에 성공을 보고합니다. 이 확인이 완료된 후에만 서버에 배출 ACK가 전송됩니다.

Q. 이 자판기용 모바일 앱도 있나요? 네. 사용자는 앱에서 재고를 확인하고 제품을 선택해 결제하면 일회용 코드를 받습니다. 앱 코드는 이 저장소에 포함되지 않으며, 저장소는 자판기 펌웨어와 하드웨어 파일만 담고 있습니다.

Q. 슬롯을 더 늘릴 수 있나요? README에 따르면 센서 통신 버스를 조정하고 ATmega32를 추가하면 최대 256개 모터까지 확장할 수 있습니다. W5500 이더넷 인터페이스나 4비트 버스가 병목이 아니라, 센서 버스 주소 지정과 모터 드라이버 수가 한계입니다.

Documents
  • GitHub Repository (Smart Vending Machine)

    Full source: firmware for all 4 AVR MCUs, Gerber files, schematics, pick-and-place files

  • Demo Video (YouTube)

    Working demo of the Smart Vending Machine

  • WIZnet W5500

    The hardwired TCP/IP Ethernet chip used as the cloud gateway

  • Arduino Ethernet Library

    Library used for W5500 DHCP and TCP socket management

Comments Write