Pages: [1]   Go Down
Author Topic: Wind Sensor Problem  (Read 1157 times)
0 Members and 1 Guest are viewing this topic.
Cebu City
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Hi im new to arduino!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

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);
  }
  
}
« Last Edit: January 07, 2013, 10:13:37 pm by xxryan1234 » Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 30
Posts: 2602
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://arduino.cc/forum/index.php/topic,140976.0/topicseen.html
Logged

Cebu City
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Hi im new to arduino!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is the schematics of my Microphone Module


* amp.PNG (40.11 KB, 1237x885 - viewed 38 times.)
Logged

Cebu City
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Hi im new to arduino!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Montreal
Offline Offline
Faraday Member
**
Karma: 30
Posts: 2602
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Cebu City
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Hi im new to arduino!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

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

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27361
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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.

Cebu City
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Hi im new to arduino!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

IC1-IC4 is still LM358 right?
Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 30
Posts: 2602
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Cebu City
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Hi im new to arduino!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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. smiley-grin
Logged

Pages: [1]   Go Up
Jump to: