ccarman602

Lesson-9-AirPressure

Nov 25th, 2021 (edited)
533
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Air pressure detection
  2. #include "Seeed_BMP280.h"
  3. #include <Wire.h>
  4.  
  5. BMP280 bmp280;
  6.  
  7. void setup() {
  8.     Serial.begin(9600);
  9.     if (!bmp280.init()) {
  10.         Serial.println("Device not connected or broken!");
  11.     }
  12. }
  13.  
  14. void loop() {
  15.  
  16.     float pressure;
  17.  
  18.     //get and print temperatures
  19.     Serial.print("Temp: ");
  20.     Serial.print(bmp280.getTemperature());
  21.     Serial.println("C"); // The unit for  Celsius because original arduino don't support speical symbols
  22.  
  23.     //get and print atmospheric pressure data
  24.     Serial.print("Pressure: ");
  25.     Serial.print(pressure = bmp280.getPressure());
  26.     Serial.println("Pa");
  27.  
  28.     //get and print altitude data
  29.     Serial.print("Altitude: ");
  30.     Serial.print(bmp280.calcAltitude(pressure));
  31.     Serial.println("m");
  32.  
  33.     Serial.println("\n");//add a line between output of different times.
  34.  
  35.     delay(1000);
  36. }
  37.  
RAW Paste Data