coin acceptor to arduino

I connected coin acceptor's white-wire(signal pulse) to arduino's pin 0, there is LED blinking on it when I insert a coin.. number of blinks are depending on the currency I inserted, question is how could I print the number of blinks/pulses on the arduino serial monitor?.. I tried this code but there's no output when I'm inserting several coins TIA coin acceptor: http://e-gizmo.blogspot.com/2013/03/multi-coin-acceptor-debugged.html

int pin = 0;

unsigned long duration;



void setup()

{

  pinMode(pin, INPUT);

}



void loop()

{

  duration = pulseIn(pin, HIGH);
  Serial.println(duration);


}

It would be helpful if you could post your whole code inside code tags (the </> symbol) and provide a link to the coin acceptor.

Also, you may want to switch to another pin as pins 0 and 1 are used for the Serial object for TX/RX.

Pauly:
It would be helpful if you could post your whole code inside code tags (the </> symbol) and provide a link to the coin acceptor.

edited sir :slight_smile:

econjack:
Also, you may want to switch to another pin as pins 0 and 1 are used for the Serial object for TX/RX.

could I use another pins except 0 and 1?

could I use another pins except 0 and 1?

Not only could you, you must.

Please post your whole code, not a snippet.

still can't get its output, whenever I insert a coin and coin acceptor accepted it there's no output printing up

white wire is connected to pin 5 black wire(ground) connected to GND of arduino and black wire going coin acceptor

1st coin = 1 pulse 2nd coin = 5 pulses 3rd coin = 10 pulses

I'm using arduino uno, is there wrong code there?

code deleted because it's wrong

Amethz:   switch (NewCoinInserted) {     case 1:       Serial.println("1php inserted");       NewCoinInserted = 0;       break;     case 101:       Serial.println("5php inserted");       NewCoinInserted = 0;       break;     case 1011:       Serial.println("10php inserted");       NewCoinInserted = 0;       break;

Where do the numbers 101 and 1011 come from?

odometer: Where do the numbers 101 and 1011 come from?

volatile byte CoinPulseCount = 0;
byte NewCoinInserted;

I changed the datatype to int and made 101 to 5 & 1010 to 10 still no output :(

const byte FINGERS_ON_ONE_HAND = 5;
const byte FINGERS_ON_BOTH_HANDS = 10;
const byte DISNEY_DALMATIANS = 101;

The reason is because you are treating your case values as binary but the compiler expects them to be ints. As you have it, the second coin needs to read one hundred and one pulses! (BTW, 10 decimal is 1010 binary.) Although you could write each case in binary (e.g., case 0b1010:), I would change it to:

  switch (NewCoinInserted) {
    case 1:
      Serial.println("1php inserted");
      NewCoinInserted = 0;
      break;
    case 5:
      Serial.println("5php inserted");
      NewCoinInserted = 0;
      break;
    case 10:
      Serial.println("10php inserted");
      NewCoinInserted = 0;
      break;

Finally, I think you need NewCoinInserted to maintain a running total of the coins entered, unless it takes less than 200 ms for all the pulses to arrive. That is, it would seem to me that each coin sends a pulse, so NewCoinInserted would never get larger than 1. Near the top of loop(), should it be:

NewCoinInserted += CoinPulseCount;

odometer: const byte FINGERS_ON_ONE_HAND = 5; const byte FINGERS_ON_BOTH_HANDS = 10; const byte DISNEY_DALMATIANS = 101;

LOL reported jk

econjack: The reason is because you are treating your case values as binary but the compiler expects them to be ints. As you have it, the second coin needs to read one hundred and one pulses! (BTW, 10 decimal is 1010 binary.) Although you could write each case in binary (e.g., case 0b1010:), I would change it to:

  switch (NewCoinInserted) {
    case 1:
      Serial.println("1php inserted");
      NewCoinInserted = 0;
      break;
    case 5:
      Serial.println("5php inserted");
      NewCoinInserted = 0;
      break;
    case 10:
      Serial.println("10php inserted");
      NewCoinInserted = 0;
      break;

Finally, I think you need NewCoinInserted to maintain a running total of the coins entered, unless it takes less than 200 ms for all the pulses to arrive. That is, it would seem to me that each coin sends a pulse, so NewCoinInserted would never get larger than 1. Near the top of loop(), should it be:

NewCoinInserted += CoinPulseCount;

Thanks for your reply :)

I tried this: please read the comments

Changed the whole code

also tried LOW, CHANGE, FALLING, even HIGH on attachInterrupt(3, CoinPulse, *); still can't enter the CoinPulse function :(

Don’t put any Serial.print() statements in an interrupt service routine since they call their own ISR and you might have blocking taking place.

Amethz: volatile byte CoinPulseCount = 0; byte NewCoinInserted;

I changed the datatype to int and made 101 to 5 & 1010 to 10 still no output :(

Rather than a joke. The data type and the numeric value you type in are two different things. 5 is decimal B101 is 5 in binary 0x05 is 5 in Hex Do be careful, the number 015 is not the same as decimal 15. For some reason C interprets the leading 0 as meaning octal ( possibly because octal was convenient on the computers C was first implemented on ). Dwight

Changed the whole code

My crystal ball says its still wrong. Stop deleting your code, even if it is wrong.