MPL3115A2 Pressure Sensor Hookup Guide

Pages
Contributors: Nate
Favorited Favorite 0

MPL3115A2 Overview

The MPL3115A2 is a low-cost, low power, highly accurate barometric pressure sensor. Use this sensor to detect changes in barometric pressure (weather changes) or for altitude (UAV controllers and the like). The sensor is very sensitive and capable of detecting a change of only 0.05kPa which equates to a 0.3m change in altitude.

MPL3115A2 pressure sensor breakout board

MPL3115A2 Pressure sensor breakout board

Things you should know about this sensor:

  • Uses the I2C interface
  • Only one sensor can reside on the I2C bus
  • Uses the I2C repeated start condition. Arduino supports this, check if you’re using a different microcontroller.
  • Typical pressure accuracy of ±0.05kPa
  • Typical altitude accuracy of ±0.3m
  • Typical temperature accuracy of ±3C
  • 3.3V sensor - use inline logic level converters or 330 ohm resistors to limit 5V signals
  • Here’s the datasheet
  • Here’s the schematic for the breakout board

This sensor is ideal for environmental sensing, a weather station, or datalogging. It is a worthy replacement for the BMP085 and is more sensitive than the MPL115A1.

Suggested Reading

Hooking It Up

Wiring up the MPL3115A2 pressure sensor is very easy!

Fritzing Diagram

Note: The 330Ω resistors are used in line withe I2C lines since we are using a 5V Arduino to talk to a 3.3V device.

There are only four pins that need to be hooked up in order to start using this sensor in a project. One for VCC, one for GND, and two data lines for I2C communication. You may also use the A4 and A5 pins on older Arduino Boards that do not have SDA and SCL broken out.

Note: This breakout board has built-in 1kΩ pull up resistors for I2C communications. If you’re hooking up multiple I2C devices on the same bus, you may need to disable the other resistors on the bus.

Connections: Breakout board to Arduino

MPL3115A2 → Arduino

  • VCC → 3.3V
  • GND → GND
  • SDA → A4 (or SDA)
  • SCL → A5 (or SCL)

Note: You can also you the SDA and SCL lines on Arduino boards that have them broken out. Make sure you edit the code accordingly if you use those pins instead.

On an Arduino board connect the SDA pin on the breakout board to A4 and SCL to A5. If you’re using a 5V Arduino Uno we recommend putting 330 ohm resistors in line to limit the 5V signal going into the sensor and prevent damage to the sensor.

Using Codebender

To get started immediately here is a Codebender example that uses the MPL3115A2 library. This example will immediately show you current pressure in Pascals.

Once the code is uploaded to your board connect using this serial terminal to see the output.

Click here for an example that coverts pressure from Pascals to inches of mercury, altimeter setting adjusted. This type of pressure reading is used in the USA on Wunderground for home weather stations and aircraft.

Click here for an example that coverts pressure to current altitude in feet (or meters).

Using Arduino IDE

We’ve written an Arduino library and some example code to make using the MPL3115A2 easy to get up and running. Grab the library from the link below.

MPL3115A2 Arduino Library

Unzip and paste the folder “MPL3115A2_Pressure” into your Arduino libraries folder. Not sure how to install an Arduino library? Read here for more information.

Arduino Example Sub Menu

Load the Pressure example

Once the library is installed, open Arduino, and expand the examples menu. You should see the MPL3115A2_Pressure sub-menu. Load the “Pressure” example onto the Arduino. Open the serial terminal at 9600bps. You will see the current barometric pressure and temperature in the room!

Arduino terminal output

Pressure readings!

Explanation of Functions

