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:

Arduino pressure sensor wiring

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.

You can clone/download the library on this page and place it directly to the Documents/Arduino/libraries folder.

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

Want to learn more about how the pressure sensor works? Read on below.

In Depth: How the MPS20N0040D Pressure Sensor Works

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

MPS20N0040D Arduino pressure sensor front

MPS20N0040D Arduino pressure sensor back MPS20N0040D Arduino pressure sensor dimensionThe 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.

MPS20N0040D wiring

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

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:

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

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.

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:

In comparison, a 10-bit ADC, the Arduino’s ADC via the analog input can detect:

The MPS20N0040D gives out a voltage output that is linearly proportional to the applied pressure in kilopascals.

MPS20N0040D voltage vs pressure

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

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

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

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

Example Project: Liquid Level Sensor

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

Liquid level detection - Pressure-sensors.eu

As the liquid level rises, the pressure inside the tube connected to the sensor increases. The height of the liquid is related to pressure through the formula:

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

Check Also

Arduino State Machine Diagram

Arduino State Machine Tutorial

A finite state machine (FSM) is a theoretical machine that only has one action or …

Leave a Reply

Your email address will not be published. Required fields are marked *