Pages: [1] 2   Go Down
Author Topic: vortex wind speed sensor  (Read 3031 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi im trying to calculate the wind speed using an anemometer, I followed my code according to
 http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1244483843/all

 However I am unable to get it work.Could anyone please help

float windspeed=0;
//float windvanevalue1=0;
//float windvanevolts1=0;

unsigned long duration;
void setup()
{
  Serial.begin(9600);
  pinMode(13,INPUT); //reads the input from pin 13
 // attachInterrupt(0, count, LOW);
}

void loop(){
  duration=pulseIn(13,LOW);
 

 Serial.print(duration  );
 Serial.print("windspeed in m/s ");
  windspeed smiley-cry(1000000.0/ duration*2.5)/0.447);
  Serial.print(windspeed,DEC);
  Serial.println(" ");

  delay(500);
 }

my outputs are shown below makes no sense to me


0   windspeed in m/s smiley-mad.0000000000
192355   windspeed in m/s :29.0756206512
4   windspeed in m/s :1398210.2500000000
4   windspeed in m/s :1398210.2500000000
4   windspeed in m/s :1398210.2500000000
6   windspeed in m/s :932140.2500000000
4   windspeed in m/s :1398210.2500000000
4   windspeed in m/s :1398210.2500000000
4   windspeed in m/s :1398210.2500000000
4   windspeed in m/s :1398210.2500000000
0   windspeed in m/s smiley-mad.0000000000
4   windspeed in m/s :1398210.2500000000
4   windspeed in m/s :1398210.2500000000
4   windspeed in m/s :1398210.2500000000
4   windspeed in m/s :1398210.2500000000
4   windspeed in m/s :1398210.2500000000
4   windspeed in m/s :1398210.2500000000
159973   windspeed in m/s :34.9611549377
6   windspeed in m/s :932140.2500000000
0   windspeed in m/s smiley-mad.0000000000
4   windspeed in m/s :1398210.2500000000
4   windspeed in m/s :1398210.2500000000
4   windspeed in m/s :1398210.2500000000
4   windspeed in m/s :1398210.2500000000
4   windspeed in m/s :1398210.2500000000
4   windspeed in m/s :1398210.2500000000
4   windspeed in m/s :1398210.2500000000
0   windspeed in m/s smiley-mad.0000000000
4   windspeed in m/s :1398210.2500000000
4   windspeed in m/s :1398210.2500000000
4   windspeed in m/s :1398210.2500000000
0   windspeed in m/s smiley-mad.0000000000
4   windspeed in m/s :1398210.2500000000
0   windspeed in m/s smiley-mad.0000000000
Logged

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

Something wrong with your hardware setup.
Duration is too low :  mostly 4 or 6 usec.
What kind of sensor is that? Have a link or picture?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hard ware setup was done according to the link on my post red wire to 5v and the black to pin 13 which contains a pull up resistor

sensor

http://inspeed.com/anemometers/Vortex_Wind_Sensor.asp

thanks
Logged

Carbondale Illinois
Offline Offline
Full Member
***
Karma: 1
Posts: 104
Making digital rivers.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Looks like the poster you referenced had a lot of problems; kind of a squirrely setup :-)

You're mixing an interger (duration) and floats here:

windspeed = (1000000.0/ duration*2.5)/0.447);

That could be a problem.  I always seem to have problems with that in my code.

Logged

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

Don't think so, he is printing "duration" - first digit in line:
Quote
4   windspeed in m/s :1398210.2500000000
4   windspeed in m/s :1398210.2500000000
4   windspeed in m/s :1398210.2500000000
6   windspeed in m/s :932140.2500000000

I think, the problem is related to pin 13 (unlucky) number, it has led-resistor attached to it on board, that would mix up with pull-up resistor in wrong way.

 Edited:

1. Schematic.
2.
Code:
duration=pulseIn(10,LOW);

 Serial.print( duration  );
 Serial.print("windspeed in m/s ");
  windspeed ( 2.5 * 1000000.0 / duration );
  Serial.print(windspeed,DEC);
  Serial.println(" MPH");

  delay(500);


* anemometr1.png (12.7 KB, 800x600 - viewed 74 times.)
« Last Edit: July 24, 2011, 10:41:59 pm by Magician » Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think I see a couple of problems. First, I wouldn't use pin 13 as my digital input because of the LED that is normally on that pin. Pick another if you can. Your sensor is just a reed switch that closes every time a magnet passes by it, so basically it is a one pulse per revolution (1PPR) generator. I would put a pull-up resistor on one of the DIO pins, say 10K, pulled up to your supply voltage. Then connect one of your sensor leads to the DIO pin and the other sensor lead to ground. This will produce a 1PPR signal that is normally at supply voltage and goes to 0 volts every time the reed switch closes. The signal is pretty noisy too because of the reed switch and will require some sort of de-bouncing. That's the reason you get the 4-6 from the pulse() function. That's the duration of the first bounce.