The library and example code demonstrate the most popular functions supported by the MPL3115A2. Here is an explanation of all the available functions in the library:

  • myPressure.begin() gets sensor on the I2C bus.
  • myPressure.readAltitude() returns a float with meters above sea level. Ex: 1638.94
  • myPressure.readAltitudeFt() returns a float with feet above sea level. Ex: 5376.68
  • myPressure.readPressure() returns a float with barometric pressure in Pa. Ex: 83351.25
  • myPressure.readTemp() returns a float with current temperature in Celsius. Ex: 23.37
  • myPressure.readTempF() returns a float with current temperature in Fahrenheit. Ex: 73.96
  • myPressure.setModeBarometer() puts the sensor into Pascal measurement mode.
  • myPressure.setModeAltimeter() puts the sensor into altimetry mode.
  • myPressure.setModeStandy() puts the sensor into Standby mode. Required when changing CTRL1 register.
  • myPressure.setModeActive() starts taking measurements!
  • myPressure.setOversampleRate(byte) sets the # of samples from 1 to 128. See note below *
  • myPressure.enableEventFlags() sets the fundamental event flags. Required during setup.

When you call the readAltitude, readAltitudeFt, readPressure, or readTemp you will get a float with the sensor reading or an error code:

  • 1638.94 is an example of a valid reading.
  • -999 indicates that I2C timed out (512ms max). Check your connections.

Oversample settings table

Oversample settings

  • setOversampleRate(byte) receives a value from 0 to 7. Check table 59 above. Allows the user to change sample rate from 1 to 128. Increasing the sample rate significantly decreases the noise of each reading but increases the amount of time to capture each reading. A oversample of 128 will decrease noise to 1.5Pa RMS but requires 512ms per reading. The datasheet recommends oversample of 128 for basic applications.

The MPL3115A2 has a large number of features. Checkout the datasheet for more info. This library covers the fundamentals. Help us out! Please add or suggesting more features on the MPL3115A2 github repo.

Pressure vs Altimeter Setting

If you grabbed a few pressure readings and became confused when you checked your local weather conditions, you’re not alone. The absolute pressure that the MPL3115A2 pressure sensor outputs is not the same as what weather stations refer to as pressure. Weather stations report pressure in lots of different units:

  • millimeters Mercury (mmHg)
  • inches Mercury (inHg)
  • millibars or hectopascals (hPa)
  • pounds per square inch
  • atmospheres (Atm)
  • kilogram per centimeter
  • inches of water

In barometer mode, the MPL3115A2 outputs pressure readings in Pascals. This is most closely related to millibars or hectopascals. But, why does the sensor not agree with the station around the corner? This is because many stations report pressure in a few different formats. Have a look at all these numbers for the Boulder/Denver area. The key is that your local weather station is probably reporting the Altimeter setting.

Thank you National Oceanic and Atmospheric Administration (NOAA)! Did you know they’re headquartered here in Boulder, CO?

  • Station pressure - This is the pressure that is observed at a specific elevation and is the true barometric pressure of a location.
  • Altimeter setting - This is the pressure reading most commonly heard in radio and television broadcasts. It is not the true barometric pressure at a station. Instead it is the pressure “reduced” to mean sea level using the temperature profile of the “standard” atmosphere, which is representative of average conditions over the United States at 40 degrees north latitude.
  • Mean sea level pressure - This is the pressure reading most commonly used by meteorologists to track weather systems at the surface. Like the altimeter setting, it is a “reduced” pressure, which uses observed conditions rather than “standard” conditions to remove the effects of elevation from pressure readings.

The calculation to get from Pascals to ‘Altimeter setting’ is a bit gnarly:

Alimeter setting formula

Formula to convert Pascal pressure to Altimeter setting

Grab the full formula here and give this great Altimeter setting calculator a try. This formula relies on two things: knowing the current pressure in milibars and knowing the height above sea level that the pressure was read. We recommend you capture altitude using a local survey point or a GPS receiver.

If you installed the MPL3115A2 library, you should also have the BarometricHgInch example sketch under the Examples->MPL3115A2_Pressure menu under the Arduino IDE. We didn’t build this calculation into the library because it could potentially chew up a lot of RAM and code space calculating all the floating point math. But, if you’re doing home weather station calculations, this should get you started.

Resources and Going Further

Now that you’ve got barometric pressure sensing under your belt, consider checking out the following projects and products: