Learn Here About an Extremely Important Sensor!

Introduction: Learn Here About an Extremely Important Sensor!

About: Do you like technology? Follow my channel on Youtube and my Blog. In them I put videos every week of microcontrollers, arduinos, networks, among other subjects.

How can you find out about the water level in a water tank? To monitor this type of thing, you can use a pressure sensor. This is very useful equipment for industrial automation, in general. Today, we’re going to talk about this exact family of MPX pressure sensors, specifically for pressure measurement. I'll introduce you to the MPX5700 pressure sensor and perform a sample assembly using the ESP WiFi LoRa 32.

I will not use LoRa communication in the circuit today, neither WiFi nor Bluetooth. However, I opted for this ESP32 because I already taught in other videos how to use all the features that I discuss today.

Step 1: Demonstration

Step 2: Resources Used

• MPX5700DP Differential Pressure Sensor

• 10k potentiometer (or trimpot)

• Protoboard

• Connection wires

• USB cable

• ESP WiFi LoRa 32

• Air compressor (optional)

Step 3: Why Measure Pressure?

• There are numerous applications where pressure is an important control variable.

• We can involve pneumatic or hydraulic control systems.

• Medical instrumentation.

• Robotics.

• Control of industrial or environmental processes.

• Level measurement in liquid or gas reservoirs.

Step 4: The MPX Family of Pressure Sensors

• They are pressure transducers in electrical voltage.

• They are based on a piezo resistive sensor, where compression is converted into a variation of the electric resistance.

• There are versions capable of measuring small pressure differences (from 0 to 0.04atm), or large variations (from 0 to 10atm).

• They appear in multiple packages.

• They can measure absolute pressure (relative to vacuum), differential pressure (the difference between two pressures, p1 and p2), or gauge (relative to atmospheric pressure).

Step 5: The MPX5700DP

• The 5700 series features absolute, differential, and gauge sensors.

• The MPX5700DP can measure a differential pressure from 0 to 700kPa (approximately 7atm).

• The output voltage varies from 0.2V to 4.7V.

• Its power is from 4.75V to 5.25V

Step 6: For the Demonstration

• This time, we will not do a practical application using this sensor; we will only mount it and perform some measurements as a demonstration.

• For this, we will use a direct air compressor to apply pressure at the high pressure inlet (p1) and get the difference in relation to the local atmospheric pressure (p2).

• The MPX5700DP is a unidirectional sensor, which means that it measures positive differences where p1 must always be greater than or equal to p2.

• p1> p2 and the difference will be p1 - p2

• There are two-way differential sensors that can evaluate negative and positive differences.

• Although it is only a demonstration, we could easily use the principles here to control, for example, the pressure in an air reservoir, powered by this compressor.

Step 7: Calibrating the ESP ADC

• Since we know that ESP's analog-digital conversion is not completely linear and can vary from one SoC to another, let's start by making a simple determination of its behavior.

• Using a potentiometer and a multimeter, we will measure the voltage applied to the AD and relate it to the indicated value.

• With a simple program for reading the AD and collecting the information in a table, we were able to determine the curve of its behavior.

Step 8: Calculating the Pressure

• Although the manufacturer provides us the function with the behavior of the component, it is always advisable to carry out a calibration when we are talking about taking measurements.

• However, since it is only a demonstration, we will directly use the function found in the datasheet. For this, we will manipulate it in a way that gives us the pressure as a function of the ADC value.

* Remember that the fraction of the voltage applied to the ADC by the reference voltage must have the same value as the ADC read by the total ADC. (Disregarding the correction)

Step 9: Assembly

• To connect the sensor, look for the notch in one of its terminals, which indicates pin 1.

• Counting from there:

Pin 1 provides signal output (from 0V to 4.7V)

Pin 2 is the reference. (GND)

Pin 3 for power. (Vs)

• As the signal output is 4.7V, we will use a voltage divider so that the maximum value is equivalent to 3V3. For this, we made the adjustment with the potentiometer.

Step 10: ​Source Code

Source Code: #Includes and #defines

