My pressure sensor reading results are wrong

MPS20N0040D Barometric Pressure sensor displays a negative number result even though the sensor has not been applied pressure. is there a problem in my code or is my sensor problematic. for the module on this sensor HX710B, and the library that I use is HX710B-base_pressure_sensor.
library from roland pelayo

please help those of you who can solve my problem

#include "HX710B.h"

const int DOUT_Pin = D2;   // Pin data sensor
const int SCLK_Pin = D3;   // Pin clock sensor

HX710B pressure_sensor; 
void setup() {
  Serial.begin(9600);
  pressure_sensor.begin(DOUT_Pin, SCLK_Pin, 128);  // Gunakan faktor penguatan default 128

}

void loop() {
  if (pressure_sensor.is_ready()) {
    Serial.print("Pascal: ");
    Serial.println(pressure_sensor.pascal());
    // Di sini Anda bisa melakukan sesuatu dengan data yang diperoleh dari sensor
  } else {
    Serial.println("Pressure sensor not found.");
  }
  delay(3000);
}


Sorry... I read the wrong library.

Are you certain your above lines are correct? The HX710B.h library example I read had this to create the object:

HX710B air_press(SCK_PIN, SDI_PIN);
.
.
if ( !air_press.init() )

If you apply pressure, readings are changing?
Why don't you use example sketch from Pelayos library?

1 Like

D2,D3 suggests that you're not using an Uno.
So which Arduino are you using.

These cheap sensors have a large offset and temp drift.
You can calibrate the offset with an extra line at the end of setup().

pressure_sensor.set_offset(-7538000L);

My sensor needed -7538000L to get near zero Pascal without pressure.
Leo..

The code is from the sample library. but I changed it a little because it was problematic when compiling the code, when I applied pressure, the sensor reading changed or read

i don't use arduino but i use nodemcu esp8266

I believe what you are seeing is a zero offset error in the sensor. If this sensor is the one that has a range of 0 to 40kPa then 45 Pa is in the order of 0.1% error. Basically no error.

Also know a reading of 0 is difficult for many sensors due to the change in direction of the force.

Did you try:

Serial.println(pressure_sensor.pascal() + 43.83);

?

That's a 3.3volt-logic processor, so you should power the sensor from the 3.3volt pin of the ESP.

The line of code I gave you over-writes the offset that is already used in the library.
You can find it in line28 of the HX710B.h file (-540000).
Leo..

Exactly.
When we pick a sensor we should stop for a minute and try to understand how that specific sensor is working, what is the range that it can measure an so on. If this sensor has a range of 0-40000Pa, I'm sure it's not built to measure changes in 0-40Pa range, but fine to sense difference between 10kPa and 11kPa. Also the output is really just a number that we want it rappresentate, maybe you want this sensor to output 0 when no external load, or maybe 101kPa, the atmospheric pressure.

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