pressure transducer programming

For my air pressure pump project i'm trying to attach a positive pressure transducer to the system.one of my pal gave me a link and code for the listed sensor below. please help me as I'm trying to learn

the sensor he mentioned was a Free Scale MPX4115 .
I could not understand the code below even after referring to the transfer function.

/* get the pressure /
val = analogRead(pressurePin);
pkPa = ((float)val/(float)1023+0.095)/0.009;
pAtm = kpa2atm
pkPa;

the whole code can be see in:

and also is it possible for me to use the MPX4250 Sensor in the same code. if not what are the differences should be made???

Those sensors are almost the same.
They measure the absolute (baromic) pressure, have analog output, and are temperature compensated.

The MPX4250A has a larger range and is therefor less accurate for low pressures.
MPX4250A up to 250kPa.
MPX4115A up to 115kPa.

In the ideal situation the output voltage would be 0.0 to 5.0V, but they need a little adjustment.

I always suggest to use more variables, and more code lines for such calculations. It will be just as fast after the code is compiled.

  // not tested code, it might be wrong

  int val = analogRead(pressurePin);      // read the rawADC value.
  float voltage = (float) val / 1023.0 * 5.0;   // voltage at the input pin

  // according to the datasheet:
  //   - the minimal voltage is 0.135 at 15kPa.
  //   - the maximum voltage is 4.863 at 115kPa
  //   - the full span is 4.590
  //   - and is 45.9mV per kPa
  float pkPa = ((voltage - 0.135) / 0.0459) + 15;

  // convert kPa to atm
  #define kpa2atm 0.00986923267
  float pAtm = kpa2atm * pkPa;

You can add Serial.println() after each line to see if the calculation going well, step by step.

Dear calota
than for the explanation. i really appreciate ur help done to me even it may be wrong or right :slight_smile:

You can print the voltage at the pin to the serial monitor, and measure that voltage with a multimeter. That is the fastest way to detect if everything is okay.