Advertisement
microrobotics

Adafruit MPL115A2

Mar 30th, 2023
663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*The Adafruit MPL115A2 is a digital barometric pressure sensor that communicates over I2C. Here's an example code in Arduino that reads the pressure and temperature from the sensor:
  2. Note: This code assumes that the Adafruit MPL115A2 sensor is connected to the I2C bus of the Arduino board. If you're using a different I2C bus or pins, you'll need to modify the mpl115a2 initialization accordingly.
  3. */
  4.  
  5.  
  6. #include <Wire.h>
  7. #include <Adafruit_MPL115A2.h>
  8.  
  9. Adafruit_MPL115A2 mpl115a2;
  10.  
  11. void setup() {
  12.   Serial.begin(9600);
  13.  
  14.   if (!mpl115a2.begin()) {
  15.     Serial.println("MPL115A2 not found!");
  16.     while (1);
  17.   }
  18. }
  19.  
  20. void loop() {
  21.   // read the pressure and temperature from the sensor
  22.   float pressure = mpl115a2.getPressure();
  23.   float temperature = mpl115a2.getTemperature();
  24.  
  25.   // print the pressure and temperature
  26.   Serial.print("Pressure: ");
  27.   Serial.print(pressure);
  28.   Serial.println(" Pa");
  29.   Serial.print("Temperature: ");
  30.   Serial.print(temperature);
  31.   Serial.println(" °C");
  32.  
  33.   // delay before reading from the sensor again
  34.   delay(1000);
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement