# Writing Arduino code for MPXV6115V pressure sensor

I'm attempting to use an MPXV6115V pressure sensor to monitor the constant vacuum of a suction device. I haven't been able to find a library to use with this sensor. I'm very new to Arduino but I am a software developer so would like to write some code to get this sensor working. The datasheet for this sensor can be found here. I've had some success using the code found here but this is for a different MPX pressure sensor and the output doesn't look right, I believe my constant values might need adjusting but not sure.

I've heard I may be able to use the transfer function for the basis of the code? I'm really not sure where to start with that. Could someone please explain how I can write the code to get this sensor working with the Arduino? Thank you.

• why would you need a library? ... the sensor outputs voltage that is proportionsl to the pressure ... measure the voltage Jan 30, 2022 at 5:33

The linked code basically just does `analogRead()`s, calculates a real world value from the results and sends it over Serial. Thats also what you want to do, you just need to change the calculation.

So take the transfer function of your sensor and reorder it so that you get a formula for P:

``````P = (Vout/Vs - 0.92)/0.007652
``````

with Vs being the supply voltage (5V in this case) and Vout being the output voltage. The ADC of the Arduino is 10 bits, so it gives you a value in the range of 0 to 1023 for 0V to 5V. So you get the voltage by calculating

``````voltage = analogRead(pin) / 1023.0 * 5.0;
``````

Now put that into the formula above, write it as proper C++ code (for the variables use `float` as type, while `pin` is an integer and is the pin you connected the sensor to, like `A0`) and then replace the calculation in the linked code with yours - or wrote your own complete code. There isn't much to do besides `analogRead()`, the calculation and corresponding `Serial.println()` calls.