Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arduino DHT11传感器的值错误,希望将值添加到来自传感器的读数中_Arduino_Arduino C++ - Fatal编程技术网

Arduino DHT11传感器的值错误,希望将值添加到来自传感器的读数中

Arduino DHT11传感器的值错误,希望将值添加到来自传感器的读数中,arduino,arduino-c++,Arduino,Arduino C++,我需要帮助,我是Arduino的新手,我在NodeMCU 1.0板上运行DHT11传感器,我发现在很多趋势上,该传感器在湿度读数上不准确,这就引出了我的问题,我想从HTML页面上显示的传感器读数中加/减一个百分比。有人能帮忙吗 PS我附加了我使用的代码 包括 #包括 #包括 #包括 #包括“DHT.h” //对于您正在使用的任何DHT传感器类型,请取消注释下面的一行! #定义DHT类型DHT11//DHT 11 //#定义DHT类型DHT21//DHT 21(AM2301) //#定义DHT类型

我需要帮助,我是Arduino的新手,我在NodeMCU 1.0板上运行DHT11传感器,我发现在很多趋势上,该传感器在湿度读数上不准确,这就引出了我的问题,我想从HTML页面上显示的传感器读数中加/减一个百分比。有人能帮忙吗

PS我附加了我使用的代码

包括
#包括
#包括
#包括
#包括“DHT.h”
//对于您正在使用的任何DHT传感器类型,请取消注释下面的一行!
#定义DHT类型DHT11//DHT 11
//#定义DHT类型DHT21//DHT 21(AM2301)
//#定义DHT类型DHT22//DHT 22(AM2302)、AM2321
mdnsrresponder-mdns;
//替换为您的网络详细信息
const char*ssid=“温度服务器”;
const char*password=“vishaworld.com”;
ESP8266Web服务器(80);
字符串网页=”;
//DHT传感器
常数int DHTPin=4;
DHT-DHT(DHTPin,DHTTYPE);
静态字符celsiusTemp[7];
静态焦华氏温度[7];
静态煤焦湿度试验[7];
浮动h,t,f;
作废设置(作废){
Ip地址Ip(10,10,10,10);
IP地址NMask(255,255,255,0);
WiFi.模式(WiFi\u AP);
WiFi.softAPConfig(Ip、Ip、NMask);
WiFi.softAP(ssid,密码);
延迟(1000);
Serial.begin(9600);
Serial.println(“”);
//等待连接
延迟(5000);
Serial.println(“”);
串行打印(“软AP IP地址:”);
Serial.println(WiFi.localIP());
dht.begin();
if(mdns.begin(“esp8266”,WiFi.localIP())){
Serial.println(“MDNS响应程序已启动”);
}
服务器。在(“/”,[](){
网页=”;
网页+=“”;
网页+=“”;
网页+=“温度和湿度摄氏温度:”;
网页+=“”;
网页+=celsiusTemp;
网页+=“*C华氏温度:”;
网页+=华氏温度;
网页+=“*湿度:”;
网页+=湿度单位;
网页+=“%”;
网页+=“”;
发送(200,“文本/html”,网页);
});
server.begin();
Serial.println(“HTTP服务器已启动”);
}
无效循环(无效){
server.handleClient();
//传感器读数也可能达到2秒“旧”(这是一个非常慢的传感器)
浮动h=dht.read湿度();
//将温度读取为摄氏度(默认值)
浮点数t=dht.readTemperature();
//将温度读数为华氏度(伊斯华氏度=真)
浮子f=dht读数温度(真);
//检查是否有读取失败并提前退出(以重试)。
if(isnan(h)| | isnan(t)| | isnan(f)){
Serial.println(“从DHT传感器读取失败!”);
strcpy(celsiusTemp,“失败”);
strcpy(华氏温度,“失败”);
strcpy(humidityTemp,“失败”);
}
否则{
//以摄氏+华氏和湿度为单位计算温度值
浮点hic=dht.计算热指数(t,h,假);
dtostrf(hic,6,2,celsiusTemp);
float hif=dht.计算热指数(f,h);
dtostrf(hif,6,2,华氏度);
dtostrf(h,6,2,humidityTemp);
}
延迟(2000年);
}

在从传感器读取湿度读数后,我可能会输入代码修改湿度读数。这样,传感器的湿度读数和修正值都位于同一位置,因此很容易找到

您的代码片段:

// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// modify the humidity reading to provide a correction to the value
h = h + h * humidityCorrectionPercentage;
然后,在湿度传感器define所在的文件顶部附近,我将进行如下更改:

// Uncomment one of the lines below for whatever DHT sensor type you're using!
#define DHTTYPE DHT11   // DHT 11
//#define DHTTYPE DHT21   // DHT 21 (AM2301)
//#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321

// humidity sensor reading modification to modify the reading to more accurate value
// percentage in decimal form so 10% is 0.10 or 25% is 0.25
// use positive vale to increase the reading and a negative value to decrease the reading.
// specify a value of zero if no modification of the reading is needed.
const float humidityCorrectionPercentage = .10;

我从树莓Pi的读数中了解到,湿度传感器因不准确而臭名昭著。随着传感器老化,需要不时重新校准。要增加10%的价值,最简单的方法就是增加价值。增加价值的10倍。减去10%的值减去10倍的值。所以它应该像
temp=temp+percent*temp在何处添加百分比,则
百分比
为正;在何处减去百分比,则
百分比
为负
percent
是一个
float
,其百分比除以100,如10/100所示,即..10。我将在其中添加此代码?这就是那个地方吗计算温度值,单位为摄氏+华氏,湿度浮动hic=dht。计算热指数(t,h,false);dtostrf(hic,6,2,celsiusTemp);float hif=dht.计算热指数(f,h);dtostrf(hif,6,2,华氏度);dtostrf(h,6,2,humidityTemp);}