Go Down

Topic: Pulse Reading from Coin slot to Arduino (Read 3889 times) previous topic - next topic

Gedon

Hey Guys really need your help on how to accurately read the pulse signal input from a Coin Slot to Arduino Uno
This is the code i used:
Code: [Select]

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 6, 5, 4, 3);
volatile int coins = 0;

void setup()
{
  lcd.begin(16, 2);
  Serial.begin(9600);
  attachInterrupt(0, coinInserted, CHANGE );
}
void coinInserted()
{
//delay(1000);
  coins = coins + 1;
}
void loop()
{
  lcd.setCursor(1,0);
  lcd.print(coins);
}


the coin slot has been set for 3 outputs:
P1.00 coin- 1 pulse
P5.00 coin- 5 pulse
P10.00 coin- 10 pulse

I used a LCD to see if the "coins" value counts corresponding to the coin inserted. But when i started to test,
the LCD DISPLAYS A CONTINUES COUNT OF THE "coins" VALUE EVEN WHEN I HAVEN'T EVEN INSERTED A COIN IN THE COIN SLOT.

In the attachInterrupt command, i interchange the "CHANGE", "LOW", "RISING", and "FALLING" and here what happens:
Falling: with delay set to 5000 - 50000, even without a coin inserted it counts up but more slowly
Rising: the same as Falling
Change: the same as Falling and Rising
Low: with delay set to 5000 - 50000, after uploading the program code to arduino the LCD doesn't display anything. Without any delay and after uploading the program code the LCD displays a continues count up of the "coins" value insanely fast.

What i'm after:
If I inserted a coin, (1,5 or 10), the LCD should display from "0" to the corresponding count up of pulses being read by the arduino (0 to 1, 0 to 5, 0 to 10) and continues to count up depending on the coin being inserted.

REALLY NEED HELP ON FIXING THIS PROBLEM.



strykeroz

Hi,

Do you have a link to the datasheet for the coin accepter you're using?  Can you confirm you've got the line that will be pulsed connected to digital pin 2 on the Uno?  Other than that,
Code: [Select]
  attachInterrupt(0, coinInserted, CHANGE );
...the above will call your function to increment your counter twice as often as (I presume) you'll want to, ie on both edges of each received pulse.

Cheers ! Geoff
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

wildbill

Are the grounds of the Arduino and the coin device connected?

Gedon

#3
Dec 19, 2012, 02:21 pm Last Edit: Dec 19, 2012, 02:30 pm by Gedon Reason: 1
I have been searching but i haven't found any link for the datasheet of the coin acceptor. As i explained i tested using "CHANGE", "FALLING", "RISING", and "LOW" and described what output i got. I'm sure that i connected the correct line to digital pin 2 to read the pulse from the coin slot.

http://e-gizmo.com/wordpress/?p=895

i double checked the connections and i'm sure that the ground of the Arduino, Coin Slot, and LCD are all connected. I also checked the voltage supplies of the LCD and the Coin slot (5V and 12V respectively) and i'm sure its right.

PaulS

Quote
I have been searching but i haven't found any link for the datasheet of the coin acceptor.

Then how do you know that various coins are supposed to output different pulses? How do you know that the device is outputting 5V pulses? Have you attached an oscilloscope to it?

Gedon

http://e-gizmo.com/wordpress/?p=895
The vendor explained briefly what output is generated when coins are inserted.

strykeroz


http://e-gizmo.com/wordpress/?p=895
The vendor explained briefly what output is generated when coins are inserted.
Are you certain you have one that's been "fixed"?  Half that article talks about how those mechanisms were pulsing far more often, and for a longer duration, than they'd expected.

Might be you've got one of the early ones?
Geoff
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Gedon

Yes i am certain that it is one of the fixed products.

strykeroz


Yes i am certain that it is one of the fixed products.
So far we've got no evidence to back that up - unless you've watched the pulses get generated conforming to the new version on a scope or similar, your sketch result certainly could be due to the issue they describe. 
Quote from: Multi-coin Acceptor Debugged
Worse, too many pulses were being generated: the Five peso coin churns out 40 pulses; the ten peso coin generates 80 pulses! Even at its fastest pulse rate setting, one will have to wait 40 seconds before the acceptor finishes the pulse transfer of a 10 peso coin.
That sounds very much what you've described in your original post.

