Go Down

Topic: Wind Sensor Problem (Read 1 time) previous topic - next topic

xxryan1234

Jan 08, 2013, 04:12 am Last 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?

http://www.youtube.com/watch?v=-uweEueGjWg&list=HL1357613504&feature=mh_lolz

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 //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);
 }
 
}

Magician


xxryan1234

Here is the schematics of my Microphone Module

xxryan1234

So you are saying sir that I should use smoothing so that I can avoid this spiky sounds I hear?

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.

xxryan1234


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 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

CrossRoads

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. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

xxryan1234

IC1-IC4 is still LM358 right?

Magician

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


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. :D

Go Up