using mills()? aquarium controller... temp sets relay...how to delay?

#include <OneWireTempSensor.h>
#include <Wire.h>
#include "RTClib.h"
#include <OneWire.h>
#include <LiquidCrystal.h>
#include <Time.h>


int DS18S20_Pin = 7; //temp

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

RTC_DS1307 RTC; //timer


OneWire ds(DS18S20_Pin); //temp

void setup(void) {
  
Wire.begin();
RTC.begin();  
lcd.begin(20, 4);
lcd.print("Time :");
pinMode(8, OUTPUT);


}


void loop(void) {
float temperature = getTemp();
float tempF = (temperature * 9.0)/ 5.0 + 32.0;

DateTime now = RTC.now();
  
  lcd.setCursor(7, 0);
     if ( now.hour() < 10) {
      lcd.print("0");
}
     lcd.print(now.hour(), DEC);
    lcd.print(':');
   if ( now.minute() < 10) {
    lcd.print("0");
}
    lcd.print(now.minute(), DEC);
    lcd.print(':');
    if ( now.second() < 10) {
    lcd.print("0");
}
    lcd.print(now.second(), DEC);
          
    lcd.setCursor(0, 1);
    lcd.print("Temp : ");
    lcd.print(tempF);
    lcd.print(" *F ");
    lcd.setCursor(0, 2);
    lcd.print("Temp : ");
    lcd.print(temperature);
    lcd.print(" *C ");

if ( tempF  < 78) {  //This line turns on pin 8 @78F
digitalWrite(8, HIGH);

}
if ( tempF  > 77) {  //This line turns off pin 8 @77F
digitalWrite(8, LOW);

}
}


float getTemp(){
//returns the temperature from one DS18S20 in DEG Celsius

byte data[12];
byte addr[8];

if ( !ds.search(addr)) {
//no more sensors on chain, reset search
ds.reset_search();
return -1000;
}



ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end

byte present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad


for (int i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}

ds.reset_search();

byte MSB = data[1];
byte LSB = data[0];

float tempRead = ((MSB << 8) | LSB); //using two's compliment
float TemperatureSum = tempRead / 16;

return TemperatureSum;

}

Hey there.
I am building an aquarium controller with a thermometer-controlled fan. this bit of code displays time from an RTC and temp on an LCD, and turns pin on and off at 78 degrees. It works, but as the temperature of a tank is very slow to change, the relay just clicks constantly as the program runs. Simply using Delay() is out and following the Blink Without Delay example caused constant clicking of the relay. constant.
So how do I stop the pin from changing more than once a minute?
thnaks!

I just told someone else this last night..

You need a deadband. There's a fancy word for it but all it means is : Turn on at a lower temp than you turn off.

For example :

On temp 76 degrees Off temp 78 degrees

However long it takes to get from 76 to 78 degrees is how long it'll take to switch. You want it longer? Widen the numbers some. Want it shorter? Narrow them some.

-jim lee