Water pump control hysteresis I'm using arduino with analog pressure sensor, temperature sensor and a relay to control water pump. The simple code I wrote works, but I want better control. 

#include &lt;OneWire.h&gt;
#include &lt;DallasTemperature.h&gt;

 const int pinCidlaDS = 2;
 int pinA0 = A0;
 int teplota;
 int rele;
 float tlak = 0;  //ideal 290+-

OneWire oneWireDS(pinCidlaDS);
DallasTemperature senzoryDS(&amp;oneWireDS);

void setup() {
 senzoryDS.begin();
 rele = 3;
 pinMode(3, OUTPUT);
 Serial.begin(9600);
}

void loop() {
 tlak = analogRead(A0);
 teplota = (senzoryDS.getTempCByIndex(0));
  if ((tlak &lt; 285) &amp;&amp; (teplota &lt; 30)) {
   digitalWrite(rele, LOW);
   delay(7000);
 }
   else {
   digitalWrite(rele, HIGH);
   delay(500);
 };
 Serial.print("Tlak: ");
 Serial.println(tlak);
 Serial.print("Teplota: ");
 senzoryDS.requestTemperatures();
 Serial.print(senzoryDS.getTempCByIndex(0));
 Serial.println(" stupnu Celsia");
 teplota = (senzoryDS.getTempCByIndex(0));
 delay (200);

}


So now I'm using delay to get away from the treshold value. And I wanted to write a code that would work like: 

Pressure is lower than 'x', relay ON.
Pressure rises to 'Y', relay OFF until Pressure is lower than 'x'.

What should I use? Could you please give me a example, if there is? 
Thank you very much! :)
Implementing hysteresis turns out to be quite straight-forward:

float pressure = read_pressure();
if (pressure &lt; x)
    turn_relay_on();
else if (pressure &gt;= y)
    turn_relay_off();