Need some help with DHT22 Sensor

I’m in need of some assistance. Attached is the full code (its a variation of Billy’s Aquaponics Controller). I sliced it and diced it and am using it as a base. I have a ton of work to do it and its very rough. Problem is- I’m new at Arduino so biting off more than I can chew. My hope is to dissect this and get it straight a piece at a time. I spent a great deal of time getting libraries and such right so it compiles and have fixed quite a few errors. Problem I am having now is with the DHT22 sensor. If I load code with nothing but the sensor (ie the example in IDE), it works fine. I even stripped everything off the attached code and left just the sensor and the “main_scr” code and it works. When I attempt to do anything else (ie add it to more code), I get Zeros for T/H. I’m not getting errors so I think this is a timing issue. Is there a better library or better way of pulling temp and humidity? I do have a 10K resistor on it. Any help is greatly appreciated.

ACL_05182017.ino (35.4 KB)

Please post your example of "anything else" on top of the basic example sketch, that is causing the problem. It's a thousand times simpler than trying to plow through a massive aquarium sketch.

I hear ya aarg and thanks for the reply. The attached (working DHT txt) works. If I add anything to it, I get zeros (I mean anything). I think the DHT sensor is slow (2ms response) so it must be a timing issue. Maybe I need a [while] statement or something; IDK. I have a long way to go with making this work and am under the gun (comparing soil, hydroponics and aquaponics; its another story all together and happy to share at some point). I know exactly what I want to do and only have skills in Andover Control language (Andover Plain English). Problem is I have a huge language barrier/ gap and much to learn Arduino and C++. Hopefully this clarifies a bit but the rest of code (in first post) is arbitrary (just an example which needs a ton of work) so just trying to concentrate on the DHT. I’m not certain if I should be using digital.write and with array or what. When temp and humid are pulled and saved to TempC and RelHumid (floating) are these volatile and short lived? Should I be saving these to eeprom addresses instead?

DHT Working Code.txt (6.45 KB)

delayMS is defined in setup(), it's not visible in loop(). EDIT: Nevermind, I just spotted it in globals. :blush:

Usmc124: I hear ya aarg and thanks for the reply.

You're welcome and I'm glad you hear me, but you didn't post a non-working example as requested.

I did some more testing and found that moving the DHT22 from pin 50 to pin 7 resolved the issue. Apparently I can run one process on Pin 50 but as soon as I add more into the loop, it would fail to read. On pin 7 there is no issue. Not sure why but there it is. Of note: I intended to buy an Uno and Mega directly from Arduino to avoid the clones. Unfortunately they had no stock on the Mega so went with a clone. I'm wondering if that's adding to the complexity. ive had not problems with the Uno. Thoughts?

Not sure why but there it is.

You'd need to look at all the libraries that you use. Do any of them use SPI to communicate with the hardware that they work with? That is the only reason I can think of that pin 50 would cause you problems.

I see that you use SD, which DOES use SPI.

That's good to know. The SD function does not work either; was planning on tackling that soon.

Usmc124: That's good to know. The SD function does not work either; was planning on tackling that soon.

Doesn't work? Or, didn't work when the DHT22 sensors were on the SPI pin?