Contents

Interfacing MPS20N0040D Barometric Pressure Sensor with Arduino

MPS20N0040D Pressure Module Features

The MPS20N0040D Pressure and Altitude Sensor Module is an MPS20N0040D pressure sensor that receives altitude data and transmits it to the HX710 IC, which is an ADC converter. This module is used to measure the ambient pressure and the pressure difference of liquid levels.

Note:

This module does not support I2C communication.

You can download the datasheet of this module here.

MPS20N0040D Pressure Module Pinout

This sensor has 4 pins:

  •  VIN: Module power supply – 3.3-5 V
  •  GND: Ground
  •  SLC: I2C Clock
  •  OUT: Digital output data

You can see pinout of this module in the image below.

Required Materials

Hardware Components

Arduino UNO R3 × 1
MPS20N0040D Pressure Module × 1
Male Female Jumper Wire × 1

Software Apps

Arduino IDE

Interfacing MPS20N0040D Sensor with Arduino

Step 1: Circuit

The following circuit shows how you should connect Arduino to MPS20N0040D module. Connect wires accordingly.

Step 2: Code

Tip

If you need more help with installing a library on Arduino, read this tutorial: How to Install an Arduino Library

Upload the following code to your Arduino
/*
  on Sep 21, 2020
  by MohammedDamirchi
  
Home
*/ #include <Q2HX711.h> #include <Average.h> const byte MPS_OUT_pin = 2; // OUT data pin const byte MPS_SCK_pin = 3; // clock data pin int avg_size = 10; // #pts to average over Q2HX711 MPS20N0040D(MPS_OUT_pin, MPS_SCK_pin); // start comm with the HX710B Average<long> ave(avg_size); void setup() { Serial.begin(9600); // start the serial port } void loop() { ave.push(MPS20N0040D.read()); Serial.println(ave.mean()); }

After running the code, you will see the following image in the serial monitor.

Liked What You See?​
Get Updates And Learn From The Best​

