DHT11 传感器值错误,想要将值添加到来自传感器的读数

DHT11 sensor with wrong values, wanting to add values to the reading that comes from sensor

我需要帮助,我是 Arduino 的新手,我是 运行 NodeMCU 1.0 板上的 DHT11 传感器,我发现许多趋势表明该传感器主要在湿度读数上不准确,这带来了对于我的问题,我想 add/subtract 从 HTML 页面上显示的传感器读数中提取百分比。有人可以帮忙吗?

PS 我附上了我正在使用的代码。

include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include "DHT.h"

// 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

MDNSResponder mdns;

// Replace with your network details
const char* ssid = "Temperature_Server";
const char* password = "vishaworld.com";

ESP8266WebServer server(80);

String webPage = "";

// DHT Sensor
const int DHTPin = 4;
DHT dht(DHTPin, DHTTYPE);
static char celsiusTemp[7];
static char fahrenheitTemp[7];
static char humidityTemp[7];
float h, t, f;

void setup(void) {
  IPAddress Ip(10, 10, 10, 10);
  IPAddress NMask(255, 255, 255, 0);
  WiFi.mode(WIFI_AP);
  WiFi.softAPConfig(Ip, Ip, NMask);
  WiFi.softAP(ssid, password);

  delay(1000);
  Serial.begin(9600);
  Serial.println("");

  // Wait for connection
  delay(5000);
  Serial.println("");
  Serial.print("SoftAP IP address: ");
  Serial.println(WiFi.localIP());

  dht.begin();

  if (mdns.begin("esp8266", WiFi.localIP())) {
    Serial.println("MDNS responder started");
  }

  server.on("/", []() {
    webPage = "";
    webPage += "<!DOCTYPE HTML>";
    webPage += "<html>";
    webPage += "<head></head><body><h1>Temperature and Humidity</h1><h3>Temperature in Celsius: ";
    webPage += "<meta http-equiv=\"refresh\" content=\"6\">" ;
    webPage += celsiusTemp;
    webPage += "*C</h3><h3>Temperature in Fahrenheit: ";
    webPage += fahrenheitTemp;
    webPage += "*F</h3><h3>Humidity: ";
    webPage += humidityTemp;
    webPage += "%</h3><h3>";
    webPage += "</body></html>";
    server.send(200, "text/html", webPage);
  });

  server.begin();
  Serial.println("HTTP server started");

}

void loop(void) {
  server.handleClient();
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    strcpy(celsiusTemp, "Failed");
    strcpy(fahrenheitTemp, "Failed");
    strcpy(humidityTemp, "Failed");
  }
  else {
    // Computes temperature values in Celsius + Fahrenheit and Humidity
    float hic = dht.computeHeatIndex(t, h, false);
    dtostrf(hic, 6, 2, celsiusTemp);
    float hif = dht.computeHeatIndex(f, h);
    dtostrf(hif, 6, 2, fahrenheitTemp);
    dtostrf(h, 6, 2, humidityTemp);
  }
  delay(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;

然后在湿度传感器定义所在的文件顶部附近,我将进行如下更改:

// 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;