If you've got no way to directly view the output pulses, I'd be contacting the supplier with your symptoms and getting them to work through this with you.  Potentially get them to send you a replacement they've tested.

Geoff
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

PeterH

You should not ever have a delay in your ISR. All that will do is cause it to catch the first pulse but miss some subsequent ones. This is no help at all to solve your problem and just introduces another problem.

I understand you're saying that with delay set to zero the counter counts up even when there are no coins inserted, and it does this in all the interrupt modes.

You say you have checked and verified the wiring so I accept that what you're counting is the actual signal output from the coin detector.

What type of electrical output does the coin detector provide? I mean, is it outputting a digital pulse on a signal wire (if so, at what voltage and frequency?) or is it giving a loop disconnect type output? If it's a loop disconnect, you'd need a pull-up or pull-down to prevent a floating input which would cause symptoms just like you describe.

The other possibility is that the coin detector is triggering spuriously. Have you investigated the "Coin detection accuracy setting" options on the detector?
I only provide help via the forum - please do not contact me for private consultancy.

Gedon

#10
Dec 19, 2012, 04:58 pm Last Edit: Dec 19, 2012, 05:10 pm by Gedon Reason: 1
As another checking if there really is a change in the pulsing in the signal wire, w/ a circuit inbetween the signal wire (the wire that gives supposedly a pulse signal) to the arduino, i have connected a LED in between.

With or w/out this circuit in between THEY HAVE THE SAME RESULT.

the thing is as i turned on the coin slot and the arduino, as well as the LCD and all of them being connected, the LED in the circuit is continuously lit up. As I inserted the a coin it shows a change and blinks:
When P1.00 coin is inserted, it blinks once.
When P5.00 coin is inserted, it blinks 4 times.
When P10.00 coin is inserted, it blinks 8 times.




Gedon

Just a Quick Question about Arduino...
If i'm using PIN 2 as Interrupt pin, does the required voltage, being above 3V is HIGH and below 3V is LOW, still a necessity?

Nick Gammon

Does that gadget just open/close a switch? If so you hardly need those transistors. Or does it output a voltage?

If it closes a switch you just need to set pin 2 to INPUT_PULLUP, and then detect a FALLING interrupt (that would be when the switch is closed). In other words, wire the switch from pin 2 to ground, and when the switch closes pin 2 will become low briefly. Don't use a LOW interrupt, that will tend to hang up your program.

Check with a meter if there is a voltage output, or just a switch closure.

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

strykeroz


Just a Quick Question about Arduino...
If i'm using PIN 2 as Interrupt pin, does the required voltage, being above 3V is HIGH and below 3V is LOW, still a necessity?
Hi

I'm not at all sure of the 3V value you're quoting here.  Unless I'm reading the datasheet incorrectly (which is a possibility, granted), when VCC is in the range 2.4V - 5.5V, the highest value where the pin is guaranteed to be read as low is 0.3V and the lowest value where the pin is guaranteed to be read as high is 0.6V. (this is from Page 313, section "28.2 DC Characteristics").

The interrupt section of the datasheet does not list alternative voltages for low and high so I expect the same rules apply, though others will have greater experience in this area.

Cheers  ! Geoff
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Gedon

THANK YOU SO MUCH for the suggestions/advice/comments.
This is the code now:
Code: [Select]

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 6, 5, 4, 3);
volatile int coins = 0;

void setup()
{
  lcd.begin(16, 2);
  pinMode (2,INPUT_PULLUP);
  attachInterrupt(0, coinInserted, FALLING);
}
void coinInserted()
{
  coins = coins + 1;
}
void loop()
{
  lcd.setCursor(1,0);
  lcd.print(coins);
}


On the LCD display, when i turn on the Arduino and the Coin Slot, it displays 1 and not 0 so i assume it already read a pulse when turned on, but still it counts the way i need it to count. It doesn't count up continuously anymore, and counts up respectively to what coin is inserted. Still starting from 0 and not 1 would be a bit more of a convenience to me than finding a way to get rid of the unnecessary 1 on start. Thanks for the Help!  XD

Go Up