Comments (21)

  • Domingo Vega Reply

    Hi thks for your input…but which units are obtained with this code..KPa?

    November 16, 2020 at 6:12 pm
    • Mehran Maleki Reply

      Hi Domingo, you’re welcome. Actually the output of HX711 is an integer. So the output of the code the average of 10 integers. It is not Pascal. For calculating the pressure accurately, the module needs to be calibrated in the region that it’s going to be used. And for calibration you can follow these steps: First go to a place where you already know the pressure, then use this module with the given code and write the output of it. Then you can easily calculate the pressure of different places by using proportionality.

      December 2, 2020 at 9:34 am
  • amir Reply

    hi,Thanks for the tutorial
    My question is the sensor output in kilopascals?

    May 16, 2021 at 10:30 am
    • Mehran Maleki Reply

      Hi. Your question is actually answered in the previous comment as well. Here it is: “the output of HX711 is an integer. So the output of the code the average of 10 integers. It is not Pascal. For calculating the pressure accurately, the module needs to be calibrated in the region that it’s going to be used. And for calibration, you can follow these steps: First go to a place where you already know the pressure, then use this module with the given code and write the output of it. Then you can easily calculate the pressure of different places by using proportionality.”
      What you actually need to do is to calculate the output of the sensor in a place where you already know the atmospheric pressure of. And use that as a reference in converting the sensor output to KPa.

      May 17, 2021 at 5:31 am
  • amir Reply

    thanks for your help.
    I tested the sensor with a manometer, but the sensor does not read more than 70 mm Hg , but in the data sheet that the sensor works up to 40 kPa, ie 300 mm Hg. What do you think is the problem?
    In fact, my project is digital therapy barometer.

    May 17, 2021 at 9:41 am
    • Mehran Maleki Reply

      You’re welcome. I’m afraid it’s not easy to exactly figure out what’s going on, but there can always be a difference between what the datasheet says and how the sensor works in the real world. And also, the datasheet is talking about the sensor itself. When the sensor is used in a PCB and accompanied by some other components, its specifications may change.

      May 18, 2021 at 4:55 am
    • Francisco Rentería Reply

      Hola Amir espero estés bien, amir una consulta como te acabo de ir con el sensor ? estoy trabajando con el y efectivamente mide hasta 70 mmhg y me gustaria saber que hicistes para mejorar este rango o si estas trabajando con otro sensor

      October 17, 2021 at 7:03 pm
  • Pravin vaidya Reply

    Hi Mehran,
    Thank you for your code and tutorial. I have the same question as asked by Damigo and Amir. Let me put it in another way. What type of signals we get it output.. ? is it millivolts signals? if yes then what value does represent which pressure say for example 0.2 mV represents 50 kPa? Further, in this case, thus the integer value gave me the voltage value or pressure value? If its output is in mV then how to convert it into corresponding Pressure value or if the output is converted directly into pressure then does that value represent kPa, Atm, or bar or what is the SI unit for the output..

    Waiting for your kind help..

    June 14, 2021 at 9:44 am
    • Mehran Maleki Reply

      Hi,
      You’re so welcome, but it’s actually Mohammad’s tutorial, not mine, as you can see at the beginning of the tutorial right under the title. And about your question, the answer is somehow the same as the answer to Damigo, but I’ll put it in another way trying to make it a little clearer.
      First, the output of the module is a voltage between 0 and 5 volts BUT what is displayed on the Serial Plotter and Serial Monitor of Arduino IDE is an integer between 0 and 1024 which you can convert to volts using this formula: Suppose the integer displayed on Arduino Serial is X then: The sensor output voltage equals “5 * (X / 1024)”. So now you know all you need about the sensor output and what is displayed on the Arduino Serial.
      Second, you want to know the relationship between the sensor output and the actual pressure. Here’s the answer: There is a linear relationship between the pressure and the sensor output. But the formula needs to be found by the one using the sensor, since it’s not factory-calibrated. It means that you should save the sensor output in volts in a place where you already know the pressure of. That will be your reference sensor output and pressure. Then you can use the module anywhere else and calculate the pressure using this formula: pressure = sensor output * (reference pressure / reference output sensor)
      Good luck. Hope that helps!

      June 15, 2021 at 5:36 am
      • muhanad muhson Reply

        can i contact you

        August 1, 2021 at 3:45 pm
        • Mehran Maleki Reply

          If you have any questions regarding the tutorials or working with any kind of module or sensor, feel free to share them in the comments.

          August 2, 2021 at 4:51 am
          • muhanad muhson

            I have calibrated the sensor, but I extracted an equation for that..Now how can I add the equation to the code. Can you give me an example to explain it?

            August 2, 2021 at 11:50 am
  • muhanad muhson Reply

    I have calibrated the sensor, but I extracted an equation for that..Now how can I add the equation to the code. Can you give me an example to explain it?

    August 2, 2021 at 11:45 am
    • Mehran Maleki Reply

      The equation you have extracted has “ave.mean()” as its parameter, right? To add that to the code, you should first define a float variable. Like this: “float x;”
      Then, assign the equation to it in the next line. Like: “x = the equation”. After that, you can display it on the Serial Monitor using “Serial.println(x)” command.

      August 14, 2021 at 10:02 am
  • kapotik Reply

    Hello, your tutorial is very interesting, but I wonder if this pressure sensor and a scale can be used simultaneously with the HX711, if so, is it necessary to install the hx711 library or with Q2HX711 can both be controlled? Thank you

    September 9, 2022 at 8:16 pm
  • Johann Lorenz Reply

    Hallo Mehran, vielen herzlichen
    Dank für Ihren Code und Ihr Tutorial. Ich baue eine Wasserstandsmessung. Funktioniert mit “Arduino UNO”, aber nicht mit dem “ESP 8266 D1 mini”. Was muss ich da ändern?
    Herzlichen Dank für eine Antwort

    December 21, 2022 at 6:47 pm
    • Ali Abdolmaleki Reply

      Hi dear
      thank you for your attention
      only thing that you want is to connect the module to esp8266 i2c (GPIO5 & GPIO4)
      and also select your ESP8266 D1 mini board from the tools menu in Arduino IDE.

      February 28, 2023 at 3:13 pm
  • Peter Lörne Reply

    Hello.
    Is the result of the measurement affected by the difference in atmospheric pressure day by day?
    Would like to measure the water level in a container.
    Regards
    Peter Lörne

    April 9, 2023 at 8:49 pm
    • Mohammad Damirchi Reply

      Hello.
      Can you explain in more detail?
      Does the atmospheric pressure change when you are at the same level?

      April 16, 2023 at 9:23 am
  • ABHISHEK Reply

    hello i want to measure the pressure of my hho gas ..can u help me

    April 7, 2024 at 3:52 pm
    • Mohammad Damirchi Reply

      Hi,
      If you have gas, you can utilize this module without any additional configuration.
      However, if your gas may contain liquid at times, it’s advisable to use a tube to create distance between the two components. This helps prevent any liquid from mixing with the module.

      April 8, 2024 at 6:26 am

Leave a Reply

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