measure sound frequency with Piezo

Dear fellow arduino users,

I walk with the following idea, would it be possible to recognize a fixed sound frequency with a piezo and arduino? For example 1000Hz or 500Hz, and filter all other frequencies. Since I'm a beginner, I do not know where to start. Via the internet, I found a piece of code that could measure the vibration as soon as I want to add extra code, I get a lot of errors.

Could anyone help me with programming?

Thanks in advance.

You would need to find a piezo with a physical resonant frequency equal to the desired input frequency.

Why not use a regular microphone, one of the widely-available microphone adaptors and a library specifically intended for finding frequencies?

An Arduino is a poor choice for this. It's like a dog walking on two legs.

Thanks for your reply.

I want to use a piezo because of the vibration measurement, thats why also the low frequency.

const int PIEZO_PIN = A0; // Piezo output

void setup() 
{
  Serial.begin(9600);
}

void loop() 
{
  int piezoADC = analogRead(PIEZO_PIN);
  float piezoV = piezoADC;
  Serial.println(piezoV); 
  delay(300);
}

This is the code i started with, i can measure up to 5 volt analoge and i dont know if the analoge to digital 1023 has anything to do with this. So all i have to do is figure out how to use f=1/T in the code. Right?

MorganS:
You would need to find a piezo with a physical resonant frequency equal to the desired input frequency.

Why not use a regular microphone, one of the widely-available microphone adaptors and a library specifically intended for finding frequencies?

An Arduino is a poor choice for this. It's like a dog walking on two legs.

[/code]

N-0-sra-tiA:
So all i have to do is figure out how to use f=1/T in the code. Right?

Yes, but you've now turned a problem about measuring f into a problem about measuring T. Doing this kind of analysis in the time domain is really inefficient, since you want an answer in the frequency domain.

It might help if you gave us more information on what this is for. Is it supposed to recognise a frequency signal in a noisy environment or is the pure tone going to be relatively isolated? Do both tones occur at once or is it supposed to differentiate between those two?

You can do one of two things.

  1. count the number of cycles of the signal you get in a fixed amount of time
    Or
  2. time how long it takes to get one cycle.

Either way you need to convert your signal into a square wave. For this you need either a comparator chip like the LM339. Or to use the Arduino's built in comparator.

Lots of examples if you google here is one http://interface.khm.de/index.php/lab/interfaces-advanced/frequency-measurement-library/