Hello everybody,
I'm a french student and with my mates, we are trying to solve a problem for an exam.
We need to use two Arduino uno cards , one card is composed of a microphone, and the other one is composed of a little buzzer.
We have got a program on the buzzer's card that play a tone for 0.5 seconds and 0.5s notone.
And we find trouble in the second part, the second card with the microphone, because we have to find a program that will recognize this 0.5s tone 0.5s notone, and when the program recognized this suit of tone/notone, he turns on a LED.
The problem is that we don't know how to recognize this 0.5 s tone/notone with the microphone , when we draw the sound heard in the microphone with the Serial.println(sensorValue) we could see a saturation of the microhone each 0.5seconds and no saturation for 0.5 s notone.
Is threre a way easier to recognize our audiosignal with the microhpone to turn on the LED ?
Thanks for your help, and i'm maybe blurred with my explainations, i do my best to be understood.
Touns (Arduino Beginner). ![]()
Is threre a way easier to recognize our audiosignal with the microhpone
I don't see what could be easier. You say that you can distinguish between a tone and no tone using the value of sensorValue, so you can use the value to decide whether the LED should be on or off.
if (sensorValue >= threshold)
{
//turn on the LED
}
else
{
//turn off the LED
}
Adjust the on/off logic and the value of threshold to suit what you want to do.
The problem is that we could see on my sensorValue, when i open the Serial Tracer, the values are always changing from 0 to 1023 bits ... We wanted to find a way to translate that into 1 and 0 , 1 when the tone works, 0 when there isn't tone.
The objective of our program is to recognize a suit of tones, and when its recognized, then, turn on the LED.
and we don't find anything to recognize the 0.5s tone 0.5 sec notone with the microphone ...
We already tried what you told to us... Thanks to be helping ! ![]()
Do you mean you want to recognise a pattern of tones, a tune? Because if so that's not what I understood.
I, like UKHB, thought you wanted to know there was or was not, a tone, and UKHB's code does exactly that. Using a threshold as he suggests, does effectively "digitise" the input and allows you to turn your LED off or on.
Are you saying that you are getting a wave on the analog in? That when the tone is playing, it varies between 0 and 1023?
Try this low-pass filter:
float filtered = 0;
loop() {
filtered = filtered * 0.95 + analogRead(0) * .05;
}
[code]
Another option is to simply keep the time that you recorded a value of above a threshold, and to treat the input as 0 only if it drops below that threshold and stays there for for .1 seconds or something.