User avatar
Posts: 382
Joined: Sat Jul 21, 2012 10:09 pm
Location: Now an expatriate, originally from Zulia, Venezuela
Contact: Website Skype

Random spikes with AM2302 Temperature & Humidity sensor

Sat Apr 27, 2019 7:59 pm

I built for logging auditing purposes a simple Temperature & Humidity datalogger, using an DS18B20 temp sensor for sensing an equipment rack and a AM2302 (also know as DHT22) Temperature & Humidity sensor for registering the ambient temperature inside the room.

This setup is running 24 hours a day registering all three sensors values once every minute, then storing the readings in a plain text file for later retrieval, all of this thanks a Python script, called via a cron job every minute.

Graph generation is done via an script using the venerable gnuplot utility.

The device has been running from March 7, but the fact is once a while I got some spikes in the humidity reading, they are no more than a couple of spikes in a single 24 logging day and has been appearing 3 or four times in about 48 days of logging.

The room were the device is running is a small (about 6 square meters) datacenter with no A/C (This is why I put the device in!) and have no AC motors nearby that be causing AC interference, also there is no lights on, also the room is manned a few days a week, the spikes appear whatever the room is manned or not.

Both sensors are connected to the Raspberry Pi by a short cable (about 1.2 meters long); the Temp&Hum sensor cable run straight outside the rack, as you can see in the picture below.

What would be the cause of those random spikes?
24-Apr-2019.png (28.82 KiB) Viewed 597 times
25-Apr-2019.png (30.17 KiB) Viewed 597 times
20190426_181748 - Copy.jpg
20190426_181748 - Copy.jpg (141.77 KiB) Viewed 597 times
Telecom Specialist (Now Available for Hire!)

Posts: 1698
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: Random spikes with AM2302 Temperature & Humidity sensor

Sat Apr 27, 2019 9:14 pm

unless someone is playing games with you and dipping your AM sensor into a bag of desiccant every now and again? i dont know. but afaik these sensors are not considered 100% reliable and have a limited active life? perhaps such glitches are just a feature of the sensor and an increase in frequency may indicate an impending end to the sensors life

perhaps rather than taking a single reading and logging it it may be prudent to take a number of readings from the sensor and record the average (modal), this should at least provide a cleaner data set.

User avatar
Posts: 295
Joined: Mon Nov 12, 2012 10:22 pm
Contact: Website

Re: Random spikes with AM2302 Temperature & Humidity sensor

Sat Apr 27, 2019 11:20 pm

The reason many people use the bme280 is that it is reliable, accurate, and repeatable. Swapping sensors can be a pain, but sometimes using a different chip just works out being easier, and wastes less of your time in the long term.

Actual analysis of 11 sensors, and note the reliability comments of the DHT style units: ... _many.html

Best of Luck,

Posts: 105
Joined: Mon May 19, 2014 3:47 pm

Re: Random spikes with AM2302 Temperature & Humidity sensor

Sun Apr 28, 2019 1:55 am

Hi Marco,

I created an application with an am2302 DHT as well... also running since early March. Yes I get erroneous data readings too... 23 times in about 7 weeks. I poll the sensor from a Python script every 10mins.

I assume it's because the sensor is cheap and so the chip in it is not very reliable.

I have been wondering what I should do with the erroneous readings. SWhen I plot them on Chart.js it messes with the Chart plot. For now I have been getting an average of the value before and after the error value and replacing the error value with that average. Another option might be to just repeat the last value that was not an "error" reading... you could certainly do that in your case since you are getting values so often... perhaps you don't need to poll so often? I might just get a better sensor myself!


Return to “Automation, sensing and robotics”