Measuring the pulse width on that pin doesn't give you the information you need. You need to measure the duration of each revolution, that is the time between the signal making its High to Low transition each revolution.  The data sheet for your sensor says that if it rotates one revolution in one second (1Hz) then that is 2.5 mph. Let's say you're on Mars or somewhere that the wind can get up to 250 mph. In that case the sensor would be rotating at 100 revolutions per second (100Hz) and the duration of one revolution would be 10 milliseconds, so you can safely de-bounce your sensor input for 10 to 20 milliseconds and still measure wind speed up to a reasonable maximum.

I would start a timer when your DIO pin goes LOW. Then I would wait 10-20 milliseconds for the reed switch to stop bouncing and then wait for it to go LOW again and then stop and read the timer. The amount of elapsed time then would be used to calculate wind speed.

Does that make sense?
Logged

Carbondale Illinois
Offline Offline
Full Member
***
Karma: 1
Posts: 104
Making digital rivers.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sounds like a good approach, EmilyJane; and re "duration" variable, pulseIn() returns an unsigned long, and I had real problems with it in code similar this until I cast it as a float before using it in a formula with division.

Not my area of expertise at all, but seems to me a potential problem! :-)

Another thing:  I've done a lot of work with water velocity meters like this, and you'll always want some way to average readings over a time period, both a short one like 1 or 2 seconds to eliminate spurious readings, and a longer one, maybe 5 or 10 seconds, to eliminate real changes in the rotor speed caused by turbulence and small gusts.  Probably the literature with the meter covers this.
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I agree. Without averaging, the reading is going to be pretty "noisy". Sensing the reed switch closure will introduce some noise as well. I don't think the pulseIn() function will be of any use here but one should always be wary of mixing data types in arithmetic.

I left out some steps in my post above. After sensing that the input has gone LOW one will have to make sure that it has gone HIGH again before looping to detect its next LOW transition. This will be important at low wind speeds.

This topic came up a couple of years ago and I don't know if the OP ever got it to work. The company that sell the sensor supplies a "readout" that is just repurposed bicycle computer.

I recommend taking a look at the conditioned sensor output with an oscilloscope to get a feel for how the LOW time varies with windspeed. If it was me, I'd run it through a one-shot to create a de-bounced, repeatable signal, as well.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the reply emilly jane and others

I will purchase some resistors tomorrow and have the wires connected to a digital I/o port as u suggested. I think I would understand better if you can please provide me with some kind of a pseudocode as I am very new to programming

thankyou

Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

One approach would be to generate an interrupt with your sensor and increment a counter in the interrupt handler. You could wait a fixed period of time in your foreground program and then read the number of interrupts (sensor revolutions) that had occurred during that time period and calculate windspeed from that.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could you please help me with the coding here.No idea how to use these intrupts

thankyou
Logged

Carbondale Illinois
Offline Offline
Full Member
***
Karma: 1
Posts: 104
Making digital rivers.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Lots of stuff in the reference section and forum.  And try here:  http://arduino.cc/forum/index.php/topic,57262.0.html
Logged

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

There is a code, that using interruption for calculation of the speed:
http://tronixstuff.wordpress.com/2011/06/22/tutorial-arduino-timing-methods-with-millis/
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Magician and Emilly for your help for the following code and hardware setup
Hi this is my new code. According to the outputs im getting its still not right. When I initially starts to twist the anemometer it gives a proper reading then even while its spinning its gives me 0m/s before coming into live once again.when I let it go it slows down gives proper readings and then when its suddenly stopped it gives a wrong speed(eg 278m/s).Then when i twist again it goes back to zero and starts giving correct outputs again.Outputs are on the bottom of this page.

float  windspeed;        // wind speed
unsigned long   start,  duration;

void setup()
{
  Serial.begin(9600);
  pinMode(2,INPUT); //reads the input from pin 2
 
  attachInterrupt( 0, wspeed,  FALLING );
  start=millis();
  delay(20);
}

void wspeed()
{
  duration = millis() - start;
  start       = millis();
}

void loop(){
   
 Serial.print (" duration of the one turn ( msec ) : ");
 Serial.println ( duration );
 Serial.print ("windspeed : ");

  windspeed = ( 2.5 * 1000.0 / (float) duration )*(0.447);

  Serial.print (windspeed);
  Serial.println (" m/s");

  delay(500);
 }




OUTPUTS


windspeed : 0.00 m/s
 duration of the one turn ( msec ) : 0
windspeed : 0.00 m/s
 duration of the one turn ( msec ) : 60
windspeed : 18.62 m/s                                                      //START
 duration of the one turn ( msec ) : 0
windspeed : 0.00 m/s
 duration of the one turn ( msec ) : 0
windspeed : 0.00 m/s
 duration of the one turn ( msec ) : 224
windspeed : 0.00 m/s
 duration of the one turn ( msec ) : 0
windspeed : 0.00 m/s
 duration of the one turn ( msec ) : 0
