MPX5700GP pressure sensor

Hello,

i have problem with my gauge pressure sensor

i found 2 different topics with MPX5700GP

https://forum.arduino.cc/index.php?topic=425830.0

https://forum.arduino.cc/index.php?topic=99381.0

an they still didnt solve my problems

maybe sth is with my sensor maybe with code or arduino idk :confused:

im using arduino nano with lcd and LCM1602

there is my code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define BACKLIGHT_PIN 3
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7);

void setup()
{
lcd.begin(16, 2);
lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
lcd.setBacklight(HIGH);
lcd.home();

lcd.print(‚ÄúVoltage‚ÄĚ);
lcd.setCursor (0, 1);
lcd.print(‚ÄúPressure‚ÄĚ);
}

void loop()
{
// averaging for noise removal
float sensorValue = analogRead(A0);
float voltage = 5000.0 * sensorValue * (1.0/1024.0); // mV
float pressure = ((((voltage / 5) - 0.04) / 0.0012858)/1000.0) ; // kPa
lcd.setCursor (10,0);
lcd.print(voltage);
delay(500);
lcd.setCursor (10,1);
lcd.print(pressure);
delay(500);

}

in attachments there is data sheet for this sensor

after vcc connection on display
i can see

voltage 258.79 (in mV)
and pressure 40.22 (and this in kPa)

this valuse sometimes are softly lower or higher but those are slight changes
so for me it is big offset of valid value

thank you in advance for any help :wink: :wink:

MPX5700-1127047.pdf (199 KB)

Not a good idea to see a pressure sensor as a voltmeter. Your code assumes a 5.000volt supply, but a Nano on USB power is more like 4.6volt. Sensors like this are ratiometric, and you should convert directly from A/D value to pressure.

Try this example. I already calculated the offset and span for this MPX5700, but it might need finetuning.

Don't expect that a pressure sensor and 10-bit A/D (1024 values) can display 700 with two decimal places precision. Leo..

// MPX5700 pressure sensor (700kPa)

int rawValue; // A/D readings
int offset = 41; // zero pressure adjust
int fullScale = 963; // max pressure (span) adjust
float pressure; // final pressure

void setup() {
  Serial.begin(9600);
}

void loop() {
  rawValue = analogRead(A0);
  pressure = (rawValue - offset) * 700.0 / (fullScale - offset); // pressure conversion

  Serial.print("Raw A/D is  ");
  Serial.print(rawValue);
  Serial.print("   Pressure is  ");
  Serial.print(pressure, 1); // one decimal places
  Serial.println("  kPa");
  delay(500);
}

Or, with a bit of averaging for a more stable readout and better offset adjustment.

// MPX5700 pressure sensor (700kPa)

int rawValue; // A/D readings
int offset = 410; // zero pressure adjust
int fullScale = 9630; // max pressure (span) adjust
float pressure; // final pressure

void setup() {
  Serial.begin(9600);
}

void loop() {
  rawValue = 0;
  for (int x = 0; x < 10; x++) rawValue = rawValue + analogRead(A0);
  pressure = (rawValue - offset) * 700.0 / (fullScale - offset); // pressure conversion

  Serial.print("Raw A/D is  ");
  Serial.print(rawValue);
  Serial.print("   Pressure is  ");
  Serial.print(pressure, 1); // one decimal places
  Serial.println("  kPa");
  delay(500);
}

Hi Leo,

i used your second code and there is a little better read because i get :

Raw A/D is 573 Pressure is 12.4 kPa Raw A/D is 576 Pressure is 12.6 kPa Raw A/D is 575 Pressure is 12.5 kPa Raw A/D is 573 Pressure is 12.4 kPa

this value still didnt content me :/

but i dont have more ideas :(

thank you for help

maybe now with this readings you can help more

I found

page with other MPX5100gp which pressure range is 100kPa

and scale is from 0.2 to 4.7 V the same like mine sensor

https://circuits4you.com/2016/05/13/arduino-pressure-measurement/

i used their code

/* Air Pressure Measurement usning MPX5010 or MPX5100 Pressure Sensor www.circuits4you.com */

const float SensorOffset = 102.4; // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); }

// the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0: float sensorValue = (analogRead(A0)-SensorOffset)/700.0; //Do maths for calibration // print out the value you read: Serial.print("Analog Read "); Serial.print(analogRead(A0)); Serial.print('\n'); Serial.print("Air Pressure: "); Serial.print(sensorValue,1); Serial.println(" kPa");

delay(1000); // delay in between reads for stability }

and i get

Analog Read 63 Air Pressure: -0.1 kPa Analog Read 63 Air Pressure: -0.1 kPa

thats are better readings but id dont know that this is valid code

thank for your help

Mateusz

Edit: Stop using other sketches. The second sketch in post#1 works perfectly after calibrating.

Are these values without any pressure on the sensor? Did you read the comments of the sketch? You need to adjust some of the values for YOUR sensor/setup.

1) remove the hoses from the sensor, and change the offset value (and re-upload the sketch) until the serial monitor is as close to zero as possible. This is the "410" value if you use the second (better) sketch. Do it in small steps, e.g. 400 or 395, or 420 or 425.

