Help me with my code for Universal Coin Acceptor with Arduino

Hi guys need help with my code, I am trying to create a project that use Universal Coin Acceptor (CH-9260 that can program every coin has a pulse) with Arduino and send serial comunication to Visual Basic
I trying to read the pulse of every coin I inserted and print what type of coin inserted

sample pulse set on the "Universal Coin Acceptor "
coin 1 = 1 pulse
coin 2 = 5 pulse
coin 3 = 10 pulse

wiring!
coin slot pin coin = pin 2 arduino

goal!!
sample output serial.println every coin inserted, just on read what type of coin inserted
coin 1 = coin 1 Inserted
coin 2 = coin 2 Inserted
coin 3 = coin 3 Inserted

this is my code that I got form a youtube video(no code provided just pause and write the code), already verify no error but still blank on serial print.
YT Video by: craynerd

I know this new topic is old, but some of them is using arduino with LCD, I am just using arduino nano and coin acceptor. If you have any idea or code line good an realiable, please help me

const int coinpulse1 = 0;
int coinPulseCount = 0;
int newCoinInserted =0;
volatile unsigned long pulseTime;

void setup()
{
  Serial.begin(9600);
  pinMode (2,INPUT_PULLUP);
  attachInterrupt(coinpulse1, coinpulse1, RISING);
}
void loop()
{
  if (coinPulseCount >0 && millis()- pulseTime > 200)
  {
    newCoinInserted = coinPulseCount;
    coinPulseCount = 0;
  }
  switch (newCoinInserted)
  {
    case 1:
    Serial.println("coin 1 Inserted");
    newCoinInserted = 0;
    break;
    case 5:
    Serial.println("coin 2 Inserted");
    newCoinInserted = 0;
    break;
    case 10:
    Serial.println("coin 3 Inserted");
    newCoinInserted = 0;
    break;
  }
}
void coinpulse()
{
  coinPulseCount++;
  pulseTime = millis();
}

You can only use pins 2 or 3 on your board.

Should be

attachInterrupt(digitalPinToInterrupt(coinpulse1), coinpulse, RISING);

I use the code you send but still blank on serial monitor :yum:
attachInterrupt(digitalPinToInterrupt(coinpulse1), coinpulse, RISING);

Its working now I change the code line
const int coinpulse1 = 0;
to
const int coinpulse1 = 2;
and
attachInterrupt(coinpulse1, coinpulse1, RISING);
to
attachInterrupt(digitalPinToInterrupt(coinpulse1), coinpulse, RISING);

I try so many coin not acurate maybe I need to lower the pulse of each coin, and now planning to add code to make the coin slot will not accept, using the "set" in on the coin slot. while the inserted coin is processing.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.