Go Down

Topic: Wind Sensor Problem (Read 2127 times)previous topic - next topic

xxryan1234

Jan 08, 2013, 04:12 amLast Edit: Jan 08, 2013, 04:13 am by xxryan1234 Reason: 1
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:
Code: [Select]
`int senseMic = 0; //analog pin of gizduino //pin14int speakerPin = 20; //analog pin of gizduinovoid 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);  }  }`

#1

xxryan1234

#2
Jan 08, 2013, 06:41 am
Here is the schematics of my Microphone Module

xxryan1234

#3
Jan 08, 2013, 09:09 am
So you are saying sir that I should use smoothing so that I can avoid this spiky sounds I hear?

Magician

#4
Jan 08, 2013, 10:10 am
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.

xxryan1234

#5
Jan 08, 2013, 02:43 pm

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.

Code: [Select]
`// 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 inputint index = 0;                  // the index of the current readingint total = 0;                  // the running totalint average = 0;                // the averageint speakerPin = 20; //analog pin of gizduino //pin14int 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

#6
Jan 08, 2013, 03:20 pm
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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

xxryan1234

#7
Jan 08, 2013, 04:23 pm
IC1-IC4 is still LM358 right?

Magician

#8
Jan 09, 2013, 04:29 am
Look here, they allow preview of books:

http://www.scribd.com/doc/52955966/Arduino-Cookbook

What do you should search, if this link 'd fail in your country, is:

O'Reilly  Arduino Cook Book by Michael Margolis 2-nd edition

pages 198 - p. 202 Detecting Sound

There is a code, all explain in great details.

xxryan1234

#9
Jan 09, 2013, 03:35 pm

Look here, they allow preview of books:

http://www.scribd.com/doc/52955966/Arduino-Cookbook

What do you should search, if this link 'd fail in your country, is:

O'Reilly  Arduino Cook Book by Michael Margolis 2-nd edition

pages 198 - p. 202 Detecting Sound

There is a code, all explain in great details.

okay magician thanks I will look into this and test it out right away tomorrow.

Go Up