ESP8266 and LPS331AP pressure sensor example

In this article we look at the LPS331AP pressure sensor and as usual we connect it to a Wemos Mini and the example will be using the Arduino IDE

Lets look at this sensor – manufacturers info

The LPS331AP is an ultra compact absolute piezoresistive pressure sensor. It includes a monolithic sensing element and an IC interface able to take the information from the sensing element and to provide a digital signal to the external world.

The sensing element consists of a suspended membrane realized inside a single mono-silicon substrate. It is capable to detecting pressure and is manufactured using a dedicated process developed by ST, called VENSENS.

The VENSENS process allows to build a monosilicon membrane above an air cavity with controlled gap and defined pressure. The membrane is very small compared to the traditionally built silicon micromachined membranes. Membrane breakage is prevented by an intrinsic mechanical stopper.

The IC interface is manufactured using a standard CMOS process that allows a high level of integration to design a dedicated circuit which is trimmed to better match the sensing element characteristics.

Features

260 to 1260 mbar absolute pressure range
High-resolution mode: 0.020 mbar RMS
Low power consumption:
– Low resolution mode: 5.5 µA
– High resolution mode: 30 µA
High overpressure capability: 20x full scale
Embedded temperature compensation
Embedded 24-bit ADC
Selectable ODR from 1 Hz to 25 Hz
SPI and I2C interfaces
Supply voltage: 1.71 to 3.6 V
High shock survivability: 10,000 g

This was the sensor that I bought, link below

Parts

The base shield is optional, I connect my Wemos mini to that and the sensor to the spare socket

Name Link
Wemos Mini WeMos D1 mini
lps331ap LPS331AP Precision Atmospheric Pressure Module
Connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire
Base shield Double Socket Dual Base Shield for Wemos D1 Mini

Connection

 

Wemos mini Sensor
3.3v 3.3v
Gnd Gnd
SDA (D2) SDA
SCL (D1) SCL

 

Code

This uses the library from https://github.com/pololu/lps-arduino

#include <Wire.h>
#include <LPS.h>
 
LPS ps;
 
void setup()
{
  Serial.begin(9600);
  Wire.begin();
 
  if (!ps.init())
  {
    Serial.println("Failed to autodetect pressure sensor!");
    while (1);
  }
 
  ps.enableDefault();
}
 
void loop()
{
  float pressure = ps.readPressureMillibars();
  float altitude = ps.pressureToAltitudeMeters(pressure);
  float temperature = ps.readTemperatureC();
 
  Serial.print("p: ");
  Serial.print(pressure);
  Serial.print(" mbar\ta: ");
  Serial.print(altitude);
  Serial.print(" m\tt: ");
  Serial.print(temperature);
  Serial.println(" deg C");
 
  delay(100);
}

Output

Open the serial monitor and you should see something like this

p: 1028.24 mbar a: -124.04 m t: 22.23 deg C
p: 1028.09 mbar a: -122.79 m t: 22.21 deg C
p: 1028.27 mbar a: -124.32 m t: 22.26 deg C
p: 1028.18 mbar a: -123.55 m t: 22.27 deg C
p: 1028.27 mbar a: -124.32 m t: 22.31 deg C
p: 1028.10 mbar a: -122.89 m t: 22.28 deg C

LEAVE A REPLY

Please enter your comment!
Please enter your name here

*