Trying to use the MPL3115A2 temperature and pressure sensor from sparkfun with arduino. I successfully wired it all to the arduino and ran the first example. However, the altitude that it is reading is 82,600 feet and fluctuates without me moving the sensor. My current elevation is 13 feet below sea level. Can anyone help???

here is the code i am using

#include <Wire.h>
#include “SparkFunMPL3115A2.h”

//Create an instance of the object
MPL3115A2 myPressure;

void setup()
Wire.begin(); // Join i2c bus
Serial.begin(9600); // Start serial for output

myPressure.begin(); // Get sensor online

// Configure the sensor
myPressure.setModeAltimeter(); // Measure altitude above sea level in meters
myPressure.setModeBarometer(); // Measure pressure in Pascals from 20 to 110 kPa

myPressure.setOversampleRate(7); // Set Oversample to the recommended 128
myPressure.enableEventFlags(); // Enable all three pressure and temp event flags

void loop()
float altitude = myPressure.readAltitude();
Serial.print(altitude, 2);

altitude = myPressure.readAltitudeFt();
Serial.print(" Altitude(ft):");
Serial.print(altitude, 2);

float pressure = myPressure.readPressure();
Serial.print(" Pressure¶:");
Serial.print(pressure, 2);

float temperaturec = myPressure.readTemp();
Serial.print(" Temp(c):");
Serial.print(temperaturec, 2);

float temperature = myPressure.readTempF();
Serial.print(" Temp(f):");
Serial.print(temperature, 2);


I don't know that specific sensor but altitude measurements always need a reference pressure. This references pressure changes by weather conditions and has to be provided to calculate the absolute altitude. I cannot see any code in your sketch where you provide that information. So you probably have to use that value to get a difference to a value read shortly before that. So measure the value at sea level, lift the sensor, read again and subtract the previous value: you get the absolute altitude.