windspeed : 0.00 m/s
 duration of the one turn ( msec ) : 98
windspeed : 11.40 m/s
 duration of the one turn ( msec ) : 118
windspeed : 9.47 m/s
 duration of the one turn ( msec ) : 142
windspeed : 7.87 m/s
 duration of the one turn ( msec ) : 115
windspeed : 9.72 m/s
 duration of the one turn ( msec ) : 133
windspeed : 8.40 m/s
 duration of the one turn ( msec ) : 0
windspeed : 0.00 m/s
 duration of the one turn ( msec ) : 101
windspeed : 11.06 m/s
 duration of the one turn ( msec ) : 79
windspeed : 14.15 m/s                                                  //SLOWING DOWN BEGINS
 duration of the one turn ( msec ) : 0
windspeed : 0.00 m/s
 duration of the one turn ( msec ) : 91
windspeed : 12.28 m/s
 duration of the one turn ( msec ) : 89
windspeed : 12.56 m/s
 duration of the one turn ( msec ) : 102
windspeed : 10.96 m/s
 duration of the one turn ( msec ) : 0
windspeed : 0.00 m/s
 duration of the one turn ( msec ) : 0                           //0 AGAIN!!!
windspeed : 0.00 m/s
 duration of the one turn ( msec ) : 0
 duration of the one turn ( msec ) : 122
windspeed : 9.16 m/s
 duration of the one turn ( msec ) : 138
windspeed : 8.10 m/s
 duration of the one turn ( msec ) : 159
windspeed : 7.03 m/s
 duration of the one turn ( msec ) : 180
windspeed : 6.21 m/s
 duration of the one turn ( msec ) : 180
windspeed : 6.21 m/s
 duration of the one turn ( msec ) : 212
windspeed : 5.27 m/s
 duration of the one turn ( msec ) : 212
windspeed : 5.27 m/s
 duration of the one turn ( msec ) : 252
windspeed : 4.43 m/s
 duration of the one turn ( msec ) : 252
windspeed : 4.43 m/s
 duration of the one turn ( msec ) : 0
windspeed : 0.00 m/s
 duration of the one turn ( msec ) : 0
windspeed : 0.00 m/s
 duration of the one turn ( msec ) : 0
windspeed : 0.00 m/s
 duration of the one turn ( msec ) : 482
windspeed : 2.32 m/s
 duration of the one turn ( msec ) : 482
windspeed : 2.32 m/s
 duration of the one turn ( msec ) : 482
windspeed : 2.32 m/s
 duration of the one turn ( msec ) : 0
windspeed : 0.00 m/s
 duration of the one turn ( msec ) : 679
windspeed : 1.65 m/s
 duration of the one turn ( msec ) : 679
windspeed : 1.65 m/s
 duration of the one turn ( msec ) : 679
windspeed : 1.65 m/s
 duration of the one turn ( msec ) : 0
windspeed : 0.00 m/s
 duration of the one turn ( msec ) : 0
windspeed : 0.00 m/s
 duration of the one turn ( msec ) : 4
windspeed : 279.38 m/s
 duration of the one turn ( msec ) : 4                      //ANEMOMETER HAS STOPPED ALLREADY! WRONG OUTPUT
windspeed : 279.38 m/s
 duration of the one turn ( msec ) : 4
windspeed : 279.38 m/s
 duration of the one turn ( msec ) : 4
windspeed : 279.38 m/s
 duration of the one turn ( msec ) : 4
windspeed : 279.38 m/s
 duration of the one turn ( msec ) : 0                       //NOW I TWIST AGAIN TO MAKE IT SPIN
windspeed : 0.00 m/s
 duration of the one turn ( msec ) : 0
windspeed : 0.00 m/s
 duration of the one turn ( msec ) : 659
windspeed : 1.70 m/s
 duration of the one turn ( msec ) : 659
windspeed : 1.70 m/s

Logged

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

Well, it's true that variable windspeed is not "up to date" when no "new" interruption was registered since last printing. To make your printing "smart", and print information only if it's fresh new, add flag in your code: "updated".
Code:
float  windspeed;        // wind speed
unsigned long   start,  duration;

int updated = 0;   //  <<<<--------  flag

void setup()
{
  Serial.begin(9600);
  pinMode(2,INPUT); //reads the input from pin 2
 
  attachInterrupt( 0, wspeed,  FALLING );
  start=millis();
  delay(20);
}

void wspeed()
{
  duration = millis() - start;
  start       = millis();
  updated = 1;
}

void loop(){
   
if (updated){

 Serial.print (" duration of the one turn ( msec ) : ");
 Serial.println ( duration );
 Serial.print ("windspeed : ");

  windspeed = ( 2.5 * 1000.0 / (float) duration )*(0.447);

  Serial.print (windspeed);
  Serial.println (" m/s");

  delay(500);
 updated = 0;  // <<<<<---- reset a flag, so it woudn't print "old data".

   }

 }

Logged

Pages: [1] 2   Go Up
Jump to: