[env:nodemcu]
platform = espressif8266
board = nodemcu
framework = arduino
lib_deps =
beegee-tokyo/DHT sensor library for ESPx@^1.19
#include "DHTesp.h"
#define DHTTYPE DHT11 // 传感器型号
#define DHTPIN 2 // D4连接到DHT11传感器的数字引脚
DHTesp dht;
void setup()
{
dht.setup(DHTPIN, DHTesp::DHT11);
}
void loop()
{
float h = dht.getHumidity();
float t = dht.getTemperature();
if (!isnan(h) && !isnan(t))
{
Serial.print("温度:");
Serial.println(temperature);
Serial.print("湿度:");
Serial.println(humidity);
}
delay(1000);
}