DHT22 sensor wire length with ESP32?

I am putting together a project that needs several temp and humidity sensors. I need to space them out over 15-40 feet of wire length. How long can I go with wire? Something like cat5/6/7?!? Or is there a better alternative? I have read posts about issues over as little as 6 inches. There has to be a way to string them about. I guess I can place an ESP32 with each sensor but that would not be ideal either.
My use case is inside a Shipping container/Connex Box with the ESP outside and wired sensors inside. If I go with an ESP for each sensor I am doubtful the wifi signal will be able to get out. I do know the container acts like a big faraday cage. I have not tested this setup specifically but it is 2.4ghz. I have had issues with 2.4 wifi getting in to a container tiny house we built. So I am doubtful.
I have looked at several data sheets for these. Not finding anything specific about wiring length.

This is what I am using for DHT22
I already have several ESP32s

1 Like

I am using a esp8266 with 2 DHT22 sensors. One extends about 4" out and the other is about 12’ out. The connect is solid for the most part. However, at times when HA restarts, I loose one or the other sensors when HA is booted back up. When this happens, I just unplug/plug the power from the ESP8266 and both sensors work again. Once in awhile I would loose connection for a few seconds, but I think that maybe a router wifi issue.

40’ out, I would like to know if it will work as well. One connection perhaps but not multiple sensors connected imo.

1 Like

Based on my experience with DHT sensors, over a few feet won’t be reliable at 3.3V.

However at 5V, I’ve had no issues personally with 15’ cables. Have not tried anything longer. Google suggests that about 20’ is the upper limit.

Even at 5V these sensors are very fragile. A surge or spike nearby (ie. contactor opening) will cause the sensor to lock up requiring a power cycle. So I’ve been slowly modifying all my DHT sensors so the controller can power cycle them.

Now problem for your setup is you can’t run them at 5V without level shifting because the ESP is 3.3V only. If you have 5V available, you can use a bi-directional level shifter in the data line to allow the sensor to be biased at 5V, but communicate with the 3.3V ESP.

If all you need is temperature measurement, the DS18B20 is a much more stable choice.

1 Like

The ESPs I have do offer 5v and 3.3v so maybe I will try 5v with longer length. I have DHT11s hooked up right now on my test bench with dupont wires. DHT22s should be here monday. The spec on them says 3v-5.5v. For my project I must have temp and humidity. I will be the test guinea pig I guess. I will try it first with a regular cat5 UTP cable. If that is not reliable I will get some cat STP and try that. I was hoping someone had already done this and had some info.

I am making a hybrid de-humidification / solar wood kiln. It will have both a solar heat exchanger(think soda can heat exchanger but better) and a basement/crawlspace dehumidification unit run off of about 2kw of solar panels and a growatt 3000w hybrid inverter. My friend has a solar kiln but in the winter the cycle time is way too long, 6-8+ weeks. I am looking to shorten that to 2-3 weeks by using a 20’ shipping container along with dehumidification.

I couldn’t get the DHT22 to reliably report Temp/Humid using an ESP32 microcontroller using ESPHome. It would drop the temperature intermittently. I even tried using 5v to power the DHT22, using a 5v to 3.3v level shifter to ensure the ESP32’s GPIO pins were not damaged. I still had the drop outs. I switched to an AM2320 I2C Temp/Humid sensor and it has been rock solid. Those DHT22’s just are not very robust, IMHO. I would never use one for any critical tasks based on my testing.

What DHT22s with I2C did you use? Have a link? The ones I ordered are the AM2320 chip but just 1 wire.

The AM2320 is a different device compared to a DTH22 (aka AM2302). :wink:

Yeah the chip maker has them labeled as DHT22 and AM2320. I guess I need to look at getting a true I2C AM2320 from what you are saying. The ones I got are packaged just like a DHT11. POS, NEG, Data. See link above.

There are AM2302 devices, which are the same as DHT22s…

and there are AM2320 I2C devices, which require more wiring, including pull-up resistors.

image

It looks like this package has all of that. It is just not I2C. Here is the wiring spec.

This is an interesting site, comparing various humidity sensors…

https://www.kandrsmith.org/RJS/Misc/Hygrometers/calib_many.html

Ah I just read what you said again. Yes these are AM2302 not AM2320. Thanks for pointing that out.

1 Like

So I got a minute to play and read up some more on the 1wire spec. I should be able to go up to about 50’ with a 4.7k resistor commonly used on these sensors. I found a 15’ old cat5 UTP cable and snipped the ends off of it. I then stripped the wires and just hand wire wrapped them to appropriate dupont jumpers for the ESP32 and DHT11 using 5v, GND and GPIO2. I used both wires of each color so 6 of the 8 wires available. IT WORKS! I think I will be ok to go the length I need to based on this testing with the DHT22s I have coming.

This thread and this post specifically stated it should work and it does.
https://forum.arduino.cc/index.php?topic=93241.msg700811#msg700811

2 Likes

Picture!!!

Give it time, and it will stop working. :slight_smile:

Start a vehicle beside the container, wait for a distant lightning strike, or otherwise let the sensor just run for a week, 2 weeks, a month, and it will fail at some point.

If you want to use the I2C version, there are I2C extenders which are basically differential line drivers. If you search eBay/Aliexpress for “i2c differential extender” you can find them for a few dollars. They’ll allow you to use hundreds of meters of cable for I2C devices and because they are differential, are very immune to noise.

Or, if you are going to use the DHT22 style sensors, set them up so the controller can power cycle them if it starts getting a bad reading.

Except…they do have an insidious failure mode. More than once I have seen the sensor itself still respond to the onewire, but either the humidity or temp value (most often humidity) returns a frozen value. No new readings are taken. So in my setup, I have a fail safe that if any reading is the same for 60 reads (once per minute) it toggles the sensor power.

My favourite DHT failure is in my shop. DHT22 connected to my own custom controller board which also handles switches and relays. The power button for my air compressor is mounted to a cabinet which also contains the compressor contactor (switching 25A at 240V). The wire for the button runs beside the DHT22 sensor wire for about 6". Every 10 times or so, when I switch off the compressor, the DHT22 locks up and starts returning NaN. I have been unable to solve this with filter capacitors on the DHT22 power pins (can’t do anything about the data pin, unfortunately, due to the strict timing requirements of the protocol), a snubber on the relay coil, snubber on the button wires or shielded cable. So that’s whey I rewired the DHT22 so I could toggle the power with the controller and changed my code to return a dummy value of 99.9 / 199.9 and toggle the power. Because I also found a bug in HA (which has been reported) that stops the front end from loading if a template sensor feeding a generic thermostat receives a NaN value.

2 Likes

I hope I dont have those types of problems. Maybe I will. The way I am setting this up is to power down overnight. Everything except the RPi running everything will shut off before dusk. The RPi will not be out on the kiln itself. I only need this to run when the sun is out and can power the fans/dehumidifier. Maybe that will work in my favor as I plan on having the ESPs/fans/dehumidifier on smart power switches.

Messy but it is working.

Is that a DTH22 or a DHT11?

That to me looks like a DHT11 sensor. A worse version of the DHT22. :slight_smile:

You would both be correct. That is a DHT11. I said upwards that I had ordered some DHT22s. The DHT11s I have seem to work fine as far as cable length goes but I was sorely unimpressed with the RH% accuracy. The sheet says +/-5% for DHT11. I was seeing 8%-10% variance of sensors right next to each other. So I ordered some DHT22s. Hopefully they will be much closer to the +/-2% on that data sheet.