Go Down

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

mstxee

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

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
--
My New Arduino Book: http://www.arduinobook.com

Qsilverrdc

You could use interrupt driven coding to get very accurate timing. 8)
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

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.
Check out my experiments http://blog.blinkenlight.net

mstxee

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

Go Up