Pages: 1 [2]   Go Down
Author Topic: How to detect a coin falling?  (Read 1345 times)
0 Members and 1 Guest are viewing this topic.
NSW Australia
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3561
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've built a penny pusher for my daughter - this is her playing it the other night... I still have a lot of work to do!!
http://youtu.be/eqOI4IMVRlQ
Impressive indeed.

I've also purchased a 10p hopper and cheap coin validator mechanism and used the arduino to make a change machine. Paul, this is where both interrupts are being used.
But that is my point.  Why?  Why make the code unnecessarily complicated and potentially unreliable (particularly when you need to perform de-bouncing which I am not sure whether that is provided by the coin counter mechanism) when there is absolutely no need whatsoever to use interrupts?

I know now how I'm going to dump the coins using a stepper motor but this thread is about counting the coins falling into the box. The coins will be funnelled into the box so will always have to pass past the led and sensor if I went that way.  I'm just still in two minds whether to pay the £12 and go for the mechanical option. With all those LEDs flashing in the background, I'm not sure how stable the opto sensor would be!
Opto sensors are mounted at the end of little black tubes. Very effective.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


I've also purchased a 10p hopper and cheap coin validator mechanism and used the arduino to make a change machine. Paul, this is where both interrupts are being used.
But that is my point.  Why?  Why make the code unnecessarily complicated and potentially unreliable (particularly when you need to perform de-bouncing which I am not sure whether that is provided by the coin counter mechanism) when there is absolutely no need whatsoever to use interrupts?


I'm not at all with you??? How do I read the coin validator pulses and coin hopper coin ejection pulses accurately without using the interrupts?? Confused.

Edit - and I'm also confused how this working function of the machine is having any impact on this coin fall count we are discussing.
« Last Edit: September 21, 2013, 03:36:29 am by craynerd » Logged

NSW Australia
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3561
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm not at all with you??? How do I read the coin validator pulses and coin hopper coin ejection pulses accurately without using the interrupts?? Confused.
Presumably the same way you do everything else.  You have a "loop" routine that executes one sub-task after another, attending to any new event accordingly and passing by otherwise.  This loop will generally cycle something of the order of a thousand times a second, it should never be "busy waiting" for some associated event to happen.

One of the tasks it performs, is de-bouncing - if it detects a change in an input, it makes a note of it in a counter and on each successive pass (though the main loop), tests whether the change is sustained and if it is for a certain number of passes (advancing the counter) or a certain time elapsed (more accurate), it determines that input (change) to be meaningful.  This can be performed - and must be performed if the input is a mechanical contact - in a similar fashion if you are using an interrupt routine, but then you still have to use a flag (semaphore) of some sort to communicate with the consequential actions in the main loop.

Interrupts should be reserved for events that are genuinely time--critical.  A coin taking tens of milliseconds to fall through a chute is in computer terms, anything but time-critical.  smiley-grin

I am curious as to whether this coin hopper mechanism is providing the de-bouncing for you, or whether you are in fact employing de-bounce code?

I'm also confused how this working function of the machine is having any impact on this coin fall count we are discussing.
Perhaps, perhaps not, but is likely to be an unnecessary complication as you add more functionality and a potential source of conflicts if for example, on the rare and unpredictable situation that two interrupts just happen to occur simultaneously and inter-react.  This becomes all the more likely when interrupt routines are unnecessarily responding to repeated contact bounce events.

« Last Edit: September 21, 2013, 04:15:28 am by Paul__B » Logged

Phoenix, AZ
Offline Offline
Jr. Member
**
Karma: 1
Posts: 90
Retired engineer still playing with gadgets.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A servo seems like a better choice than a stepper motor. A servo only moves 180 degrees.

Great game!!
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Paul_B - if the coin validator coin sense output is not on an interrupt, then the arduino could very well miss a coin being inserted for changing... Likewise, the pulses are sent in batches, 2p - 1 pulse, 5p - 2 pulses...etc and I need to capture accurately the number of pulses coming through. Again, if this wasnt on the interrupt then they could be missed and the whole functionality of the coin change machine lost.


Pmlapl - although I want to spin 180, I'll actually take it a little further to ensure all the coins spill. Also, a good rigid stepper motor shaft should be substantial enough to directly hold the box that contains the coins...
Logged

Florida
Offline Offline
God Member
*****
Karma: 2
Posts: 559
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Lets stick to the topic here "how to detect a coin falling"

I think my idea will work fine. As Paul_G said if you incase the photo resistor so that the only opening is in a place that will be blocked when the coin falls you should have no problem. If you have the stuff you could always test it out. It should only take a few moments to try it.

Best of luck!
Logged

Manchester, NH
Offline Offline
Full Member
***
Karma: 0
Posts: 116
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A coin falling past a detector is a lifetime to a 16MHz processor and interrupts should not be needed. I like one poster's idea to use the coin itself as the switch. Use two long, thin pieces of springy copper on either side of the coin slide and detect the short circuit made by the coin.
Logged

Phoenix, AZ
Offline Offline
Jr. Member
**
Karma: 1
Posts: 90
Retired engineer still playing with gadgets.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

He brought up the subject of a stepper motor, so I think my comment is valid. It's part of the design.

You won't need to rotate the box 180 to dump the coins. Maybe only 120. Try it for youself.
Also there are servos made that can take the side load, in this case, 4.4 oz. and a servo is easier to program.
Logged

NSW Australia
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3561
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A coin falling past a detector is a lifetime to a 16MHz processor and interrupts should not be needed.
I do not seem to be able to get this matter of scale understood.   smiley-eek-blue

I like one poster's idea to use the coin itself as the switch. Use two long, thin pieces of springy copper on either side of the coin slide and detect the short circuit made by the coin.
Bronze.

On the same side would do.
Logged

Offline Offline
Edison Member
*
Karma: 29
Posts: 2455
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

if you consider what an Arduino can do and calculate in the time it takes a coin to travel from top to bottom is pretty impressive.

Logged

Pages: 1 [2]   Go Up
Jump to: