Notifications
Clear all

Why?

3 Posts
3 Users
0 Likes
1,945 Views
somewhereinusa
(@somewhereinusa)
Member
Joined: 4 years ago
Posts: 16
Topic starter  
I just finished a project that is finally installed and operating correctly.  I had a bit of code that was giving me fits. The part that was giving me trouble was this. 
 
[code]  if (temperature8 <= heat_set) {
    Serial.println("Heat Relay:  ON");
    digitalWrite(relay_4, HIGH);
    delay(500);
  }
  if (temperature8 >= heat_set + 4) {
 
    Serial.println("Heat Relay:  OFF");
    digitalWrite(relay_4, LOW);
    delay(500);
  }[/code]
 
Basically it says turn on a relay below 36 degrees and turn it off at 40.  I was using the serial monitor to do the testing and thought that it wasn't working right because  at any temp between 36 and 40 the serial monitor would show nothing for the relay. It would show the temp but, the line for relay would be blank.  It took me 4 days to figure out that the pinout on the board was doing exactly what I was asking it to. I also have a log file that puts things into a csv file for a spreadsheet.  If it leaves out an entry it messes up the whole file because a comma and a println is missing. Once I figured out there wasn't really a problem it was just a matter of telling the logfile to just turn "ON/OFF" at 36.
 
My question is why doesn't the serial monitor show the same thing as what the pinout does?

   
Quote
Ruplicator
(@ruplicator)
Member
Joined: 4 years ago
Posts: 127
 

If I understand your question (and I may not), the Serial.print does not set any variables it only prints out a line on the monitor when the function is called and the code doesn't show any Serial.println  when the temperature is in the mid range.

If you had used a variable such as "bool Heat_on" and set that variable to the current state of the heating relay each time it changed you would have been able to use

if( Heat_on) Serial.println("Heat Relay: On");

else Serial.println("Heat Relay: Off");

 


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1112
 

If heat_set = 36  and temperature8 = 37 then of course nothing will print and no digitalWrite will take place.  However, what the initial position of the relay_4 pin is before the if statements shown has not been revealed and maybe the cause of the confusion?


   
ReplyQuote