Microbit and LPS25H piezoresistive pressure sensor example

In this article we look at a pressure sensor – this time its the LPS25H and we will connect to our Microbit and see what it can do

This is the sensor that I used

Lets see what the manufacturer says about the sensor

The LPS25H 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 of detecting pressure and is manufactured using a dedicated process developed by ST.

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.

The LPS25H is available in a cavity holed LGA package (HLGA). It is guaranteed to operate over a temperature range extending from -30 °C to +105 °C. The package is holed to allow external pressure to reach the sensing element.

Features

260 to 1260 mbar absolute pressure range
High-resolution mode: 1 Pa RMS
Low power consumption
Low-resolution mode: 4 μA
High-resolution mode: 25 μA
High overpressure capability: 20x full scale
Embedded temperature compensation
Embedded 24-bit ADC
Selectable ODR from 1 Hz to 25 Hz
SPI and I²C interfaces
Supply voltage: 1.7 to 3.6 V
High shock survivability: 10,000 g

 

Parts Required

 

Name Link
Microbit BBC Micro:bit Micro-Controller with Motion Detection, Compass, LED Display and Bluetooth
LPS25H Diybigworld LPS25HTR ST CJMCU-25 Miniature high Precision Pressure Sensor Temperature Compensation
Connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire
expansion board Microbit expansion board

Schematic/Connection

 

Microbit Sensor
3v3 3v3
Gnd Gnd
SDA – 20 SDA
SCL – 19 SCL

Code Example

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

This is the Serialmetric example

#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: 1015.95 mbar a: -22.49 m t: 22.00 deg C
p: 1016.00 mbar a: -22.84 m t: 22.01 deg C
p: 1016.11 mbar a: -23.80 m t: 22.01 deg C
p: 1016.16 mbar a: -24.21 m t: 22.04 deg C
p: 1016.04 mbar a: -23.18 m t: 22.08 deg C
p: 1016.06 mbar a: -23.35 m t: 22.14 deg C
p: 1016.00 mbar a: -22.84 m t: 22.24 deg C
p: 1015.97 mbar a: -22.65 m t: 22.36 deg C

 

Links

https://www.st.com/resource/en/datasheet/lps25h.pdf