Problems with DHT22 sensor

Okay I have been using the attached code for my egg incubator. It would read the temp and humidity fine for a while and then randomly go NAN for both.

I have a 10k between the data pin and 5v.

I have tried different libraries....

Now it will only show the temp and humidity is NAN.

I have tried multiple arduino nanos and I get the same problem.

Could someone please look over this code and see if they see anything I am missing. I think I may switch to a Si7021 sensor...

NOTE: Code was to big to put in this post so it is attached!

incmaincode_Hogen.ino (48 KB)

Once again, you have discovered the difficulty in "finding the needle in the haystack" problems that happen when code is written in this monolithic style.

All I can ask is, have you checked the hardware with a simple DHT library example?

aarg:
Once again, you have discovered the difficulty in "finding the needle in the haystack" problems that happen when code is written in this monolithic style.

All I can ask is, have you checked the hardware with a simple DHT library example?

Yes I have uploaded and checked the sensor using the tester example in the dht library and it reads fine with it and continues to do so for over an hour. where as with the code I uploaded it wont read humidity at all and if it does it goes nan for both temp and humidity randomly after a while.

Another thing to try, is to run the sketch with only the relay(s) disconnected, and see what happens. Sometimes a power glitch from that can cause weird problems.

How far from the control board is the DHT22 sensor? Try using screened cable, I use twin screened flex similar to stereo screened audio cable. Use the screen as ground (common -ve) and say red for +5v and white for DHT22 output signal. Could use a small decoupling capacitor, say 10uF across the supply to the sensor.

aarg:
Another thing to try, is to run the sketch with only the relay(s) disconnected, and see what happens. Sometimes a power glitch from that can cause weird problems.

I have a 12 volt to 5 volt converter and that plugs into the arduino through usb. Is it possible thats not giving the system enough juice? Between the sensor and the 8 channel relay board and 20 X 4 lcd screen? Maybe I should power those devices directly from the power supply vs the 5 volt pin on the board.

Any results from the experiment in reply #3?

aarg:
Any results from the experiment in reply #3?

Are you talking about the decoupling capacitor idea? I will have to see if i have a capacitor to try. Is he saying between the 5v and ground near the dht22?

No, just what I said -

with only the relay(s) disconnected

. Is there something confusing about that?

aarg:
No, just what I said - . Is there something confusing about that?

I have already tried upluging the relays that doesnt do anything. It reads the temp but has NAN for the humidity.

Anita_Bath:
I have already tried upluging the relays that doesnt do anything. It reads the temp but has NAN for the humidity.

When was that? You should have reported the results already, to avoid wasting peoples time.

aarg:
When was that? You should have reported the results already, to avoid wasting peoples time.

I had tried that before I started this thread and didnt think of it till it was mentioned it.

I now have a si7021 sensor and will see if it can read it instead.

Hows that for an update.

Okay so I now have an si7021 temp and humidity sensor hooked up and it uses I2C to communicate just like the lcd and the real time clock module does. It seems to work now but after an hour or so some times not always the lcd screen goes gibberish and a power cycle clears it up. What would cause that?

The arduino is powered through usb from the power supply and the lcd, relay board, temp and humidity sensor, and RTC is all powered from the power supply directly to keep it from robbing power from the arduino 5v pin. which would be hard on it.

What is the power supply? The 5V power on the Arduino comes from the USB port. So it sounds like you do have everything running from the same power source.

Just a cheap 12 volt to 5 volt converter I bought on amazon. Maybe it's to noisy for the LCD screen and needs a capacitor?

Also the year starts off as 2020 but after a while it become 20206 and I am not sure why.

The count down for hatch days does not seem to work properly either....sigh

If I push the button that should turn the light on and off when the LCD screen is gibberish and frozen it wont turn the light on or off so that tells me the arduino is what it hanging up... meaning the code must be buggy or the power supply is crappy?

I get a random number beside the year when the humidity relay kicks on.