กลับไปหน้ารวมไฟล์
control-coin-acceptor-with-arduino-36e871-en.md

The purpose of this project is to write code to control a coin acceptor with Arduino so it can be used in other projects. The particular project I had in mind was to build a balance-aware piggy bank for my daughter.

Vending Telemetry: Commercial Coin Acceptor Integration

Converting physical metal currency into digital credits requires extreme temporal precision. This project connects a massive commercial arcade/vending machine coin mechanism (like a CH-926) directly to an Arduino! You absolutely CANNOT simply use standard digitalRead() in the loop() to detect a coin. The coin acceptor fires violently fast 20-millisecond pulses; if the Arduino is busy updating an LCD, the pulse is missed, and the machine literally steals the customer's money!

The Hardware Interrupt Imperative (attachInterrupt)

To guarantee absolutely 100% accurate accounting, the system must utilize explicit Silicon Interrupts!

  1. The Coin Acceptor's signal wire is wired directly to Arduino Pin 2 or Pin 3 (The absolute ONLY pins on an Uno capable of Hardware Interrupts!).
  2. An Interrupt Service Routine (ISR) halts the entire main core instantly the nanosecond a coin drops!
volatile int totalCredits = 0; // MUST be marked volatile! It's altered blindly!

void setup() {
  // If the coin mech pulse goes from 5V falling down to 0V:
  attachInterrupt(digitalPinToInterrupt(2), coinInsertedISR, FALLING); 
}

// This function fires instantly in the background, ignoring all loop() delays!
void coinInsertedISR() {
  totalCredits++; // SECURE THE CURRENCY!
}

The 12V to 5V Level Shifting Danger!

Commercial Coin Acceptors operate on a massive industrial 12-Volt power supply to power their heavy anti-jamming solenoids and internal optical sorters.

  • The signal wire outputs a massive 12V pulse!
  • CRITICAL: If you wire a 12V signal directly into Arduino Pin 2, you will violently incinerate the ATmega328P chip instantly!
  • You MUST construct a Voltage Divider (e.g., a 10K resistor and a 4.7K resistor) or use a logic-level converter to squash the 12V pulse down to a safe 5V logic signal BEFORE it hits the interrupt pin!

Mechanism Hardware Required

  • Arduino Uno/Nano (For hardware interrupt capabilities).
  • Multi-Coin Acceptor (CH-926 / JY-926) (Programmed to recognize specific coin weights, diameters, and metallic signatures natively).
  • Voltage Divider Components (10K / 4.7K Ohm Resistors).
  • Massive 12V Power Adapter (Required to drive the coin mech solenoids independently of the Arduino's delicate 5V rail).
  • Relay Module (To dispense a product or turn on a game once the totalCredits variable hits the threshold!).

ข้อมูล Frontmatter ดั้งเดิม

apps:
  - "1x Arduino IDE"
author: "Dziubym"
category: "Gadgets, Games & Toys"
components:
  - "1x 4 Digit TM1637 LED Display"
  - "1x Arduino Nano R3"
  - "1x Coin Acceptor"
description: "Vending machine architecture! Harness extreme high-speed microsecond interrupts on an Arduino to explicitly count fast optical pulses firing from a commercial coin acceptor, securely transforming physical currency into precise digital credits."
difficulty: "Intermediate"
documentationLinks: []
downloadableFiles: []
encryptedPayload: "U2FsdGVkX1/OqdvN+7VaJ6Qb1vMYuXbTRVYnykY0xGcWKifoekQBrS3Qwj8ggFQ3FXnYhLTIyxIlrGHfdzUK/BoHlmhxz4Pfu5+pVddO5jQ="
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/control-coin-acceptor-with-arduino-36e871_cover.jpg"
lang: "en"
likes: 20
passwordHash: "3de39fe1d23514d572bf1d44137918d395de67b76c4febdd0465dafc6ab7d8bf"
price: 2450
seoDescription: "Learn how to write Code to Control a Coin Acceptor with Arduino for use in various DIY projects."
tags:
  - "nano"
  - "display"
  - "eeprom"
  - "coin acceptor"
  - "tm1637"
  - "interrupt"
  - "4 digit"
  - "arduino"
title: "Control Coin Acceptor with Arduino"
tools: []
videoLinks:
  - "https://www.youtube.com/embed/sfE7yqtd8TA"
views: 62653