关于DHT11的问题,求解
比如:传感器感应出的温度28℃,湿度75%在blinker APP上面可以显示温湿度,挺正常的用小度问出来的温度也正常,但是问出来的湿度读数却是7500%,这是神马情况啊?
下面是我的代码:
#define BLINKER_WIFI
#define BLINKER_DUEROS_SENSOR
#include <Blinker.h>
#include <DHT.h>
char auth[] = "*****";
char ssid[] = "*****";
char pswd[] = "*****";
BlinkerNumber HUMI("num-shidu");
BlinkerNumber TEMP("num-wendu");
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
uint32_t read_time = 0;
float humi_read, temp_read;
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
Blinker.vibrate();
uint32_t BlinkerTime = millis();
Blinker.print("millis", BlinkerTime);
}
void heartbeat()
{
HUMI.print(humi_read);
TEMP.print(temp_read);
}
void DuerQuery(int32_t queryCode)
{
BLINKER_LOG("DuerOS Query codes: ", queryCode);
switch (queryCode)
{
case BLINKER_CMD_QUERY_ALL_NUMBER :
BLINKER_LOG("DuerOS Query All");
BlinkerDuerOS.temp(temp_read);
BlinkerDuerOS.humi(humi_read);
BlinkerDuerOS.print();
break;
case BLINKER_CMD_QUERY_TEMP_NUMBER :
BlinkerDuerOS.temp(temp_read);
BlinkerDuerOS.print();
break;
case BLINKER_CMD_QUERY_HUMI_NUMBER :
BlinkerDuerOS.humi(humi_read);
BlinkerDuerOS.print();
break;
default :
BlinkerDuerOS.temp(20);
BlinkerDuerOS.humi(20);
BlinkerDuerOS.print();
break;
}
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(D4, OUTPUT);
digitalWrite(D4, LOW);
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Blinker.attachHeartbeat(heartbeat);
BlinkerDuerOS.attachQuery(DuerQuery);
dht.begin();
}
void loop()
{
Blinker.run();
if (read_time == 0 || (millis() - read_time) >= 2000)
{
read_time = millis();
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
BLINKER_LOG("Failed to read from DHT sensor!");
return;
}
float hic = dht.computeHeatIndex(t, h, false);
humi_read = h;
temp_read = t;
BLINKER_LOG("Humidity: ", h, " %");
BLINKER_LOG("Temperature: ", t, " *C");
BLINKER_LOG("Heat index: ", hic, " *C");
}
}
哪位懂行的道友帮我解惑啊:dizzy: 自己除100再传呗 奈何col 发表于 2020-8-17 19:47
自己除100再传呗
大神啊,我不会弄啊,怎样修改一下:handshake 奈何col 发表于 2020-8-17 19:47
自己除100再传呗
求指教啊,怎样除100啊,应该怎样修改呢
:hug: 奈何col 发表于 2020-8-17 19:47
自己除100再传呗
大神,我琢磨半天把这个除100了 humi_read = h/100;
小度是可以正常读数了,但是blinkerAPP上面湿度显示1%了……
怎么弄啊:':'( 醉了。。。不要问这么蠢的问题。。。
BlinkerDuerOS.humi(humi_read/100);
奈何col 发表于 2020-8-17 21:42
醉了。。。不要问这么蠢的问题。。。
BlinkerDuerOS.humi(humi_read/100);
……我不懂这个啊,纯小白,有时间才翻的论坛各种帖子凑出来的代码:$
页:
[1]