How to detect a coin falling?

Hello guys, I've built a game in which coins slide or fall down a ramp at a very steep angle. When a coin falls over a specific point on the board I want an arduino to detect it has passed and do something. I've been looking online and RS in the UK do a low torque micro switch : http://uk.rs-online.com/web/p/microswitches/0339207/

However, if I want one switch £6 including a handling fee and postage it works out at £12.62 which I personally think is expensive for a small switch!! http://uk.rs-online.com/web/p/microswitches/0339207/

Do any of you have any clever ways of sensing the coin? At the end of the day, if it is more than £12 I guess the switch will be the best way to go anyway. Just thought I'd ask - maybe I'm just tight!!!

Instead of a switch, can the coin short 2 wires together and become the switch itself? One wire goes to interrupt pin, 2nd is gnd, the coin then connects the pin to gnd and creates a low level interrupt.

What about a led (or laser) and photo resister? When the coin slides down less light will shine on the photo resistor. And the best part is you probably already have the stuff!

No interrupts left on pin 3 and 4, They being used on other things and only got an UNO - don't want to upgrade board. Also, I'd have to ensure the coin perfectly contacted two contacts and I expect the falling coin couldn't be orientated well enough to contact both as they are falling quickly. I appreciate your input though.

There's PCINTs - any pin can be an interrupt.
Can do same with optical - make sure the coin passes between a transmitter and receiver as Drew Davis suggested.

Hi Drew, yes, it is a possibility! I've never done this but yes, I do have the stuff in one of my arduino kits!! I'll have to have a look for some other similar sketches out there to copy. I could put my led on one side and the sensor on the other...

Does anyone know if any sketches for an led opto switch?

Really? You're just looking for a pin to change state.
If the LED shines on the receiver, the receiver's output pulls a pin low.
When the LED is blocked, the receiver's output is turned off and the pin is pulled high.

It isn't going to get blocked fully so surly you'll be looking at a change in analogue value from the receiver?

Just plug the LED into power/ground… don't for get the resistor! The longer leg should be + I think.

For the photo resistor read the link below.

http://arduino.cc/en/Reference/AnalogRead

How much control do you have over where its falling? I would think you'd want to mechanically limit its movement in the detector area for repeatability purposes.

craynerd:
Does anyone know if any sketches for an led opto switch?

Look at this:-
http://www.thebox.myzen.co.uk/Hardware/Sneak_Thief.html
It uses the analogue input so it will cope with partial cover.

I used a CCD array for this coin counting project
Imgur
and measured the size as it went past.

If you have an Arduino "kit", you probably do have a photosensor module and LED.

My interest is - why would you be using interrupts? Nothing in a game, including your rolling coin - requires a fast response, surely?

Hi Guys, many thanks for the suggestions. I'll go into a little more detail:

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!!

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.

So the arduino is already running the change machine.

Now I've explained the project I may as well expand on this part of the project. I want a special feature on the drop board - basically if a coin randomly falls pefectly centrally on the board, it will fall into a small plastic cube mounted on the front face of the drop board. The arduino will count how many coins fall into the box and when 50 coins have entered, the arduino will boot up a stepper motor and spin the box 180 deg dropping all 50 coins onto the play deck! It is just an additional interest to the game.

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!

Chris

Congratulations on your build... my daughter would love that machine!

Cool stuff....

craynerd:
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!!
Ella playing Ella'va Jackpot - YouTube

Impressive indeed.

craynerd:
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?

craynerd:
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.

Paul__B:

craynerd:
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.

craynerd:
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:

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?

craynerd:
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.

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

Great game!!

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...