September 2019 Update

New! We're moving to the new forum!

ALL new Blog posts will be on the forum.

Please join us there.

This Blog will no longer be updated...

Monday, August 5, 2019

DHT22 Temp/Humidity Sensor - Eureka Moment...

These little digital units have a habit of returning invalid data, not quite sure if it just gets confused, or has locked up and the driver can't read it, but it happens on a fairly regular basis. Often enough that I built in a "reset" by powering it from a digital pin which I can turn on and off. If I get an invalid reading, I simply write a LOW to the digital pin hooked up to it's power, wait a bit, then write a HIGH, thus rebooting the DHT22... or so I thought...  This trick hasn't been working...




I know with the pro/mini when I have it hooked up via USB, I can disconnect the 5v line, and the led will stay dimply lit until I remove the ground, or the rx/tx wires (not sure if it's one or both) which tells me they are powered too...

I just woke up from my nap with the thought that maybe the same thing is happening here, not with tx/rx, but with the actual signal wire, the one that reads the sensor...

So I got out my multi-meter and set up a test, and sure enough, the signal pin is HIGH, providing power. Now, I don't know if the DHT22 remains powered up from that, there are no leds to see...

I'm going to modify the code so that when it does a reset, it sets both pins LOW. I'll have to switch the signal pin from INPUT to OUTPUT, set it LOW, set the power pin LOW, wait a few milliseconds, set the signal pin back to INPUT mode, and the power pin to HIGH.

I'll do that and wait to see what happens next time one fails.

3 comments:

  1. Three times it has happened so far, and the great news is, it works! In all three cases, it reset the DHT22 and I got a reading...

    ReplyDelete
  2. I also noticed when I was testing to see if the pins had power, they are only getting about 4.2v, not a full 5v. I wonder if this is affecting some of the sensors? I'm thinking of putting a dc/dc stepdown converter on the board, something to provide a nice steady 5v. If I do that, I'll need a way to switch it to up to 20 different sensors... hmmm...

    I could use transistors, they can be switched using the same digital pins I'm using now to power each of the sensors, so I wouldn't even need to change code or configuration...

    ReplyDelete
  3. Just a followup, in every case I've seen, the dht is reset and a valid reading is made. This fix is working perfectly... I still haven't finished the external power supply yet...

    ReplyDelete

Any comments deemed off topic or offensive will be removed