Home / Tutorials / Arduino Tutorial / Arduino Pressure Sensor Tutorial | MPS20N0040D

# Arduino Pressure Sensor Tutorial | MPS20N0040D

This site has built up a number of tutorials on how to measure almost anything. Now, we add to that list an Arduino pressure sensor featuring the MPS20N0040D and the HX710B Analog-to-Digital IC.

### In a Rush: Wiring the Pressure Sensor to Arduino

The pressure sensor conveniently sends out pulses according to the pressure data it reads. A clock pin provides timing for that data, like other synchronous protocols. Note that you can use any Arduino digital pin for the clock and data pins. Moreover, the Arduino’s 5V is enough to power the sensor module:

No library specific for this pressure sensor exists but you can use the same HX711 library for weight sensors. The HX711 and HX710B are both 24-bit analog-to-digital converters and provide the same pulse outputs. However, the original HX711 library gives out raw ADC values and not pressure. Hence, I decided to create my own library that gives the output in pascals, mmHg, atm, and psi.

Here’s an example sketch that displays the pressure in pascals in Serial Monitor:

### In Depth: How the MPS20N0040D Pressure Sensor Works

Basically, the MPS20N0040D measures the air or liquid pressure in its opening.

#### Bridge Circuit

The MPS20N0040D pressure sensor is a bridge circuit where one of the bridge elements is a pressure-sensitive resistor.  A source voltage is applied to the bridge at points 2 and 5 and output is measured at points 1 or 6, and 4.

The voltage output at points 1 or 6 and 4 is calculated using this formula:

$V_{out} = (\frac{R_{4}}{R_{3}+R_{4}} - \frac{R_{2}}{R_{1}+R_{2}})V_{in}$

You’ll notice that when all resistor values are equal, Vout is zero. A bridge with all resistor values equal is known as a balanced bridge.

Let’s say each resistor in the bridge is 10 ohms. Then the voltage output, for a 5V input, is:

$V_{out} = (\frac{10}{20} - \frac{10}{20})\cdot 5$

When pressure is applied, one of the resistances in the bridge changes value. This unbalances the bridge and Vout is no longer zero.

Let’s say that because of the pressure, R1 changed from 20 ohms to 10 ohms. The value Vout then becomes

$V_{out} = (\frac{10}{20} - \frac{10}{20 + 10})\cdot 5 = (0.5 - 0.333)\cdot 5 = 0.83335$

A 10-ohm change is a bit generous; in reality, the change in resistance is often very small. This corresponds to the voltage from the sensor Vout also being very small, way below the sensitivity of the Arduino’s ADC. Hence, there’s the need to use an external ADC, with a higher resolution than the Arduino’s 10-bit ADC. That’s the job of the HX710B.

#### Converting Voltage to Pressure

The HX710B is a 24-bit ADC that sends out pulses based on the voltage it reads. The higher the number of pulses within a specified frame, the higher the voltage measured. A 24-bit ADC can detect a voltage level of as low as:

$Sensitivity = \frac{5}{2^{24}} = 2.98023\, x\, 10^{-7} \, V$

$Sensitivity = \frac{5}{2^{10}} \approx 4.88\, x\, 10^{-3} \, V$The MPS20N0040D gives out a voltage output that is linearly proportional to the applied pressure in kilopascals.

$V- V_{1} = \frac{V_{2} - V_{1}}{P_{2} - P_{1}} (P - P_{1})$

$V - 0.5 = \frac{4.5 - 0.5}{40 + 40} (P + 40)$

$V = 0.005P + 2.5$

$P = 200V + 500$

We can use this formula to convert the ADC output value to pressure in pascals.

$ADC\, value = \frac{V}{Sensitivity}$

$P = 200 * Sensitivity * ADC\, value + 500$

For a 24-bit ADC like the HX710B, the equation becomes:

$P = 1.430\, x\, 10^{-3} * ADC value + 500$

This is the equation used in the library to read the pressure in pascals.

For other units of pressure, we just use conversion factors:

$1\, Pa = 0.00750062 \, mm Hg$

$1 \, Pa = 0.000145038\, psi$

$1\, Pa = 9.86923\, x\, 10^{-6}\, atm$

### Example Project: Liquid Level Sensor

It is possible for a pressure sensor to measure the current level of any liquid. Here's an example setup, where the KP610 device can be the MPS20N0040D pressure sensor (image from pressure-sensors.eu):

As the liquid level rises, the pressure inside the tube on the sensor increases. The height of the liquid is proportional to pressure with the formula:

$P_{gauge} = \rho h g$

where ρ is the density of the liquid, h is the liquid height and g is the acceleration due to gravity.

## Using a Fingerprint Sensor

Fingerprint sensors are old technology but it wasn’t readily available to makers until it was …

Hx710b:4:11: error: conflicting declaration 'const int SCK'

const int SCK = 3; //sensor clock pin

^

In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:257:0,

from sketch\Hx710b.ino.cpp:1:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard/pins_arduino.h:46:22: note: previous declaration as 'const uint8_t SCK'

static const uint8_t SCK = PIN_SPI_SCK;

^

exit status 1
conflicting declaration 'const int SCK'