I am using "generic" coin-acceptor in my project, that can accept 5 coins. It's accepting coins as long as it is powered on. It should accept only when appropriate screen is displayed on my LCD. When I remove power from it - it is rejecting all coins. So simple solution is to use relay to turn on and off this acceptor whenever I need it to accept coins. So far, so good.
Problem is.. when I supply power to coin acceptor it imediatelly send some random pulses to coin-wire before it's ready to go. Those some random pulses are already counted as some coin-value and that shoudnt be.
How to properly detach interrupt (or simply saying disable pin2 for about 1000ms so this coin acceptor gets ready)
In Void setup I have code:
pinMode(2, INPUT_PULLUP); attachInterrupt(coinInterruptPin, coinInserted, FALLING);
When apropriate screen is displayed on my LCD screen I have folowing code that must turn-on coin acceptor.
detachInterrupt(digitalPinToInterrupt(2)); //trying to detach interrupt while coin-acceptor turn on. delay(400); digitalWrite(38, HIGH); // Turning on relay that supply +12V to coin-acceptor delay(1500); //waiting for coin acceptor to become ready attachInterrupt(coinInterruptPin, coinInserted, FALLING); //attaching interrupt and coinInserted function
But this solution don't work as expected - one pulse is added anyway.
Another thing - whenever I plug/unplug coin-pulse wire to/from Arduino pin2 - it counts this one pulse. Maybe I need to attach some resistor?