I'm trying to connect CH-923 coin acceptor (like this one: Coin acceptor - YouTube ) into my Arduino Uno R3 microcontroller and send information to PC when coin is inserted.
I've already set it up (3 types of coins, 30 samples for each).
Right now I cannot make it work, it looses signals or adds additional random signals.
This is my Arduino sketch:
My wiring, real photos of connections, settings of coin acceptor etc are in attachements. I've already tried a lot of options as pull-up resistor (500 Ohms, 1kOhms, 1k2 Ohms, 4k7 Ohms, 47k Ohms 100k Ohms etc), changing settings of coin acceptor, attaching coin acceptor to ground (I mean it's casing isn't grounded so I attached it to the wallet socket's ground).
Right now it does give me exact number of signals (1 polish zloty = 1 pulse; 2 polish zlotys = 2 pulses, 5 polish zlotys = 5 pulses), but also it gives me random pulses. Any ideas what should I do to prevent those ivalid pulses and keep correct pulses?
Bottom line is that you can not do a serial print from inside an interrupt service routine. Also note all variables used both inside and outside of one should be volatile.
You also need to connect the ground of your coin counter to the ground of the Arduino.
OK, right now I have different problem... When somebody touches something made from metal and then he/she touches the coin acceptor (or touch coin and try to insert it), the coin acceptor will give signal. It works everytime - this is what I do: I hold coin in metal tool, touch it with finger, then I touch coin acceptor and it gives me +1 signal, it works as many times as I repeat this... Any idea why is it like this? Is it possible coin acceptor is broken? Or should I buy plastic one (where)?
@edit3:
Something intresting. Even when white cable of coin acceptor is not connected at all to Arduino (pin 2 is connected with pull-up resistor to 5V of Arduino), touching the coin acceptor will give me +1! No idea why...
Something intresting. Even when white cable of coin acceptor is not connected at all to Arduino (pin 2 is connected with pull-up resistor to 5V of Arduino), touching the coin acceptor will give me +1! No idea why...
It is not interesting, you wire it up without a ground and it misbehaves why struggle to understand it.
Ami777:
Didnt work. Any ideas?
Get a scope and look at what the signals are doing.
Looks like interrupts don`t work as expected... Im in my local school with Electronics Students for few hours, we tried transoptors, some condestators etc etc, but nothing worked... The only thing we did right now is this simple code in loop:
if(digitalRead(3)==HIGH)
{
unsigned int temporaryValue=millis();
while(digitalRead(3)==HIGH);
temporaryValue=millis()-temporaryValue;
if(temporaryValue>=50 && temporaryValue<=200) { //Not required, but added just to be sure (signal is 100ms)
sendInfo(F("+1"), "");
}
}