When I was contemplating building a weather station, the part that I thought would be the most straightforward was measuring temperature. As reality often doesn’t match expectations, this has not been the case. I am using a couple of DHT22 temperature and humidity sensors. One for indoor and another for outdoors. I found this Random Nerds Tutorial that has been helpful. I read that these were an older sensor and are slow requiring a couple of seconds between reads. I didn’t expect that this would be a problem as at most I only take one reading per minute. I went ahead and included them.
Temperature reading is too high
The specifications list the temperature accuracy as less than ±0.5 °C, however, initially my sensors were reading at least 2°C higher than expected. I don’t know if that is consistent across the temperature range. What I do know is that when the ground is covered in a thick white frost and the hot water pipes from our solar hot water system are frozen and I check the official weather and it says -2°C I knew my sensor is wrong when it showed +2°C.
I checked online for solutions. The main suggestions are:
Heat from Components and enclosure effects: The sensor is mounted on a spacer outside of the enclosure for the indoor unit. For the outdoor unit the sensor is mounted a couple of metres away under the shaded south-facing eaves (southern hemisphere).
Power supply: The supplies I am using are good quality. The sensors themselves were being powered from the 3.3V pin of the ESP board
This is the indoor unit with the top open.

The indoor unit sitting on a shelf in the kitchen

The ESP32 board (highlighted red) for the outdoor unit is in a PC case, powered by a Meanwell 5V power supply which sits in our garage

The outdoor sensor sits under the eaves and the DHT22 is held off from the protective cover (yes, that’s a spray paint can lid) by a brass standoff.

I wanted to try and make it as accurate as possible. We have a number of digital thermometers and what I found is that no two of them read the same temperature. Even an indoor/outdoor displays different temperatures (often only about 0.5 degrees) when the two sensors have been next to each other for hours. I remember now why I lost interest in building test equipment. In the end I had something I didn’t have confidence with.
Changing power supply
The maximum current required by the sensor listed in the datasheet is 1.5mA, this should be low enough to comfortably power it from a GPIO pin of the ESP32. This allows the sensor to be powered down when not taking readings, which I hope will reduce supply heating effects.

The ESP32 goes into deep sleep between readings. Here are the relevant bits I added to power the sensor from GPIO pin D25. I got ChatGPTs help with the code to ensure the pin was kept low during deep sleep.
// At the top of the sketch
#define DHT_PWR 25 // GPIO powering the DHT22
// --- In setup before taking a reading ---
// Power the DHT22
pinMode(DHT_PWR, OUTPUT);
digitalWrite(DHT_PWR, HIGH);
// Allow the DHT22 time to stabilise (needs ~1s after power-on)
delay(2000);
// --- In the sleep function ---
// Turn off DHT22
pinMode(DHTPIN, INPUT); // float data pin to prevent back-powering
digitalWrite(DHT_PWR, LOW); // power off
gpio_hold_en((gpio_num_t)DHT_PWR);
gpio_deep_sleep_hold_en(); // ensure it stays low during sleep
This seems to have helped. The sensor is still reading higher than I believe is correct, but not quite as high as before. I’m currently simply deducting 1.1°C from all readings, which feels like cheating but does does get it closer to what I expect.
Negative temperatures error
We have quite a few frosts here during winter. As the sensor was reading too high I didn’t notice another issue until one day the temperature apparently fell to -3276.7°C. Surely that must be a record, not just for our area but also for the universe.

I’ve been using the Adafruit DHT library and found this post in the Arduino forum reporting issues with negative temperatures. There was a link to an issue posted on 30 Dec 2024 in the library GitHub repository [DHT22] Incorrect handling of negative temperature values #221 that covers the issue. While it hasn’t yet been fixed in the library there is a link to this change for the DHT.cpp file that has not been included in the library. It looks like it is still being reviewed. I manually made the changes by adding the lines marked with a + in the patch to the DHT.cpp file.
We have had low temperatures and I can confirm the change works. If you are using this sensor and library at least be aware of the issue.
Alternative sensor fail
I had a couple of TMP36GT9 sensors sold as “TMP36GT9 ORIGINAL Low Voltage Temperature Sensors” that I purchased a few years ago from eBay for $AU6.64 for 2. I decided to give these a shot. The datasheet lists the specifications for these as having a range of −40°C ≤ +125°C, which seems ideal.
An interesting thing about these is that they are a three wire device in a package similar to a transistor. I hadn’t used these before and spent some time setting one up on a breadboard. The readings for one jumped all over the place and the other output a zero value. I tested them in my cheap component tester and both were identified as NPN transistors. This puts them up there with the most expensive transistors I’ve purchased. Both went in the bin and I’ve gone back to the DHT22 sensors.
Finally
Do you have any thoughts? Have you had success with these sensors or recommendations for other sensors? Do you see anything I’m doing wrong? Even a suggestion of how to calibrate them other than placing the sensor in boiling water would help.
Leave a comment