How To Measure Air Pressure with Arduino


CanSatLogoContinuing with our series on CanSat, we discuss how to detect atmospheric pressure using an Arduino Uno R3 and an MPX4115A Pressure Sensor.

ArduinoPressure_schemTo sense atmospheric pressure we’re given an MPX4115A Pressure Sensor.  This comes as a 6 pin package, though only three of the pins are used.  Pin 1 is marked with a notch, and is the sense (Vout) pin, while pin 2 is connected to ground, and pin 3 to Vin.

The datasheet shows that you can calculate pressure using the formula:

Vout = Vin*(0.009*P – 0.095)

Where pressure P is given in kilopascals.  Some arithmetic rearranging can express P in terms of Vin and Vout, which we will use the Arduino to measure.

Our Arduino sketch then becomes,


void setup() {
    Serial.begin(9600);
}

void loop(){
    float pressure = readPressure(A1);
    float millibars = pressure/100;

    Serial.println();
    Serial.print("Pressure = ");
    Serial.print(pressure);
    Serial.println(" pascals");
    Serial.print("Pressure = ");
    Serial.print(millibars);
    Serial.println(" millibars");
    delay(1000);
}

/* Reads pressure from the given pin.
* Returns a value in Pascals
*/
float readPressure(int pin){
    int pressureValue = analogRead(pin);
    float pressure=((pressureValue/1024.0)+0.095)/0.000009;
    return pressure;
}

Once we have pressure calculated, then we can use a formula to estimate our altitude, but we’ll discuss that another day.

Again, I would say this configuration is accurate, though not very sensitive to pressure changes. The limiting factor seems to be the Arduino’s ability to sense changes in voltage. Given that the Arduino uses a analogue to digital converter (ADC) when reading from an analogue pin, we can only get 1024 voltage readings between 0 and 5 volts, giving a difference of 4.8 mV between readings. In order for this to be detected at the at the Arduino, the pressure has to change through approximately 1.085 hPa at the sensor.

Advertisements

Tags: , , , , , , , , , ,

4 responses to “How To Measure Air Pressure with Arduino”

  1. Jim says :

    Hello. Did you mean to type kpa rather than hpa in the last line. Thank you for this work. I’ve found this very useful!

  2. Jim Davids says :

    Hey!

    I was wondering is there anyway to turn the MPX4115A into an Altimeter and combine the code?

    Could you give me the code for it if possible?

    Thank you!

%d bloggers like this: