本站改版新增arduino频道
arduino BMP280 气压 海拔 高度
#include <Wire.h> #include <Adafruit_Sensor.h> #include <Adafruit_BMP280.h> #define SDA_PIN 4 #define SCL_PIN 5 Adafruit_BMP280 bmp; void setup() { Serial.begin(9600); // 指定 SDA 和 SCL 引脚 Wire.begin(SDA_PIN, SCL_PIN); if (!bmp.begin(0x76)) { Serial.println("Could not find a valid BMP280 sensor, check wiring!"); while (1); } } void loop() { float temperature = bmp.readTemperature(); float pressure = bmp.readPressure() / 100.0; float altitude = bmp.readAltitude(1013.25); Serial.print("Temperature: "); Serial.print(temperature); Serial.println(" °C"); Serial.print("Pressure: "); Serial.print(pressure); Serial.println(" hPa"); Serial.print("Altitude: "); Serial.print(altitude); Serial.println(" meters"); Serial.println(); delay(1000); }
Copyright © 2014 ESP56.com All Rights Reserved
晋ICP备14006235号-22 晋公网安备14108102001165号
执行时间: 0.0093538761138916 seconds