Measuring Frequency With the Analog Input Pin

Hello,

Is it possible to have the Arduino measure frequency? I would guess using the pulsein() function should be the right course of action but what would be a sample code to measure the input frequency?

My project is a metal detector which changes from low to high frequencies when metal is found. I want to use the Arduino to set a threshold frequency which indicates 'No Metal' and anything above that frequency indicates 'Metal Detected.'

How would I use the pulsein() function to implement this?

I wish I could give you some more.. detailed information, but here's a member of LMR (Letsmakerobots.com) Who installed a metal detector on his robot, I'm not sure how he implemented it, only seen the pictures haven't read into it much!

http://letsmakerobots.com/node/9433

Hello,

pulseIn() is possible. Code should look something like this:

int frqin = 2;
int nofrq = 3;
int lowfrq = 4;
int highfrq = 5;

int threshold = 500; // 500us -> high > 1kHz
unsigned long duration;

void setup()
{
pinMode(frqin, INPUT);
pinMode(nofrq, OUTPUT);
pinMode(lowfrq, OUTPUT);
pinMode(highfrq, OUTPUT);
digitalWrite(nofrq,HIGH);
digitalWrite(lowfrq,LOW);
digitalWrite(highfrq,LOW);
}

void loop()
{
duration = pulseIn(pin, HIGH);
if (duration == 0) {
digitalWrite(nofrq,HIGH);
digitalWrite(lowfrq,LOW);
digitalWrite(highfrq,LOW);
}
else if (duration <= threshold) {
digitalWrite(nofrq,LOW);
digitalWrite(lowfrq,HIGH);
digitalWrite(highfrq,LOW);
}
else {
digitalWrite(nofrq,LOW);
digitalWrite(lowfrq,LOW);
digitalWrite(highfrq,HIGH);
}
}

Connect the input frequency to pin2, and 3 LEDs to pins 3,4 and 5;
LED at pin3 lights up if no frequency detected, LED at pin4 indicates a low frequency and LED at pin 5 indicates a high frequency.
Threshold determines what a low or high frequency is. A value of 500 gives a half period of 500 Microseconds (1000Hz) (supposed that the frequency is symmetrical);

Good luck
Michael