本站改版新增arduino频道
arduino AHT20+BMP280模块
#include <Wire.h> #include <AHT20.h> #include <Adafruit_BMP280.h> #define SDA_PIN 4 #define SCL_PIN 5 AHT20 aht20; Adafruit_BMP280 bmp; void setup() { Serial.begin(9600); // 指定 SDA 和 SCL 引脚 Wire.begin(SDA_PIN, SCL_PIN); if (!aht20.begin()) { Serial.println("Could not find AHT20 sensor!"); while (1); } if (!bmp.begin()) { Serial.println("Could not find BMP280 sensor!"); while (1); } } void loop() { // Read AHT20 data int temperature_aht = aht20.getTemperature(); int humidity_aht = aht20.getHumidity(); if (!isnan(temperature_aht) && !isnan(humidity_aht)) { Serial.print("AHT20 Temperature: "); Serial.print(temperature_aht); Serial.println(" °C"); Serial.print("AHT20 Humidity: "); Serial.print(humidity_aht); Serial.println(" %"); } else { Serial.println("Failed to read AHT20 data!"); } // Read BMP280 data int pressure_bmp = bmp.readPressure() / 100; int altitude_bmp = bmp.readAltitude(1013.25); Serial.print("BMP280 Pressure: "); Serial.print(pressure_bmp); Serial.println(" hPa"); Serial.print("BMP280 Altitude: "); Serial.print(altitude_bmp); Serial.println(" meters"); delay(2000); // Delay for 2 seconds before the next reading }
Copyright © 2014 ESP56.com All Rights Reserved
晋ICP备14006235号-22 晋公网安备14108102001165号
执行时间: 0.0095260143280029 seconds