入驻于 2020-04-26 / MAKE 主页
@Spoony 我用这个代码显示有错误
#include <DHT.h>
#include <DHT_U.h>
#include <LiquidCrystal.h>
#define DHTPIN 8
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// put your setup code here, to run once:
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("start");
delay(1000);
dht.begin();
Serial.begin(9600);
Serial.println("DHT11 TEST PROGRAM ");
Serial.println();
}
void loop() {
int chk = DHT11.read(DHT11PIN);
// 测试 DHT 是否正确连接
Serial.print("Read sensor: ");
switch (chk)
{
case DHTLIB_OK:
Serial.println("OK");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.println("Checksum error");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.println("Time out error");
break;
default:
Serial.println("Unknown error");
break;
}
// put your main code here, to run repeatedly:
float h = dht.readHumidity();
float t = dht.readTemperature();
Serial.println("\n");
lcd.setCursor(0, 0);
lcd.print("Hum:");
lcd.setCursor(7, 0);
lcd.print(h);
lcd.setCursor(11, 0);
lcd.print("%");
lcd.setCursor(0, 1);
lcd.print("Temp:");
lcd.setCursor(7, 1);
lcd.print(t);
lcd.setCursor(11,1);
lcd.print("C");
Serial.print("Humidity: ");//湿度
Serial.println(h);
Serial.print("Temperature: ");//温度
Serial.print(t);
Serial.println(" ℃ ");
delay(2000);
}
这是我的代码
有没有用esp8266相关教程呢