Coin operated water dispenser help!

Hi

The interrupt pin is pin D2 and what's triggering it is a coin acceptor.

Would that also be the case with coin acceptors? I did monitor the D2 pin with an oscilloscope. Everything is normal from the time the arduino is reading the impulse from the coin acceptor > turning on the relay > turning off the relay.

The only problem is sometimes after a cycle, my coin_imp variable goes up.

I tried inserting "Serial.println("Triggered");" in my interrupt code but it doesnt show in the serial monitor when i get the unwanted impulse.

Try with coin_imp declared as a volatile variable and use à critical section

  noInterrupts();
  // critical section
  int coin_imp_copy = coin_imp;
  coin_imp = 0;
  interrupts();
  // work with coin_imp_copy

to work on a copy in the loop.

(also necessary for i (Which is a stupid global variable name)

1 Like

haha yeah my arduino's millis function is loco so i just used i. pretty much just random letters i use as timers. sorry

anyway, thank you, all for all your inputs! it's working now, I just put a capacitor between my D2 (interrupt pin) and gnd.

i cant thank you all enough! =D

Hi,

Post #16.

Tom.. :grinning: :+1: :coffee: :australia:

1 Like

oh yeah sorry! =( forgot to quote you but yeah you we're the one who suggested it first.

Thank you sooooo much! =)

I would still suggest you declare your interrupts variable as volatile

i read what volatile is just now and ill definitely use it. thanks! =)

also, what use will the noInterrupt() function serve? also the coin_imp_copy variable?

If you have interrupts while the loop is using the variable your code might have weird behavior

and by variable you mean...?

Those shared between the interrupt and the main code

oh ok. I think i get it.

so i just put the NoInterrupt() function on the loop right?

but since the Interrupt() function is called in the NoInterrupt() function wouldnt that call the interrupt() function without D2 having to call the interrupt?

Notice the s at the end

It’s NOT your function. This is to deactivate and then reactivate the interrupts, this way you are sure nothing bad happens to the bytes whilst your loop plays with the variables. Of course you want to minimize the duration of the critical section, so that’s why you just make a copy of the values and then work from the copies

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