Relays and Temp

New to this and this is the first project I'm attempting to do.... all be it somewhat a combination of many samples and such I've found online. What I have done so far is to make a sketch that will turn on a relay if the temperature is below my set point, and turn on an LED is the temp is above another set point, while displaying the temp on an LCD screen. This works, but the problem I'm having is that when the temp is right at my lower set point (74F) the relay is triggering on/off very quickly... this would I fear cause problems for the high voltage heater I wish to run off of it. What I would like to do is have the relay stay high (when triggered) for 30-90 seconds, and/or keep it from triggering again for the same length of time.... smoothen it out a bit. I've been looking at setting time delays in millis(), but have not found anything to help me understand how to adapt this type of timing to my needs, or if this is even the best way to go about doing this. I don't know if it matters, but what I am using is an Arduino Nano, DS18b20 Temp sensor, SR1y relay and a 2X16 I2C display on breadboard now. Any help would be appreciated in pointing me in the right direction to getting this done. Thank you.

the problem I'm having is that when the temp is right at my lower set point (74F) the relay is triggering on/off very quickly..

It sounds like you need to introduce some hysteresis. Turn the relay on at the low temperature point but turn it off at a slightly higher temperature. This will prevent it cycling quickly between on and off.

Consider that solution and if you still want to use a fixed on time let us know and we will help.

Thank you UKHeliBOb, I saw I’m limited to posts per time limit, so I’ll respond as I am allowed.

Maybe I’m not understanding how this would be different than what I have now, or didn’t explain it fully ( Forget not everyone’s looking at my screen! LOL), but I’ve got it set as is.

if (temp<=74.00){
digitalWrite (relay, HIGH) ;
} else {
digitalWrite (relay, LOW) ;
}

Would this do the same as it’s only to turn on at 74 or lower?
The problem or situation I’m encountering is when the temp “bounces” for lack of a better wording between something over 74 (relay off) and at or lower than 74 (relay on).

I suppose I could add a 30-90 second delay in the loop, but liked the temp being in real time, and have heard how DELAY is not the best option for programming.

It’s ultimately going to control a heater in a fish tank, so IDK, not knowing what is all involved in coding a time delay, I’m also wondering if it’s worth it or if a delay is the best bet. Any pros/cons to either that would make one option over the other?

david1975:
Thank you UKHeliBOb, I saw I’m limited to posts per time limit, so I’ll respond as I am allowed.

Just make a couple of more post (but no useless posts) and the time limit is lifted. It’s one of the anti-spam measures :wink:

david1975:
The problem or situation I’m encountering is when the temp “bounces” for lack of a better wording between something over 74 (relay off) and at or lower than 74 (relay on).

Correct, so add room for that bounce :wink: Something like:

if (temp <= 74.00){
    digitalWrite (relay, HIGH) ;
  } else if(temp >= 75){
    digitalWrite (relay, LOW) ;
  }

david1975:
and have heard how DELAY is not the best option for programming.

Again correct. In my opinion chapter two (after one being Blink) of every Arduino tutorial should be called “Now NEVER use delay() again!” :wink:

septillion:
Just make a couple of more post (but no useless posts) and the time limit is lifted. It’s one of the anti-spam measures :wink:

It’s a love hate thing… But I completely understand it and wish some sites had striker/harsher measures.

septillion:
Correct, so add room for that bounce :wink: Something like:

if (temp <= 74.00){

digitalWrite (relay, HIGH) ;
  } else if(temp >= 75){
    digitalWrite (relay, LOW) ;
  }

This worked perfectly! I’m assuming that if I should experience any more bounce when in the water, I can just adjust the 2 temps to help eliminate it.

septillion:
In my opinion chapter two (after one being Blink) of every Arduino tutorial should be called “Now NEVER use delay() again!” :wink:

I laughed at this… I think one of those lessons and videos I worked though should be retitled to this! :grinning:

I decided to try to make this, and got the idea this, after seeing a post on a Facebook group about Arduino… shortly after I had a heater malfunction and go closed loop all day (while I was gone). Came home to a 90+ degree tank and all the fish “cooked”. Thought this might prevent or help prevent this from happening again…

Thank you for your help, I know I’d still be on google scratching me head without your help.

I'm assuming that if I should experience any more bounce when in the water, I can just adjust the 2 temps to help eliminate it.

That's right, but if anything I suspect that when in the water the "bounce" effect will be less anyway because of the thermal inertia of the water which will slow down the rate of change of temperature.

I think your probably correct in that, the digital thermometer I have in there now only does tenths of a degree, and I don’t think I’ve really see that bounce all too much.

Now for an enclosure and then… a lighting project I found while researching all of this. Think I might have found a fun and useful hobby :slight_smile: