Contents

Interfacing LPS331AP Pressure / Altitude Sensor with Arduino

LPS331AP Pressure/Altitude Module Features

This small board has an LPS331AP pressure sensor or barometer. The communication protocol of this module is I2C and SPI. In addition to measuring pressure and altitude, this module can also measure temperature.

LPS331AP Sensor Pinout

This sensor has 9 pins. 4 pin are more useful:

  • +5V: Module power supply – 5 V
  • GND: Ground
  • SLC: I2C Clock
  • SDA: I2C data

You can see pinout of this module in the image below.

You can download the datasheet of this module here.

Required Materials

Hardware Components

Arduino UNO R3 × 1
LPS331AP Atmospheric Pressure Module × 1
Male to Female jumper wire × 1

Software Apps

Arduino IDE

Interfacing LPS331AP Sensor with Arduino

Step 1: Circuit

The following circuit shows how you should connect Arduino to LPS331AP module. Connect wires accordingly.

Step 2: Installing Library

Install following library on your Arduino.

https://github.com/pololu/lps-arduino.git

Tip

If you need more help with installing a library on Arduino, read this tutorial: How to Install an Arduino Library

Upload the following code to your Arduino.
/*
  modified on Sep 8, 2020
  Modified by MohammedDamirchi from https://github.com/pololu/lps-arduino.git
  
Home
*/ #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/33.77); Serial.print(" Inches (Hg)\ta: "); Serial.print(altitude); Serial.print(" m\tt: "); Serial.print(temperature); Serial.println(" deg C"); delay(100); }
After running the code, you will see the following image in the serial output.
Liked What You See?​
Get Updates And Learn From The Best​

Leave a Reply

Your email address will not be published. Required fields are marked *