When a sound is detected at a specific frequency

Good Morning,
Can you help me with this doubt?
is there a way to create a code in which the arduino sends a pulse to a relay, when a sound is detected at a specific frequency?
example: I would like that when a sound between 100 Hz to 4 KHz is detected, the arduino sends a pulse to the relay.

I created a sound detection system however I need to filter some frequencies

you could envision running an FFT to get in frequency domain and make your decision based on peak frequencies (see an example here: https://create.arduino.cc/projecthub/lbf20012001/audio-frequency-detector-617856)

PS: remember Nyquist frequency = half the sample rate

Sorry for my lack of knowledge in this area, but could you give me more information??

"Fourier Analysis" and "Nyquist Sampling Theorem" would be two good search terms to start your journey.

What sort of sound is this?
A sine wave or a natural sound like a piano note or a shout?

Most natural sounds have frequencies in this range, so they will trigger your relay no matter what the sound is.

have you looked at the link?

basically you can analyze the incoming sound using Fast Fourier transform - Wikipedia to extract key frequencies of your samples.

There is a specific rule know as Nyquist frequency - Wikipedia to be aware of when you'll define your sampling rate.

this is more than voice range... isnt ? you could just use simple detection with bandpass filter ... I think a simple opamp with filter would do it.

Then show it to us. What have you done so far? What hardware do you have? What sound are you trying to detect?

No the voice can go much higher, but the so called telephone quality is this range.

The point being if you did you will trigger off virtually any sound. I think @victor88srocha is not taking this into consideration and maybe he wants something like a guitar chord to trigger the relay and a dog barking to not. But until we here back from him we won't know.

With a bandwidth that wide you would have to make it from a low pass and a high pass filter.

To me it reads like a language translation/usage issue. I'm guessing the OP wants to detect some unspecified type of sound within that range. They must not have read the forum introduction about how to ask a question.

1 Like

Of course, I'm sending everything I did.

int son = 2; // pino out do módulo conectado ao pino 2
int bot = 3; // pino 3--->botao--->GND
int led1 = 9;
int led2 = 11;
int led3 = 4;
void setup() {
pinMode (son, INPUT);
pinMode (bot, INPUT_PULLUP);
pinMode (led1, OUTPUT);
pinMode (led2, OUTPUT);
pinMode (led3, OUTPUT);

}

void loop() {
digitalWrite(led3, HIGH);
while (digitalRead (bot) == HIGH); // aguarde a pulsação
digitalWrite(led1, HIGH);
digitalWrite(led3, LOW);
while (digitalRead (bot) == LOW); // aguarde a liberação do botão
while (digitalRead (son) == LOW);// enquanto não houver som, ele funciona
digitalWrite(led1, LOW);{
// seu programa
if (digitalRead(son) == LOW)

{

digitalWrite(led2, HIGH);
delay (500);
digitalWrite(led2, LOW);

}
}
while (digitalRead (bot) == LOW); // aguarde a liberação do botão
while (digitalRead (son) == LOW);{// enquanto não houver som, ele funciona
// seu programa
if (digitalRead(son) == HIGH)

{

digitalWrite(led2, HIGH);
delay (500);
digitalWrite(led2, LOW);

}
}
}


Good Morning,
the sound I want to be detected is just the human voice.
this equipment is to be used in a shooting range, however the system must rule out ambient noise (shots, seeing and other things)

please edit your post, select the code part and press the </> icon in the tool bar to mark it as code. It's barely readable as it stands. (also make sure you indented the code in the IDE before copying, that's done by pressing ctrlT on a PC or cmdT on a Mac)

Then you would have to take sound duration into account..
A shot will be very short, voice will be longer, but both will be in same freq range.

I would definitely not trust anything safety-related to a hobbyist-quality processor board running code written an obviously inexperienced programmer.

A gunshot contains almost all frequencies but it (obviously) has a short duration and it's loud. Ambient noise normally includes most of the audio range too.

With Audacity you can record sounds on your computer and then you can plot the spectrum. You might want to play around with that before you try to build something.

what's the purpose? just detect if humans are around?

well, I don't know if you know the skeet shooting modality?
where after the shooter asks for the dish, the machine launches it, see the video so that you have a better understanding. so when the system detects the voice, it sends a pulse to the machine to launch the plate.

the system I made works, however I wanted to narrow the accepted frequency.

What sound does seeing make?

Anyway you can't do this with a humble Arduino Uno. You need something like an Arduino BLE 33 sense, so you can run some sort of AI program.
Even then you will have to train the system which is the difficult bit. Here are some links to get you going.

sound recognition:-
https://www.eetasia.com/news/article/Data-is-King-for-AI-Sound-Recognition

AI - Google’s flagship machine learning library: “TensorFlow“

The training is the hard part and the recognition when you get it will take time to come through with such a minimum system.

This would be a cutting edge project and not one a beginner could easily understand.

Hi,
how about using MSGEQ7 to separate the frequency range you want to use to trigger the arduino?

datasheet: