loading

The MPL3115A2 employs a MEMS pressure sensor with an I2C interface to provide accurate Pressure/Altitude and Temperature data. The sensor outputs are digitized by a high resolution 24-bit ADC. Internal processing removes compensation tasks from the host MCU system. It is capable of detecting a change in only 0.05 kPa which equates to a 0.3m change in altitude. Here is its demonstration with Arduino Nano.

Step 1: What You Need..!!

1. Arduino Nano

2. MPL3115A2

LINK : https://www.controleverything.com/content/Analog-Digital-Converters?sku=MPL3115A2_I2CS

3. I²C Cable

LINK : https://www.controleverything.com/content/I2C-Cables?sku=I2CAFF3

4. I²C Shield for Arduino Nano

LINK : https://www.controleverything.com/content/I2C-Master?sku=ANI2C

Step 2: Connections:

Take an I2C shield for Arduino Nano and gently push it over the pins of Nano.

Then connect the one end of I2C cable to MPL3115A2 sensor and the other end to the I2C shield.

Connections are shown in the picture above.

Step 3: Code:

The arduino code for MPL3115A2 can be downloaded from our github repository-ControlEverythingCommunity

Here is the link for the same :

https://github.com/ControlEverythingCommunity/MPL3...

The datasheet of MPL3115A2 can be found here:

https://s3.amazonaws.com/controleverything.media/c...

We include library Wire.h to facilitate the I2c communication of the sensor with the Arduino board.

You can also copy the code from here, it is given as follows:

// Distributed with a free-will license.

// Use it any way you want, profit or free, provided it fits in the licenses of its associated works.

// MPL3115A2

// This code is designed to work with the MPL3115A2_I2CS I2C Mini Module available from ControlEverything.com.

// https://www.controleverything.com/content/Analog-...

#include<Wire.h>

// MPL3115A2 I2C address is 0x60(96)

#define Addr 0x60

void setup()

{

// Initialise I2C communication

Wire.begin();

// Initialise Serial Communication, set baud rate = 9600

Serial.begin(9600);

// Start I2C transmission

Wire.beginTransmission(Addr);

// Select control register

Wire.write(0x26);

// Active mode, OSR = 128, altimeter mode

Wire.write(0xB9);

// Stop I2C transmission

Wire.endTransmission();

// Start I2C transmission

Wire.beginTransmission(Addr);

// Select data configuration register

Wire.write(0x13);

// Data ready event enabled for altitude, pressure, temperature

Wire.write(0x07);

// Stop I2C transmission

Wire.endTransmission();

delay(300);

}

void loop()

{

unsigned int data[6];

// Start I2C transmission

Wire.beginTransmission(Addr);

// Select control register

Wire.write(0x26);

// Active mode, OSR = 128, altimeter mode

Wire.write(0xB9);

// Stop I2C transmission

Wire.endTransmission();

delay(1000);

// Start I2C transmission

Wire.beginTransmission(Addr);

// Select data register

Wire.write(0x00);

// Stop I2C transmission

Wire.endTransmission();

// Request 6 bytes of data

Wire.requestFrom(Addr, 6);

// Read 6 bytes of data from address 0x00(00)

// status, tHeight msb1, tHeight msb, tHeight lsb, temp msb, temp lsb

if (Wire.available() == 6)

{

data[0] = Wire.read();

data[1] = Wire.read();

data[2] = Wire.read();

data[3] = Wire.read();

data[4] = Wire.read();

data[5] = Wire.read();

}

// Convert the data to 20-bits

int tHeight = (((long)(data[1] * (long)65536) + (data[2] * 256) + (data[3] & 0xF0)) / 16);

int temp = ((data[4] * 256) + (data[5] & 0xF0)) / 16;

float altitude = tHeight / 16.0;

float cTemp = (temp / 16.0);

float fTemp = cTemp * 1.8 + 32;

// Start I2C transmission

Wire.beginTransmission(Addr);

// Select control register

Wire.write(0x26);

// Active mode, OSR = 128, barometer mode

Wire.write(0x39);

// Stop I2C transmission

Wire.endTransmission();

delay(1000);

// Start I2C transmission

Wire.beginTransmission(Addr);

// Select data register

Wire.write(0x00);

// Stop I2C transmission

Wire.endTransmission();

// Request 4 bytes of data

Wire.requestFrom(Addr, 4);

// Read 4 bytes of data

// status, pres msb1, pres msb, pres lsb

if (Wire.available() == 4)

{

data[0] = Wire.read();

data[1] = Wire.read();

data[2] = Wire.read();

data[3] = Wire.read();

}

// Convert the data to 20-bits

long pres = (((long)data[1] * (long)65536) + (data[2] * 256) + (data[3] & 0xF0)) / 16;

float pressure = (pres / 4.0) / 1000.0;

// Output data to serial monitor

Serial.print("Altitude : ");

Serial.print(altitude);

Serial.println(" m");

Serial.print("Pressure : ");

Serial.print(pressure);

Serial.println(" kPa");

Serial.print("Temperature in Celsius : ");

Serial.print(cTemp);

Serial.println(" C");

Serial.print("Temperature in Fahrenheit : ");

Serial.print(fTemp);

Serial.println(" F");

delay(500);

}

Step 4: Applications:

Various applications of MPL3115A2 includes High Accuracy Altimetry, Smartphones/Tablets, Personal Electronics Altimetry etc. It can also be incorporated in GPS Dead Reckoning, GPS Enhancement for Emergency Services, Map Assist, Navigation as well as Weather Station Equipment.

About This Instructable

484views

1favorite

More by Dcube Tech Ventures:Home Automation with Raspberry Pi using Relay board Motion Control with Raspberry Pi and LIS3DHTR, 3-Axis Accelerometer, using Python 3-Axis Accelerometer, ADXL345 with Raspberry Pi using Python 
Add instructable to: