반응형
    
    
    
  
💬 일부 링크에는 클릭 또는 구매 시 소정의 수익이 발생할 수 있습니다.
알리익스프레스
구입가: ₩956
배송: 초이스 무료. 4일 만에 도착
상품페이지
https://s.click.aliexpress.com/e/_omvCOdZ
BME280/BMP280 5V 3.3V Digital Sensor Temperature Humidity Barometric Pressure Module I2C SPI - AliExpress 502
Smarter Shopping, Better Living! Aliexpress.com
www.aliexpress.com
전압에 따라 모듈의 형태가 다릅니다. 이 모듈의 특징은 온도와 기압이 측정되므로 고도를 계산할 수 있습니다.
I2C 핀연결
| BMP280 | ESP32 | 
| VCC | 3.3V | 
| GND | GND | 
| SCL | 22 | 
| SDA | 21 | 
| CSB | x | 
| SDO | x | 
I2C 주소는 기판에서 변경할 수 있습니다.
Arduino IDE
- Arduino BMP280 라이브러리를 설치합니다.
 
예제를 참고하여 코딩을 합니다.
Arduino 코드
#include <Wire.h>
#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp;
void setup() {
  Serial.begin(115200);
  Serial.println(F("BMP280 test"));
  unsigned status;
  status = bmp.begin(0x76, 0x58);
  if (!status) {
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring or "
                      "try a different address!"));
    while (1) delay(10);
  }
  bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */
                  Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */
                  Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */
                  Adafruit_BMP280::FILTER_X16,      /* Filtering. */
                  Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
}
void loop() {
  static unsigned long i2c_start = millis();
  if (millis() - i2c_start > 1000) {
    Serial.print(F("BMP280 Temperature = "));
    Serial.print(bmp.readTemperature());
    Serial.println(" ℃");
    Serial.print(F("BMP280 Pressure = "));
    Serial.print(bmp.readPressure() / 100);
    Serial.println(" hPa");
    Serial.print(F("BMP280 Altitude = "));
    Serial.print(bmp.readAltitude());
    Serial.println(" m");
    Serial.println();
    i2c_start = millis();
  }
}
위 코드는 기준 기압(1013.25)으로 계산하기 때문에 실제 고도와 다르게 표시될 수 있습니다.
float readAltitude(float seaLevelhPa = 1013.25);
정확한 고도 계산 방법
\(
{\displaystyle h=145366.45\left[1-\left({\frac {\text{현위치 기압(hPa)}}{기준 기압(hPa)}}\right)^{0.190284}\right]}
\)
표준 1기압은 1013.25hPa입니다. 해면 기압은 실시간으로 변하기 때문에 실제 기압으로 계산해야 합니다.
기상청에서 기압 정보를 얻을 수 있습니다. 일기도를 보거나 지역별 기압 자료를 참고합니다.


그다음 코드에서 bmp.readAltitude() 파라미터에 기준 기압(Pa)을 입력하면 됩니다.
// 아두이노
Serial.print(bmp.readAltitude(1023.3)); /* Adjusted to local forecast! */
※ 기상청은 유효자리수가 소수점 1자리이므로 고도값에 오차가 발생할 수 있습니다. 현재 기압을 입력 후 실행해보니 현재 높이와 근사치로 측정되었습니다.
반응형