I've put together a flashing circuit and sketch (it's seemed to have worked). The purpose of which is to read the ambient temperature and send it on to a MQTT server within my local network via WiFi. The temperature reading my MQTT server receives is over by about 23 C. The circuit reads about 33 C, and my house is about 17 C at most. I appreciate the DHT11 is only accurate to +/- 2 C but this reading is well over specification.
I'm using a DHT11 sensor module, coupled to an ESP-01S micro-controller. The sketch is something I've written myself to publish MQTT messages to a server. The connection to the Wifi network and Publishing of messages works as I'd expect. Power is a from a cheap variable bench PSU reading about 5.14V.
Expected readings would have been around 17 C - 20 C. Using Arduino 1.8.9 on Arch Linux, DHT sensor library (by Adafruit) is at 1.3.0
I'm quite inexperienced with Arduino, MQTT, and these kind of projects (although I did a bit of Digital Electronics nearly 20 years ago) so forgive me if I've missed the obvious.
Do you suspect the conversion from float to string (fair point, I was unsure)? So as a test (just now) I amended the main loop as follows;
void loop()
{
delay(DELAY_TIME);
humidity = dht.readHumidity(); // Read humidity (percent)
temp = dht.readTemperature(false); // Read temperature as Celcius
temp = 17.23; // Test hard code value
bufString = "Temp: " + String((int)temp) + " C, Humidity: " + String((int)humidity) + "%";
bufString.toCharArray(buf, 128);
client.publish("esp/temp", buf);
}
Note that I've added a line to set temp to 17.23 prior to sending the MQTT message. The message was received as "Temp: 17 C, Humidity: 56%". (Imgur: The magic of the Internet). It would seem that the value of the temp variable is being reported correctly.
One thing I noticed to get you the above is that the timestamps are 2016, and that the current version on Releases · adafruit/DHT-sensor-library · GitHub is a lot more recent. I'm going to try getting the latest version with git rather than a download zip (which I did this afternoon).
I'm now using the latest version of the library, and seeing temperatures started at 26 C, after two minutes it seems to be at 29 C. Looks like its passing 30 C as I write this. This is the library.properties file
This is something interesting. I moved the ESP-01s board away from the DHT11 module using a load of wires. It's been running now for about 15 minutes, and has been reporting a consistent 26 C for the most of that time.
I'm measuring the room at 19 C using one thermometer, and 20 C on my 3D printer.
So there is an element of the ESP-01s sitting on top of the DHT11 that is throwing the reading off significantly. This style of packaging is obviously a weakness. However unless I'm mistaken, the fact its reading 26 C while true ambient is 20 C is still outside the +/- 1% tolerance the DHT11 should be within.
Is there a calibration process I can do to rectify this?
Without the ability to do Serial debug prints you're working blind. Guess I'd try the sensor on a different processor where you can print intermediate results. Maybe try a couple sensors with different processor boards. After that I'd probably dig into the datasheet and instrument the library code with debug prints until I determined whether the problem is the hardware or the code.
I haven't had any issues with the Adafruit library using a DHT22.