pressure sensor MPX4115

Hello

I got a MPX4115 pressure sensor and I tried to get it working with the Arduino. But as I try to calculate the pressure it does gave me strange results.

I just plugged the Vout to +5V GND to Ground and Vs to the AnalogPin 0

int x;

void setup()
{
Serial.begin(9600);
}
void loop()
{
x=analogRead(0);
Serial.println(x);
delay(100);
}

Has someone experience with those sensors or have I done a big mistake?

Thx Geko

This is pretty much exactly the code I have for the 6115 sensor, and it seems to work fine.

What do your results look like, and what did you expect?

Realize that you have to apply a function to convert from voltage to pressure (and there's another function to convert from that integer to a floating point voltage).

-j

Hi kg4wsv

Thx for your reply. Yes I do know that I have to use a formula.
I always get the value 1023 and this seems to my quite wrong :slight_smile:

What do you mean by this
“(and there’s another function to convert from that integer to a floating point voltage).”

Here what’s written in the data sheet:

Nominal Transfer Value:
Vout = VS x (0.009 x P – 0.095)
± (Pressure Error x Temp. Factor x 0.009 x VS)
VS = 5.1 ± 0.25 Vdc

Thx
Geko

I just plugged the Vout to +5V GND to Ground and Vs to the AnalogPin 0

Vs should be connected to +5v, Vout to the analog pin

Yeah of course I just worte it wrong....

So the formula would be P=((Vout/Vin)+0.095)/0.009 Vout = 783 Vin = 5v

I do get values for P around 1653...

Thx Geko

If you have a multimeter, can you measure the voltage on the analog pin (Vout). A reading of 1023 implies 5 volts and if that's what you are getting then the sensor may not be wired correctly or the sensor is faulty

What do you mean by this "(and there's another function to convert from that integer to a floating point voltage)."

The ADC returns an integer from 0 to 1023, representing values from 0 to 5V (assuming you haven't added an external analog reference), so each integer from analogRead() represents ~4.88mV. To get Vin, you need the following conversion:

float Vin;
Vin = (5.0/1024.0) * analogRead(0);

Also, be careful of rounding when evaluating integers - it can lead to unexpected results.

-j

Thx!

I do get now pressures around 957 and this could be right I have to test this somewhere...

PS: With the formula P=((Vout/5.0)+0.095)/0.009 I just got 95.7 but I do think I have to multily it by 10... or not?

Thx Geko

That should be right; I don’t know why you think you may need to multiply by 10?

If you’re in the US, a local airport will have the pressure, as will the National Weather Service web site, although you may have to convert units.

-j

Because of the units. At our airport the pressure are 965.5 hPa and not like the Arduino 95.7 so it's more like 957 do you understand my "problem"?

Thx Geko

I understand now, but I sure don't see the cause...

-j

I realise that this is an old post now, but, just got one of these to make my own weather station.

In regards to your readings being out by a factor of 10, the datasheet states that the formula is for calculating kPa, not hPa, so that's why it's out by a factor of ten.

The formula can be simplified a little for the Arduino too. As the 'Vout/Vs' part is just a ratio, you don't need to calculate the actual voltage. This saves a few steps in the calculation and will reduce the error too.

Also, as you might not be supplying exactly 5v to the sensor, working the whole thing out as a voltage probably won't be totally accurate, where as 'analogRead/1024' will always give you the right ratio.

So, to work out the pressure in hPa, or millibars as we call them in the UK, and get the most accurate reading use:

P= ((analogRead(0)/1024)+ 0.095)/0.0009

Regards, The Cageybee

(Updated the formula. Took away a zero from the final division when I should have added one)

Ok, just had a go with this sensor, first time.

I was getting some bizzare results that bore no resembalence to the hand calculated figures.

I was using a float as the pressures data type and didn’t realise that you have to follow any whole numbers with a ‘.0’.

So, with,

pressure = (analogRead(0)/1024**.0** + 0.095 ) / 0.0009;

everything works as expected. Yay.

Regards,
The Cageybee

I did a blog entry about this a while ago:

http://pwillard.com/?p=31

I remember fussing a lot with floats… before they made some nice changes in recent ARDUINO IDE versions.

Hi there pwillard.

Noticed from your blog your working out as a voltage. Doing it like that is likely to lead to error. The more calculations you do, the more error will creep in.

Also, as the voltage being presented to the Vs pin is likely to fluctuate to some degree, even more so if being supplied by a battery, working it out as a voltage will increase the error.

If you work it out as 'analogRead(0)/1024', it doesn't matter what the voltage at Vs is, your analogRead value will always be at the correct proportion. Do you see what I mean?

I noticed you're using the suggested caps. I was a little worried about not using them as I thought I'd be getting reading going all over the place. As it turns out, it's rock solid without them. They're nice sensors I've got to say, but then they should be for the price.

Regards, The Cageybee

I am using an external 5V supply and have not noticed any instability. I guess I’m lucky.