coin acceptor/Reading the pulses/08. COIN or COUNTER: pick one wire
Reading the pulses · 08 of 11

COIN or COUNTER: pick one wire

The module hands out two signal pins and you only wire one. COIN sends a burst whose length says which coin. COUNTER sends one pulse per accepted coin and nothing else. On the smallest coin they look identical, which is how the confusion starts.

One coin, two wires

COIN counts the value, COUNTER counts the coin
25c · 3 pulses
Which coin
Pulses on COIN
Pulses on COUNTER
Tells them apart
COIN only
Same coin, two wires. Press the button and watch both traces: the number of pulses is the only difference, and it is the whole difference.

Drop the same coin in and both wires respond, differently. COIN sends as many pulses as that coin is programmed for. COUNTER sends exactly one, whatever the coin was.

That single pulse is a genuinely useful fact — something was accepted — and it arrives immediately rather than after a train of pulses has finished. If your project is a door, a dispenser, a game that starts, or anything where one coin buys one thing, COUNTER is the simpler wire and there is nothing to program wrong.

Which wire answers which question

You want to knowWireWhy
A coin arrivedCOUNTEROne pulse, immediately, no counting
How many coins so farCOUNTERCount the pulses
How much money so farCOINThe pulse count carries the value
Which coin it wasCOINSame reason

The one-pulse coincidence

Test with a coin programmed to one pulse and the two wires do the same thing. It is easy to conclude from that test that COUNTER is just a second COIN pin, wire COUNTER, write a money-totalling sketch, and then discover that every coin adds the same amount.

Test with your largest coin instead. The difference is immediate and obvious.

Both idle high

Whichever you pick, the pin sits at your board's logic voltage when nothing is happening and is pulled down to ground for each pulse. The library sets the pin to INPUT_PULLUP and counts falling edges, which is why the acceptor's output mode switch has to be on NO — see the two switches.

That is also why an unconnected signal pin does not read as a stream of coins. The pull-up holds it high, which is the idle state, and nothing happens.

When it does not work

I wired both and the library only seems to read one

It reads one, by design. A CoinAcceptor object is constructed with a single pin. Wiring both does no harm but tells the library nothing extra, so pick the one that answers your question and leave the other off.

COUNTER gives me several pulses per coin, not one

Check which pin the wire is actually on. On the module the MCU-side header runs GND, VCC, COIN, COUNTER, and COIN is the pin next to VCC — one row up from where people expect COUNTER to be. It is the commonest miswire on this board.

I want both the count and the value

Use COIN in mapped mode, which fills in both totalCoins() and totalValue(). COUNTER cannot give you value under any arrangement, because the value information is never on that wire.

Can I run two CoinAcceptor objects, one on each wire?

You can construct two, but only the first to call begin() gets the interrupt — the library allows one interrupt instance and the second silently falls back to polling. That makes the second one far easier to lose pulses on, so it is not a good way to get both facts. Mapped mode on one wire is.

Where this goes next

What the library actually fills in, and the accumulator each mode leaves at zero.

Three modes, and which one you want

Edit this page — content/books/coin-acceptor/coin-or-counter.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

Arcade Coin Acceptor Module Kit, USB-C Powered

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum