I am trying to get air speed information using the MPXV7002DP sensor. I found 2 sources here [approach 2] and here [approach 1] for this sensor and modified the code for Electron accordingly as:
int sensorPin = A0;
int sensorValue = 0;
int offset = 0;
float Vout = 0;
long P = 0;
int s2;
float v2, P2, P3;
void setup() {
pinMode(sensorPin, INPUT);
Serial.begin(9600);
int i = 0;
int sum = 0;
Serial.println("init...");
//Calibrate offeset
for (i = 0; i < 10; i++)
{
sensorValue = analogRead(sensorPin) - 2048; //How is this value chosen? should this be 2048??
sum += sensorValue;
}
offset = sum / 10.0;
Serial.println("Ok");
}
void loop() {
//approach 1
sensorValue = analogRead(sensorPin);
Vout = (5 * sensorValue) / 4096.0; //sensor adc to voltage
P = Vout - 0.5; //is 2.5 the offset voltage. why is this necessary?
//approach 2
s2 = sensorValue - offset; //with "calibration" ?
v2 = (5 * s2) / 4096.0; //adc to v
P2 = v2 - 2.5;
//approach 3
P3 = (Vout / 5.0 - 0.5) / 0.2; //transfer function from from the datasheet ; in kPa
//Print all
Serial.print("P = " );
Serial.print(P * 1000);
Serial.print("Pa");
Serial.print(" P2: ");
Serial.print(P2 * 1000);
Serial.print(" Pa");
Serial.print(" P3: ");
Serial.print(P3 * 1000);
Serial.println(" Pa");
delay(1000);
}
This is my output:
Questions:
Q1. Is my code implementation right?
Q2. Which approach of getting the pressure (P, P2 and P3) is correct?
Q3. Can I use the pressure obtained from the above code in the equation here to get true air speed?
Q4. The abovementioned sources say that the output is in Pa. So does that mean that this sensor cannot measure atmospheric pressure since the current atm pressure of 30 inHg = 101.58kPa and this sensor caps at 2kPa (i understand it is a differential pressure sensor but, even if a close one of the opening, I get random values for P, P2 and P3, which don’t correspond to the expected drop in pressure)?
If the original library is an Arduino library then I would just compare output data between each other and if the Photon data matches the Arduino data then I would say your port worked just fine. If you see differences then you still may need to tweak the code.
I’m guessing you’re just seeing noise in the readings and the fact that your probably not getting a perfect 5V from the Vin pin due to the protection diode dropping the input voltage from USB.
Here is something I came across from a google search for this same sensor.
I did see this one and tried it… I get a different set of values (-0.01kPa to 0.02kPa) when i use these mapping limits. The datasheet for the sensor says that it should be able to operate at 4.5V.
It’s been a while. Did you figure this out? Regarding the negative pressure it is common for the lower levels of a building to have lower pressure than the upper floors. See this basic image: https://www.google.com/search?q=pressure+floors+of+building+neutral+plane&rlz=1C9BKJA_enUS759US759&hl=en-US&prmd=sivn&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjWkb3syIPdAhUFLqwKHRBtA14Q_AUIEigC&biw=1024&bih=653#imgrc=izMsabjkmLOGDM:
You can google neutral pressure plane.
Also the sensor is a differential pressure meter. It is trying to give you the difference in pressure between the ports. When connected to a pito tube and in motion, or the ports connected to different air spaces, the sensor outputs the difference. If both ports are exposed to the same air space in your house you will not get meaningful data. Does that make sense?
I am interested in using the sensor with particle to monitor the differential pressure in a radon mitigation system.