how can I get wind speed from digital wind speed sensor
I try a lot of code but it doesn't work
example
float windspeed;
volatile unsigned long start, duration;
void setup()
{
Serial.begin(9600);
pinMode(27,INPUT);
pinMode(5,OUTPUT);
attachInterrupt( 0, wspeed, RISING );
start=millis();
}
void wspeed()
{
duration = millis() - start;
start = millis();
}
void loop()
{
digitalWrite(5,digitalRead(27));
Serial.print ("windspeed : ");
windspeed = ( 312.5/ (float) duration ); // .3125 mph per hz
if (duration > 1000)
{
windspeed =0;
}
Serial.print (windspeed);
Serial.println (" MPH");
}
peak_wichu:
I try a lot of code but it doesn't work
What does it do?
A common approach is to use interrupts as you did, but just increment a count. Periodically, calculate windspeed and zero out the count again.
MarkT
3
No need to zero out the count, just remember the last value you read.
Also you may need a critical section to read the count if its an 8-bit microcontroller and
more than 8 bits of counter...
wildbill:
What does it do?
A common approach is to use interrupts as you did, but just increment a count. Periodically, calculate windspeed and zero out the count again.
I don't know how to pause loop for counting interrupt. Please show me how. Thank you
system
Closed
5
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.