The coin acceptor datasheets I've looked at indicate it's handled internally. They are typically programmed ("trained") to produce a fixed number of pulses for each different coin denomination. So, the pulses are generated electronically, not mechanically with contacts actuated by the coin.
That's been my experience also. I have a client whose business model is basically putting bill acceptors on all kinds of entertainment equipment. All the bill & coin acceptors that I've had to interface to use NPN-style open-collector outputs. Never had to debounce a single one.
The output is digitally controlled by the internal firmware, so it seems to be kinda open collector. The pulse isn't sent using any mechanical switch.
The pulses are generated electronically, so no bouncing.
The pulse width is selectable: Fast (30ms), Medium (50ms) and Slow (100ms), with 100ms between pulses.
The output is open collector and can be switched between NC (normally low, goes high during pulse) and NO (normally high, goes low during pulse).
10 pulses Fast NC:
4 pulses Slow NO:
Here is the CH926 manual.
Your code is written with a more-than-adequate debounce time (delay(200)). The problem is probably in the acceptor-device and wiring. See Post #2.
firstly thanks for making time for our problem, so we figured out how it works and it works fine with that code:
// Arduino coin acceptor code - Improved version
// Constants
const int coinpin = 2;
const int ledpin = 3;
const int targetcents = 50;
const int debounceTime = 100; // Minimum pulse süresi (ms)
// Variables
volatile int pulseCount = 0;
int balance = 0;
int credits = 0;
unsigned long lastPulseTime = 0;
// Setup
void setup() {
Serial.begin(9600);
pinMode(coinpin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(coinpin), coinInterrupt, RISING);
pinMode(ledpin, OUTPUT);
}
// Main loop
void loop() {
if (pulseCount > 0) {
delay(900); // Gürültü engellemek için kısa bir gecikme
int count = pulseCount;
pulseCount = 0; // Sayacı sıfırla
if (count == 5) {
balance += 50;
} else if (count == 2) {
balance += 20;
} else if (count == 1) {
balance += 10;
}
// Pulse sayısını ve yeni bakiyeyi göster
Serial.print(" - Balans: ");
Serial.print(balance);
Serial.println(" qepik");
digitalWrite(ledpin, HIGH);
delay(200);
digitalWrite(ledpin, LOW);
}
if (balance >= targetcents) {
credits += 1;
balance -= targetcents;
Serial.print("Yeni kredi! Toplam: ");
Serial.print(credits);
Serial.println(" kredi");
}
delay(100);
}
// Interrupt
void coinInterrupt() {
unsigned long now = millis();
if (now - lastPulseTime > debounceTime) {
pulseCount++;
lastPulseTime = now;
}
}
but again we have another problem like we do all the wiring stuff and run the code it works perfectly but 2 days after we plug all the things and run it doesn't working suddenly, its kinda randomly working one day and another day not
I saw this question not so long ago, We never got the schematic and I believe the question was never answered. .I asked for an annotated schematic showing exactly how it is wired.That needs to show all connections, components, and anything else connected. Also show what this is driving (operating) such as a relay, display etc. Note any leads over 10"/25cm.
Does that correspond to the day number being odd or even?
I wonder if February 29 will be working or non-working day...
Since your software and construction hasn’t changed, .id be looking. at the power supply and assembly of the project,
maybe it is a wheather issue. On rainy days it works and on sunshine days not. If so then you have problems with loose cables or bad contacts where higher humidity can temporarily close the loose contacts
I have merged your forum topics due to them having too much overlap on the same subject matter @salamkalbasa.
In the future, please only create one topic for each distinct subject matter and be careful not to cause them to converge into parallel discussions.
The reason is that generating multiple forum topics on the same subject matter can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.
Thanks in advance for your cooperation.
does it makes any difference
Then it would not be random!
Ok but wht do you mean with "doesn't wroking"? the cose is unrespnsive? Or wrongly counts the pulses? Or looks like it receives unknown pulses even without any coin inserted?
Besides, I can't find a culprit for that, but first of all I wonder why you need debounce:
// Interrupt
void coinInterrupt() {
unsigned long now = millis();
if (now - lastPulseTime > debounceTime) {
pulseCount++;
lastPulseTime = now;
}
}
This code says you will ignore any pulse received after "debounceTime", but you shoudn't ever "ignore" pulses, or you'd fail counting pulses. But I don't think any debounce is necessary because the coin acceptor works with mechanical relays: the pulse is digitally performed so no debouce is needed.
The only thing you need to know is when the pulse sequence ends, and you just need to check if the elpsed time after the last pulse is greater than a specific value. And that's why I used "tmrLastPulse" variable and PULSE_PAUSE symbol (see my post #19, where you just need to set PULSE_PAUSE accordingly to your coin acceptor setup values).
Does my code work or not? If not, what is its real behaviour?

