Mpx 5700 ap esp 32

Hello everyone, i have a problem with my sensor or with my code idk, because the result for the sensor is 3.6V in the beginning, i dont give any pressure, anyone can help me please (my english so bad, sorry)

i use this code
<
float rawADC;
float sensorValue;
float pressureValue;

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

void loop()
{
rawADC = analogRead(36); // raw data
sensorValue = (rawADC * 5.0) / 1023.0; // raw data convert to volt
pressureValue = (sensorValue - 0.2) / 4.5 * 700.0; // sensor-offset = 0.2V, voltage range = 4.5V, pressure range = 700kPa, pressure = mV/kPa

// print out the value you read:
Serial.print("Raw value:");
Serial.println(rawADC);

Serial.print("Sensor value:");
Serial.print(sensorValue);
Serial.println ("V");

Serial.print("Air pressure: ");
Serial.print(pressureValue);
Serial.println(" kPa");

delay (1000);
}

and this is the result

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Which library is being used to read the sensor?

post a image of your setup.

you know the sensor is an I2C device?

The search box of this site may be helpful,

usin the words "mpx5700"

hello sir, i dont use any library for this sensor
and this is my setup


what do u mean about the sensor is i2c device sir?

I see that you chose to ignore the advice in the link that I posted in reply #2 and decided not to use code tags when posting code

float rawADC;
float sensorValue;
float pressureValue;

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

void loop()
{
rawADC = analogRead(36); // raw data
sensorValue = (rawADC * 5.0) / 1023.0; // raw data convert to volt
pressureValue = (sensorValue - 0.2) / 4.5 * 700.0; // sensor-offset = 0.2V, voltage range = 4.5V, pressure range = 700kPa, pressure = mV/kPa

// print out the value you read:
Serial.print("Raw value:");
Serial.println(rawADC);

Serial.print("Sensor value:");
Serial.print(sensorValue);
Serial.println ("V");

Serial.print("Air pressure: ");
Serial.print(pressureValue);
Serial.println(" kPa");

delay (1000);
}

The MPX5700 is a ratiometric 5volt-logic only sensor.
You might get it working with a 3.3volt-logic ESP32, but you can never get it right (stable).
Change to a sensor with I2C output.
Leo..

Thanks leo, but how to connect a sensor to i2c? Because i am still learning this sensor

i am using 5v from arduino nano and the result still same sir, can u help me sir?

The MPX5700 is a ratiometric sensor, meaning it's output voltage not only depends on pressure, but also on it's supply voltage. You should code in ratios and A/D values, not in voltages.

This sensor can work with a classic Nano (5volt logic), but not with the newer 3.3volt Nanos.

Copied/corrected from a previous thread I wrote:
If you read the datasheet of the MPX5700, then you find a typical output voltage range of 0.2volt (no pressure) to 4.7volt (full pressure). That should actually be converted to a percentage for the ratiometric A/D of an Arduino, so typical sensor output range is 4% to 94% of VCC.

That translates to an offset of 4% of 1024 = 41,
and a fullScale of 96% of 1024 = 983.

It seems you want to display in kPA.

declare

int offset = 41; // adjust for zero kPa
int fullScale = 983; // adjust for accurate top scale readout if... you have a calibration instrument
float pressure;

and in loop

pressure = (analogRead(A0) - offset) * 700.0 / (fullScale - offset); // in kPa
Serial.print(pressure);

Build your code around that.
Leo..

Edit: You only have 983 - 41 = 942 A/D values for that 700kPa range,
so don't expect meaningful decimal places.
You can use
Serial.print(pressure, 1); // display one decimal place

thanks leo, for the code, I followed your instructions but it's still the same, I've tried with nano and the results are different from using esp, with the same power supply, but the results are also not satisfactory

Post your full code, and a picture of the setup.
Describe the exact problems you're having.
Leo..

float 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(27);
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(1000);*/
  String command = "t3.txt=\"" + String(rawValue) + "\"";
  Serial.print(command);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  delay(1000);
  String command1 = "t4.txt=\"" + String(pressure) + "\"";
  Serial.print(command1);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  delay (1000);
}

i am using nextion for the display sir

T3 is rawValue
T4 is pressure

So you didn't use a Nano.
Leo..

yes i am using a esp for the project, but i try use a nano too and the result still same

the problem is results obtained directly to the pressure of 400, how to get it back to 0?

Try to test the sensor on it's own.
With it's output not connected to the Nano or ESP.

Only connect it to 5volt and ground (from the Nano),
and measure it's output with a voltmeter (assuming you have one).
It should be about 0.2volt without pressure.
Leo..


I follow your instructions, but the result is not 0.2, the result is 0.8V sir

No pressure voltage of an MPX5700 should be between 0volt and 0.4volt.
Is this a new sensor from a trusted place.
Does voltage increase with pressure.
Try a bicycle pump (it's a 7bar sensor).
Leo..

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.