2021年11月28日 星期日

ESP32 BMP280 大氣壓強度(高度計)感測模組

 ESP32 BMP280 BMP280 大氣壓強度(高度計)感測模組 




ESP32 SCL (GPIO 22) and SDA (GPIO 21) pins


#include <Wire.h>             // include Wire library, required for I2C devices

#include <Adafruit_Sensor.h>  // include Adafruit sensor library

#include <Adafruit_BMP280.h>  // include adafruit library for BMP280 sensor

#define BMP280_I2C_ADDRESS  0x76


Adafruit_BMP280 bmp280;

 

void setup() {

  Serial.begin(115200);

  Serial.println(F("BME280 test"));

  if (!bmp280.begin(BMP280_I2C_ADDRESS))

  {  

    Serial.println("Could not find a valid BMP280 sensor, check wiring!");

    while (1);

  }

  

}


void loop()

{

    // get temperature, pressure and altitude from library

    float temperature = bmp280.readTemperature();  // get temperature

    float pressure    = bmp280.readPressure();     // get pressure

    float altitude_   = bmp280.readAltitude(1013.25); // get altitude (this should be adjusted to your local forecast)

    //1013.15需修正

    //該1013.25值應為數百Pa處的海平面局部壓力。

    //如果要顯示高於地面的高度,則需要知道該位置,並編寫代碼以計算高度偏移。

    //海平面:泛指我們所處的高度,即1大氣壓(1atm或1013.25hPa 或 1013.25mb)

    //That 1013.25 value should be the local pressure at sea level in hundreds of Pa. 

    //If want to show altitude above ground level, you will need to know that for your location and write your code to calculate the altitude offset.

    // print data on the serial monitor software

    // 1: print temperature

    Serial.print("Temperature CELSIUS 攝氏溫度= ");

    Serial.print(temperature);

    Serial.println(" °C");

    float TempF = (temperature*1.8)+32;

    Serial.print("Temperature FAHRENHEIT 華氏溫度= ");

    Serial.print(TempF);

    Serial.println(" °F");

    // 2: print pressure

    Serial.print("Pressure 大氣壓力百帕(hPa)= ");

    Serial.print(pressure/100);

    Serial.println(" hPa");

    // 3: print altitude

    Serial.print("Approx Altitude 大概海拔高度= ");

    Serial.print(altitude_);

    Serial.println(" m");

    delay(2000);

}    

沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) Node-Red 程式 [{"id":"d8886...