2) You can skip this part, but if you have the means of calibrating the sensor then: Connect the hoses again, and put a known pressure on the sensor. Adjust the max pressure(span) value (and re-upload every time), until the value on the serial monitor shows the same value as the known pressure. Leo..

Leo, in your second sketch, did you forget:

rawValue /= 10;

? Never mind. :-[ I'm in training for the blunder olympics.

outsider: Never mind. :-[ I'm in training for the blunder olympics.

Haha. Be prepaired for some fierce competition. I'm also joining. Leo..

Hi Leo

i used arduino uno as 5v power supply and it works quite good

i get:

Raw A/D is 420 Pressure is 0.8 kPa Raw A/D is 420 Pressure is 0.8 kPa Raw A/D is 418 Pressure is 0.6 kPa

for me sounds perfect <3

thank you a lot

// MPX5700 pressure sensor (700kPa)

int rawValue; // A/D readings int offset = 410; // zero pressure adjust int fullScale = 9630; // max pressure (span) adjust float pressure; // final pressure

void setup() { Serial.begin(9600); }

void loop() { rawValue = 0; for (int x = 0; x < 10; x++) rawValue = rawValue + analogRead(A0); pressure = (rawValue - offset) * 700.0 / (fullScale - offset); // pressure conversion

Serial.print("Raw A/D is "); Serial.print(rawValue); Serial.print(" Pressure is "); Serial.print(pressure, 1); // one decimal places Serial.println(" kPa"); delay(500); }

code for future searcher :)

Mateusz

25434275_1752890268117823_2101840827_o.jpg|1152x2048

Hi, Leo

i see your sketch regard this quote in below, i have question how to measure " int fullScale = 963;// max pressure (span) adjust " another sensor and we know this value as per your sketch, maybe have Technic? please advice me

regard's /kangmus

Wawa: Not a good idea to see a pressure sensor as a voltmeter. Your code assumes a 5.000volt supply, but a Nano on USB power is more like 4.6volt. Sensors like this are ratiometric, and you should convert directly from A/D value to pressure.

Try this example. I already calculated the offset and span for this MPX5700, but it might need finetuning.

Don't expect that a pressure sensor and 10-bit A/D (1024 values) can display 700 with two decimal places precision. Leo..

// MPX5700 pressure sensor (700kPa)

int rawValue; // A/D readings int offset = 41; // zero pressure adjust int fullScale = 963; // max pressure (span) adjust float pressure; // final pressure

void setup() {  Serial.begin(9600); }

void loop() {  rawValue = analogRead(A0);  pressure = (rawValue - offset) * 700.0 / (fullScale - offset); // pressure conversion

 Serial.print("Raw A/D is  ");  Serial.print(rawValue);  Serial.print("   Pressure is  ");  Serial.print(pressure, 1); // one decimal places  Serial.println("  kPa");  delay(500); }



Or, with a bit of averaging for a more stable readout and better offset adjustment.


// MPX5700 pressure sensor (700kPa)

int rawValue; // A/D readings int offset = 410; // zero pressure adjust int fullScale = 9630; // max pressure (span) adjust float pressure; // final pressure

void setup() {  Serial.begin(9600); }

void loop() {  rawValue = 0;  for (int x = 0; x < 10; x++) rawValue = rawValue + analogRead(A0);  pressure = (rawValue - offset) * 700.0 / (fullScale - offset); // pressure conversion

 Serial.print("Raw A/D is  ");  Serial.print(rawValue);  Serial.print("   Pressure is  ");  Serial.print(pressure, 1); // one decimal places  Serial.println("  kPa");  delay(500); }

Not sure what your question is.

'963' is calculated from the sensor's datasheet, for a 10-bit A/D (most Arduinos).

Full Scale Output: 4.7volt/5volt = 0.94 * 1024 = ~963.

If you need higher precision, and have the gear to calibrate, then see what raw A/D value you get with a pressure of 700kPa. Zero pressure is easier. Just see what raw values you getting without any pressure. Should be about 41. If different, then change that value. Leo..

this aswer i want to know from you.

thanks for your reply