Thermostat logic help, simple

Hello,

I'm using my arduino to control a fan when the humidity drops below a certain point.

Currently my logic is this with humidity measured every 30 seconds:

if (humidity < 65)
  {
    digitalWrite(transistorPin, HIGH);
  }
  else
  {
    digitalWrite(transistorPin, LOW);
  }

This is nice because it maints a rock solid 65%, but the fans run almost every 30 seconds which i want to avoid.

I'd like the fans to run more efficently like a furnace in a home where it mantains a range, say turn on when temp < 65* and off when >=68*. This seems very simple but I am not sure how to approach it in C.

Any advice is appreciated!

Thanks,
Jacob

Wouldn't it be just

if (humidity < 65)
  {
    digitalWrite(transistorPin, HIGH);
  }
  else if (humidity >= 68)
  {
    digitalWrite(transistorPin, LOW);
  }

Thanks!

Given your code, the pin would not go LOW at say, 66?

That's right.
IT will turn on when humidity drops below 65 and then stay on until humidity exceeds 68, and then turn off.