I'm working on a project that makes use of a CH926 coin acceptor. The problem we're having is that when I read the serial monitor, the coin value is continuously going up and adding credits when it's supposed to remain at 0 until a coin Is fed into the acceptor.
We've tried a different coin acceptor, different codes, arduinos, wiring, resistors, breadboards, the lot. nothing seems to be solving this problem and we can't determine why, it had been working fine until we tried to tidy up our wiring and untangle it.
we're using a basic code that had worked fine up until we had the issue of the counter value no longer remaining at 0:
const int coinpin = 2;
const int ledpin = 3;
const int targetcents = 100;
// Variables
volatile int cents = 0;
int credits = 0;
// Setup
void setup() {
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(coinpin), coinInterrupt, RISING);
pinMode(ledpin, OUTPUT);
}
// Main loop
void loop() {
// If we've hit our target amount of coins, increment our credits and reset the cents counter
if (cents >= targetcents) {
credits = credits + 1;
cents = cents - targetcents;
}
// If we haven't reached our target, keep waiting...
else {
}
// Debugging zone
Serial.print(cents);
Serial.print(" cents toward current credit and ");
Serial.print(credits);
Serial.println(" credit(s) earned so far.");
delay(1000);
// Turn off LED
digitalWrite(ledpin, LOW);
// Now, write your own cool code here that triggers an event when the player has credits!
if (credits > 0) {
// Play music?
// Spin up a motor?
// Start a game?
// It's up to you!
}
}
// Interrupt
void coinInterrupt(){
// Each time a pulse is sent from the coin acceptor, interrupt main loop to add 1 cent and flip on the LED
cents = cents + 1;
digitalWrite(ledpin, HIGH);
}
any advice on what may be causing this problem?
cheers