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 <OneWire.h>
#include <DallasTemperature.h>
const int pinCidlaDS = 2;
int pinA0 = A0;
int teplota;
int rele;
float tlak = 0; //ideal 290+-
OneWire oneWireDS(pinCidlaDS);
DallasTemperature senzoryDS(&oneWireDS);
void setup() {
senzoryDS.begin();
rele = 3;
pinMode(3, OUTPUT);
Serial.begin(9600);
}
void loop() {
tlak = analogRead(A0);
teplota = (senzoryDS.getTempCByIndex(0));
if ((tlak < 285) && (teplota < 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! :)