Pressure sensor 5v - 3.3v. Am I doing it right?

Hi all! Quick one on a pressure sensor attached to an ESP32. Any help would be appreciated

Need to know if I'm on the right track or missing something

0->174 psi pressure sensor that is powered by 5v and has a range of 0.5v to 4.5v
Using esp32 to power @ 5v and voltage divider on input to esp consisting of a 4.7k and 8.2k giving max voltage at esp of 3.178v if 5v were applied from sensor

This sensor output range equates to 10% to 90%
Taking the esp has a analog range of 4096 and theoretically max @ 5v from sensor we'd see 3280.5 bits
10% to 90% of this is 328.05 - 3280.5 bits

my code

// Function to map using floats

float mapPress(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

pressRaw = analogRead(pressPin);                       // Get analog value
pressure = mapPress(pressRaw, 328.05, 3280.5, 0, 174); // Map it

I'm getting -11 to -13 psi. Could this have something to do with atmospheric pressure? if anything I'd expect it to be more like 14.7 psi...

Can you clarify what this means?

Do you have a link to the datasheet for the sensor?

If 10% is 328.05, then 90% is 2,952.45 (3280.5 being 100%)

Thanks! you are correct! Unfortunately it seems that doesn't bring it to 0 but got closer at around -5. I then re-calculated using the true resistances to get rid of the tolerance and get a little better.

In the end I simply read the raw value and assumed this to be about 0 as no pressure is applied outside of the atmosphere. This should do the trick for what I need :slight_smile:
Thanks all

Your topic has been moved to a more suitable location on the forum.

Basically, a ratiometric (10-90%) 5volt sensor shouldn't be connected to a 3.3volt processor. There is no supply compensation, and you will be rewarded with instability. Get a sensor with I2C output.
Leo..

What does the sensor's datasheet say about the effect of a 12.9k (388µA) load on the sensor's output voltage?
Post the datasheet.

Looks like no datasheet and haven't had luck with the supplier yet

NZ$ 16.02 23%OFF | DC 5V G1/4 Pressure Sensor Transmitter Pressure Transducer 1.2 MPa 174 PSI For Water Gas Air Oil Fuel Car Stainless Steel Switch

What I said before.
You're wasting your time getting a 5volt ratiometric sensor to work reliably on an 3.3volt processor with absolute A/D.

A poor man always buys twice.
Leo..

Hahah. Live and learn! Thanks

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