Hi i'm trying to make a Wind Sensor for my project and what i'm using as a wind sensor is a Microphone Module.
The problem is that when I blow into the Microphone it makes jammed sounds but sometimes it makes a consistent sounds only if I blow hard into it, how do I make a consistent reading so that it would not make jammed sounds?
Here is a video of my project.
And here is the code of my Microphone Module:
int senseMic = 0; //analog pin of gizduino //pin14
int speakerPin = 20; //analog pin of gizduino
void setup(){
Serial.begin(9600);
}
void loop(){
int val = analogRead(senseMic);
//If Wind Is blown
if (val > 540 || val < 490){
tone(speakerPin, 277.180)
}
//If Wind Is not blown
else{
noTone(speakerPin);
}
}
Exactly. Mic outputs audio, about 20 Hz and up. To measure it, you need rectify and smooth it. Otherwise, as it jumps up and down there is a chance analogRead would measure when it crosses zero line.
Magician:
Exactly. Mic outputs audio, about 20 Hz and up. To measure it, you need rectify and smooth it. Otherwise, as it jumps up and down there is a chance analogRead would measure when it crosses zero line.
// Define the number of samples to keep track of. The higher the number,
// the more the readings will be smoothed, but the slower the output will
// respond to the input. Using a constant rather than a normal variable lets
// use this value to determine the size of the readings array.
const int numReadings = 10;
int readings[numReadings]; // the readings from the analog input
int index = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average
int speakerPin = 20; //analog pin of gizduino //pin14
int inputPin = 0; //analog pin of gizduino
void setup(){
Serial.begin(9600);
// initialize all the readings to 0:
for (int thisReading = 0; thisReading < numReadings; thisReading++)
readings[thisReading] = 0;
}
void loop(){
// subtract the last reading:
total= total - readings[index];
// read from the sensor:
readings[index] = analogRead(inputPin);
// add the reading to the total:
total= total + readings[index];
// advance to the next position in the array:
index = index + 1;
// if we're at the end of the array...
if (index >= numReadings)
// ...wrap around to the beginning:
index = 0;
// calculate the average:
average = total / numReadings;
// int val = analogRead(senseMic);
Serial.println(average);
//If Wind Is blown
if (average > 540 || average < 490){
tone(inputPin, 277.180);
}
//If Wind Is not blown
else{
noTone(inputPin);
}
//delay(1000);
}
Thank you sir, I updated my code and combined it with the smoothing code. I will try to test it tomorrow. BTW, am I doing the code right? lol
So you have AC coupling and the resistors setting the level to an analog read of ~511 with no wind blown, and then the output would turn on/off from there.
I think perhaps using an envelope follower might give a better result, so the level into the ADC would be a steadier DC-ish kind of level.
Take the amplified signal you have now (IC1), rectify it (IC2), and run it thru a low pass filter/buffer (IC3) to feed the ADC.