Page 1 of 1

Pressure Sensor

Posted: Thu Jun 06, 2019 3:07 pm
by Jeroem
Hello Everyone,

I am using a pressure sensor like this:"
https://www.banggood.com/200PSI-Pressur ... 20789.html

I followed this youtube guide: https://www.youtube.com/watch?v=AB7zgnfkEi4

The mcu I am using is a ESP32. The sensors gets 4.75volt power and the ESP32 gets 3.3v
The sensors read out fine but the results are very unstable.
Analog value - voltage - pascal - bar:

384 - 0.47 - -3750.00 - -0.00
362 - 0.44 - -84316.41 - -0.08
400 - 0.49 - 54843.75 - 0.05
396 - 0.48 - 40195.31 - 0.04
384 - 0.47 - -3750.00 - -0.00
368 - 0.45 - -62343.75 - -0.06
416 - 0.51 - 113437.50 - 0.11
352 - 0.43 - -120937.50 - -0.12
376 - 0.46 - -33046.87 - -0.03
480 - 0.59 - 347812.50 - 0.35
368 - 0.45 - -62343.75 - -0.06
368 - 0.45 - -62343.75 - -0.06
384 - 0.47 - -3750.00 - -0.00
361 - 0.44 - -87978.52 - -0.09
365 - 0.45 - -73330.08 - -0.07
400 - 0.49 - 54843.75 - 0.05


This is in my room, so 0.47 voltage seems to be the best result, 0.00.
But when I blow in the pressure sensor the voltage goes up and so does the bar.
I don't know what I do wrong but would like to fix the unstable results.

Does anyone have an idea what could go wrong?
This is the code:

Code: Select all

float getSensorvalue(int analoge){
  int sensorVal=analogRead(analoge);
  Serial.print(sensorVal);Serial.print(" - ");

  float voltage = (sensorVal*5.0)/4096.0;
  Serial.print(voltage);Serial.print(" - ");

  float pressure_pascal = (3.0*((float)voltage-0.47))*1000000.0;
  Serial.print(pressure_pascal);Serial.print(" - ");
  float pressure_bar = pressure_pascal/10e5;
  Serial.println(pressure_bar);
  
  delay(100);
  return pressure_bar;
}

void loop(){
	getSensorvalue(34);
	getSensorvalue(35);
	getSensorvalue(32);
	delay(1000);
}
Thanks everyone.

Re: Pressure Sensor

Posted: Thu Jun 06, 2019 3:34 pm
by portasynthinca3
I think the reason with the unstable value is the ADC noise. To overcome this, you can use multisampling. Instead of doing calculations on one value, use an average of several ADC readings, or even better, use a low-pass filter. Here's a code for the simple averaging:

Code: Select all

int adc_value_final = 0;
int adc_samples = 64;
for(int i = 0; i < adc_samples; i++){
  adc_value_final += analogRead(analog_pin);
}
adc_value_final /= adc_samples;
//...and do pressure calculations using adc_value_final variable instead of analogRead()

Re: Pressure Sensor

Posted: Mon Jul 13, 2020 1:59 am
by salvim
Hello Jeroem, how are you? Have you made any progress in using this pressure sensor?