Conflict between serial monitor and pin state

I have a sketch that among other things tests a DHT22 sensor for fahrenheit and humidity, and based on preset high and low values, the respective pin with LED is to trigger high or low. Also in the code, I have a Serial.print to display some text when the condition is true, but for some reason when the condition becomes false, the serial monitor doesn’t display the text, but the pin remains HIGH. Is the 10% difference in my high and low values causing the shift in performance, or am I just testing the condition incorrectly?

#define hiHum = 50;
#define lowHum = 40;
#define Relay_D  33  // relay 4 - Mega Pin 33
#define TURN_ON 1 // TURN_ON and TURN_OFF may need to swich values to work properly
#define TURN_OFF 0 // Used to switch relay states for on/off of AC devices

  if (h >= hiHum) 
  {
    digitalWrite(Relay_D, TURN_ON);  // (dehumidifier)
    Serial.print("\t");
    Serial.print(F("Drying the air!"));  
    Serial.println("\t");
  }
  else if (h <= lowHum)
  {
    digitalWrite(Relay_D, TURN_OFF);  
  }

In the above code, the “if” statement is the defining factor for both the Serial.print and the digitalWrite. So why does the Serial.print no longer display to the serial monitor, but the digitalWrite remains HIGH?

I am using a Freetronics EtherMega.

#define hiHum = 50;

define statements do NOT have = signs OR ; at the end.

Posting ALL of the code that actually compiles is the ONLY way that you are going to get help.

PaulS:

#define hiHum = 50;

#define statements do NOT have = signs OR ; at the end.

Posting ALL of the code that actually compiles is the ONLY way that you are going to get help.

Thanks for the tip about #define. I will change that in my code, but as it stands, it compiles and uploads, but perhaps the corrected changes will make things run more smoothly?

For some reason I am not seeing the attachments icon so I will create a github account and try to get my sketch there.

Sorry, I think I needed to click reply at the bottom of the page to see the attachments. Here’s my sketch (not yet corrected). Thanks for the help!

Phase_1_-_0.3.ino (8.69 KB)

For sketches/attachments use: |500x165

For images use: http://imgur.com/

LarryD: For sketches/attachments use:

For images use: http://imgur.com/

When you click "Quote", for some reason the attachments icon isn't visible.

|500x226

Maybe try a different browser.

It isn't clear what you intend your program to do, with values between 40 and 50.

Also, digitalWrite( ) expects the keywords HIGH and LOW, and there is not really a good reason to re-define them.

michinyon: It isn't clear what you intend your program to do, with values between 40 and 50.

Also, digitalWrite( ) expects the keywords HIGH and LOW, and there is not really a good reason to re-define them.

I will change the commands back to HIGH or LOW, but I previously tried that to see if that might resolve the issues, and it didn't. I am also now noticing that my Feed Time block is only producing brief pulses of HIGH rather than a constant HIGH for 10 minutes. It's been a few days since I got the EtherMega and I have cleaned up the code a bit since so I will test the sketch on the Mega with no shield to see if the issue is maybe in the EtherMega.

My sketch is a work in progress that I intend to add a lot more functionality into. This is just what I am calling phase 1, and I am learning mostly everything as I go. Phase 1 is to consist of a Mega with Ethernet, an RTC to keep time, a DHT22 temp/humidity sensor and an 8 channel relay that is successively connected to 8 duplex AC outlets to control AC powered on/off devices that are being used in my indoor garden. My project will be like [Billies Hydroponics Controller/i][/b], but I want all data to POST to my PHP website. So obviously my sketch is needing networking, but I don't want to open that can of worms till I get the sketch debugged and proof read. I may also be wanting on/off buttons added to my site to manually actuate my relays via the internet. I am still Googling my a$$ off looking for the best possible information that will reveal to me the best possible plan to build that infrastructure. Because I would also have to learn a lot of HTML/PHP language, on top of also learning Arduino code, I opted to build my site through wordpress to save me from having that immediate need. So now I am trying to link my project to my page in an agreeable manner with WP, and I can defer the need of learning those languages to the future. I feel my understanding is nearing a level of comfort that I can begin planning the best network, but I still have a bit more reading to do on the subject, but first I want what I have debugged.

but for some reason when the condition becomes false, the serial monitor doesn't display the text, but the pin remains HIGH.

"but for some reason", that is EXACTLY what the code you wrote, instructed it to do.

When the humidity goes over 50, you turn the relay on and start writing messages each time through the loop.

When the humidity goes below 50, you do NOTHING, and the relay stays on.

When the humidity finally gets down to 40, which might take days, you turn the relay off.

My confusion to that matter stems from the fact that the test controls both the digitalWrite and the Serial.print. Because those are blocked in the same list of commands, both executed upon a specific condition, how is it that one can deviate and not the other? There is no place in my code that I can see that would permit the digital pin to remain high, while not displaying the text in the serial monitor. If there is an error that would cause a deviation, please outline so I can make the correction and more importantly, learn why.

TYIA