Trying to calculate the wind speed using a pitot tube MPXV7002DP.
We are getting the dynamic pressure from the sensor and then applying Bernoulli's equation:
pd = dynamic pressure
air density = 1.225kg/m^3
windspeed = sqrt(2*Pd/air density)
We are using an Arduino UNO.
We think that there is problem with reading the pressure from the sensor.
We don't know how to get the correct values.
#include <SoftwareSerial.h>
float Output=0;
void setup() {
Serial.begin(9600);
}
void loop() {
float sensorValue = analogRead(A0);
output=sqrt((2*sensorValue)/1.225);
Serial.println(output);
Serial.print("m/s");
delay(100);
}
As one commenter pointed out, the return value of analogRead is an integer from 0-1023. This is a scaling of the voltage on pin A0, from 0 to the comparison voltage. (If you're using a 5V Arduino, 1023 is 5V. 3V Arduino, 1023 is 3V. It doesn't look like you're doing anything complicated that alters what you're using as your comparison voltage, so this should be accurate.)
I'm going to assume that you're working with 5V, since that's what your sensor uses.
What you need to do is look at the data sheet for your device, to determine what the relationship between pressure and voltage is. Looking at the sheet, you have a complicated bugger here, but from the graph on page 5, it looks like you can assume that 0.5V (analogRead of around 102) is a pressure of -2kPa and a 4.5V (analogRead of around 921) is a pressure of 2kPa. You're in luck that the scaling is linear.
I say "around" because it's clear that the device has quite a bit of slop in it's response - at least plus-or-minus .5V or .2kPa! (In other words, 0kPa could read anywhere from 462 to 562.)
You should map analogRead values from 0-102 to -2kPa, from 921-1023 to 2kPa, and everything in between should be a lerp between -2 and 2. I don't have an arduino in front of me so I can't try it out, but it should be something like:
result = analogRead(A0);
if (result < 102) {
kPa = -2.0;
} else {
if (result > 921) {
kPa = 2.0;
} else {
kPa = map(result, 102, 921, -2000, 2000)/1000.0;
}
}
Let me know, in the comments, if I screwed something up and I'll see about fixing it. This is all without the benefit of being able to actually compile/test. =]