//Bibliotecas para utilização do display oLED
#include <Wire.h> // Necessário apenas para o Arduino 1.6.5 e posterior #include "SSD1306.h" // o mesmo que #include "SSD1306Wire.h" //Os pinos do OLED estão conectados ao ESP32 pelos seguintes GPIO's: //OLED_SDA -- GPIO4 //OLED_SCL -- GPIO15 //OLED_RST -- GPIO16 #define SDA 4 #define SCL 15 #define RST 16 //RST deve ser ajustado por software

Source: Global variables and constants

SSD1306 display(0x3c, SDA, SCL, RST); //Instanciando e ajustando os pinos do objeto "display"
const int amostras = 10000; //número de amostras coletadas para a média const int pin = 13; //pino de leitura const float fator_atm = 0.0098692327; //fator de conversão para atmosferas const float fator_bar = 0.01; //fator de conversão para bar const float fator_kgf_cm2 = 0.0101971621; // fator de conversão kgf/cm2

Source Code: Setup ()

void setup()
{ pinMode(pin, INPUT); //pino de leitura analógica Serial.begin(115200); //iniciando a serial // Inicia o display display.init(); display.flipScreenVertically(); //Vira a tela verticalmente }

Source code: Loop ()

void loop()
{ float medidas = 0.0;//variável para manipular as medidas float pressao = 0.0; //variável para armazenar o valor da pressão //inicia a coleta de amostras do ADC for (int i = 0; i < amostras; i++) { medidas = medidas + float(analogRead(pin)); } medidas = (medidas / float(amostras));//Tira a média das amostras pressao = calculaPressao(medidas); //Calcula a pressao em kPa //Exibe o tela inicial ou os valores de pressão //se está ligado a mais de 5 segundos, exibe os valores de pressão //se está ligado a menos de 5 segundos, exibe tela inicial if (millis() > (5000)) //se está ligado a mais que 5 segundos { //Limpa o buffer do display display.clear(); //ajusta o alinhamento para a esquerda display.setTextAlignment(TEXT_ALIGN_LEFT); //ajusta a fonte para Arial 10 display.setFont(ArialMT_Plain_16); //Escreve no buffer do display a pressao display.drawString(0, 0, String(int(pressao)) + " kPa"); display.drawString(0, 16, String(pressao * fator_atm) + " atm"); display.drawString(0, 32, String(pressao * fator_kgf_cm2) + " kgf/cm2"); //escreve no buffer o valor do ADC display.drawString(0, 48, "adc: " + String(int(medidas))); } else //se está ligado a menos de 5 segundos, exibe a tela inicial { //limpa o buffer do display display.clear(); //Ajusta o alinhamento para centralizado display.setTextAlignment(TEXT_ALIGN_CENTER); //ajusta a fonte para Arial 16 display.setFont(ArialMT_Plain_16); //escreve no buffer display.drawString(64, 0, "Sensor Pressão"); //escreve no buffer display.drawString(64, 18, "Diferencial"); //ajusta a fonte para Arial 10 display.setFont(ArialMT_Plain_10); //escreve no buffer display.drawString(64, 44, "ESP-WiFi-Lora"); } display.display();//transfere o buffer para o display delay(50); }

Source code: Function that calculates the pressure in kPa

float calculaPressao (float medida)
{ //Calcula a pressão com o //valor do AD corrigido pela função corrigeMedida() //Esta função foi escrita de acordo com dados do fabricante //e NÃO LEVA EM CONSIDERAÇÃO OS POSSÍVEIS DESVIOS DO COMPONENTE (erro) return ((corrigeMedida(medida) / 3.3) - 0.04) / 0.0012858; }


Source code: Function that corrects the AD value

float corrigeMedida(float x) {
/* Esta função foi obtida através da relação entre a tensão aplicada no AD e valor lido */ return 4.821224180510e-02 + 1.180826610901e-03 * x + -6.640183463236e-07 * x * x + 5.235532597676e-10 * x * x * x + -2.020362975028e-13 * x * x * x * x + 3.809807883001e-17 * x * x * x * x * x + -2.896158699016e-21 * x * x * x * x * x * x; }

Step 11: Files

Download the files:



Be the First to Share


    • Puzzles Speed Challenge

      Puzzles Speed Challenge
    • "Can't Touch This" Family Contest

      "Can't Touch This" Family Contest
    • CNC Contest 2020

      CNC Contest 2020