Go Down

Topic: MPX5700GP pressure sensor (Read 653 times) previous topic - next topic

teutek213

Dec 07, 2017, 09:11 pm Last Edit: Dec 07, 2017, 09:29 pm by teutek213
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 :/

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  ;)  ;)


Wawa

#1
Dec 07, 2017, 11:15 pm Last Edit: Dec 07, 2017, 11:56 pm by 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..
Code: [Select]
// 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.
Code: [Select]
// 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);
}

 

teutek213

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

teutek213

#3
Dec 13, 2017, 07:37 pm Last Edit: Dec 13, 2017, 07:43 pm by teutek213
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

Wawa

#4
Dec 13, 2017, 07:57 pm Last Edit: Dec 13, 2017, 08:02 pm by Wawa
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..

outsider

#5
Dec 13, 2017, 08:10 pm Last Edit: Dec 13, 2017, 08:21 pm by outsider
Leo, in your second sketch, did you forget:
Code: [Select]
rawValue /= 10;
?
Never mind. :-[   I'm in training for the blunder olympics.

Wawa

Never mind. :-[   I'm in training for the blunder olympics.
Haha. Be prepaired for some fierce competition. I'm also joining.
Leo..

teutek213

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


Go Up