Arduino IDE 开发ESP-01/ESP8266-01读取DHT11温度湿度传感器
引脚接线:
DHT11---ESP8266-01
Singnal--IO2,
GND----GND,
VCC----VCC
DHT11引脚说明:
ESP8266-01/ESP8266-01S引脚说明:
Arduino 工具>管理库>搜索并安装SimpleDHT
#include <SimpleDHT.h> int pinDHT11 = 2; //IO2 SimpleDHT11 dht11(pinDHT11); void setup() { Serial.begin(115200); } void loop() { byte temperature = 0; byte humidity = 0; int err = SimpleDHTErrSuccess; if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { Serial.print("Read DHT11 failed, err="); Serial.println(err);delay(1000); return; } Serial.print((int)temperature); Serial.print(" *C, "); Serial.print((int)humidity); Serial.println(" H"); delay(1500); }
个人接线:
连接电脑测试:
运行效果: