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...
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
Thanks all
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..