Go Down

### Topic: Eddy Current coin detector (Read 4320 times)previous topic - next topic

#### mstxee

##### Mar 22, 2012, 05:05 pm
Hello!

I'm new to the world of Arduino, so far I've only done a few simple blinking LED projects with buttons and such.

I'm looking to create a setup that will detect what type of US coin has been rolled down a ramp using a magnetic field and the eddy current interactions for a physics project. Basically, I want something pretty similar to this: http://www.youtube.com/watch?v=5QRKZBdkY4g

I was looking to use two IR photogates to determine the speed of the coin (simply the time difference between when photogate 1 and two are tripped) and then I was going to use an Adafruit 16x2 LCD display to show the time it took to travel from photogate 1 to 2 and then display what sort of coin it is by comparing the time to a known range of values.

My question is, how do I find an accurate difference in time between tripping photogate 1 and 2? The absolute time is irrelevant, I just need a good delta t. I've looked around and I'm not sure if loops will be fast enough, and I'm a little unsure of my other options.

I feel confident in doing the comparison and display of the type of coin once the delta t is calculated but I'm a little stuck on the first part.

Thanks in advance for any help!!

#### Si

#1
##### Mar 22, 2012, 05:43 pm
Hi,

You can use the function millis()

This returns a long which is the milliseconds since the Arduino last reset (well pretty much).

So, in pseudo code:

Code: [Select]
`when trigger1 tripped     t1 = millis()when trigger2 tripped    t2 = millis()    dt = t2 - t1    display dt on LCD`
--
I write books about Arduino and Electronics: http://simonmonk.org

#### Qsilverrdc

#2
##### Mar 22, 2012, 06:16 pm
You could use interrupt driven coding to get very accurate timing.
Attach your photo eyes to the interrupt inputs.  Use the micros() function to get times.
pseudo code kind of:

INT0 :
micros() > stack.
Count+

INT1:
if Count > 0
Micros() > endTime
Pop stack > startTime
Set EventFlag
Count -
Main:
If EventFlag
do calculations
clear flag
----
Other stuff like display

Pushing start times onto a stack would allow rapid drops, so long as your main loop is able to complete faster then a coin can get thru.
(Lots of error stuff missing here, but you should get the idea.)

Notes:
Most Arduino boards have two external interrupts: INT0 (on digital pin 2) and INT1 (on digital pin 3).

FUNCTION:  attachInterrupt(interrupt, function, mode)
FUNCTION:  micros()

Returns the number of microseconds since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 70 minutes. On 16 MHz Arduino boards (e.g. Duemilanove and Nano), this function has a resolution of four microseconds (i.e. the value returned is always a multiple of four). On 8 MHz Arduino boards (e.g. the LilyPad), this function has a resolution of eight microseconds.

There are 1,000,000 microseconds in a second.

Good Luck

Richard

#### Udo Klein

#3
##### Mar 22, 2012, 06:56 pm
Interrupt driven code will only give reliable accurate timing if all interfering interrupts are disabled. Otherwise you get mostly correct timing. That is every once in a while your timing will be off the mark depending on the interrupts that are blocking it.

#### mstxee

#4
##### Mar 22, 2012, 07:04 pm
Thanks! The interrupt inputs seem like exactly what I want. I was searching all sorts of terms but never found that and it seems like a perfect solution. Now to wait for all my parts to arrive...

#### Grumpy_Mike

#5
##### Mar 22, 2012, 07:19 pm
Are you sure that will work?

I did a coin counting project back in 1994 that used a linear CCD to measure the diameter of coins. Mind you they are English coins.

The words are here
http://www.doc.mmu.ac.uk/STAFF/A.Wiseman/Acorn/BodyBuild/BB94.html
and the diagrams here
http://www.flickr.com/photos/33177304@N03/3851893046/

#### bperrybap

#6
##### Mar 22, 2012, 10:12 pm
I'm with Si.
There is no need to over complicate this.
All you need is enough accuracy & precision to be able to distinguish between the coins.

Notice that the induction is influencing the roll speed between the different coins
by more than a 100ms time difference between the coins.
That is all day long to the AVR.
Plus it does not require super precise timings in order to be able to distinguish
between the coins.

Based on a known timing range for the coins, you can figure out which coin it is.
i.e. don't look for an exact timing value of an individual coin, look for > or < some other number
relative to the other coins.
You can nest your comparisons so that you only compare to one timing value
for each coin.
In his case:
if ( dt > 1000) quarter
else if( dt > 900) dime
else if(dt > 700) penny
else nickel

You will probably have to experiment a bit to determine what times identify each coin
and potentially tune your detector by varying a a few things like the slope of the
ramp to control the entry speed into the magnetic field and the strength of the field
by varying the distance between the coin and magnets.

--- bill

#### Udo Klein

#7
##### Mar 23, 2012, 05:22 pm
It all depends on what you want to achieve. If you know in advance that you are measuring a coin that belongs to a fixed set of coins then the task is easy. If you have to judge by the measurements if you are actually dealing with a coin and if this coin belongs to a predetermined set of coins then the tasks becomes significantly harder.

For the current task it seems that you want to solve the easy problem thus bill's approach is definitely sufficient.

#### bperrybap

#8
##### Mar 23, 2012, 11:38 pm
So True about the problem scope.
Even when dealing with just USA coins there some "gotchya's" involved.

The metal composition of the coins has changed over the years.

There are actually 3 different USA pennies. 1943, 1982 to now and all the rest.
I'm wondering if a 1943 penny would even make it through the magnets without
getting stuck to one.

There are multiple dimes but for modern dimes it is  pre 1965 and post 1965.

Quarters also changed in 1965.

--- bill

#### GoForSmoke

#9
##### Mar 24, 2012, 01:19 am
I kind of wonder, if you had a magnet with hall sensor at one pole, what change to the field would there be from the induction into a coin passed by the other pole? I think that by conservation there should be some change, one way or the other.

2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

Go Up

Please enter a valid email to subscribe