MPXV7002DP Air Speed Sensor with Electron

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);

  int i = 0;
  int sum = 0;


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


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("   P2: ");
  Serial.print(P2 * 1000);
  Serial.print(" Pa");
  Serial.print("   P3: ");
  Serial.print(P3 * 1000);
  Serial.println(" Pa");


This is my output:


  • 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)?

Thank for helping me out. :slight_smile:

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.

That’s how I go about doing this at least :slight_smile:

Umm…I’m getting negative indoor pressure (~19.53 Pa) with the Arduino code. I don’t understand what’s happening! :frowning: :frowning:

You sure the ~ is a negative?

I see this in the link you posted for the Arduino code results showing negative results are possible.

Yes, but it doesn’t make sense to have an indoor atmospheric pressure differential of -19 Pa does it?

I don’t think I’m understanding this right.

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.

I’m still stuck on this sensor :slight_frown:

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