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.


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 List

Here are the parts I used


Name Links
Wemos Mini
Connecting cables




Wemos mini Sensor
3.3v 3.3v
Gnd Gnd



This uses the library from

[codesyntax lang=”cpp”]

#include <Wire.h>
#include <LPS.h>

LPS ps;

void setup()

  if (!ps.init())
    Serial.println("Failed to autodetect pressure sensor!");
    while (1);


void loop()
  float pressure = ps.readPressureMillibars();
  float altitude = ps.pressureToAltitudeMeters(pressure);
  float temperature = ps.readTemperatureC();
  Serial.print("p: ");
  Serial.print(" mbar\ta: ");
  Serial.print(" m\tt: ");
  Serial.println(" deg C");




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


Please enter your comment!
Please enter your name here