Hello,
I'm using an ESP32 to control a freezer. The ON/OFF of the freezer depends on two sensors, a digital Flow sensor and a pressure sensor. If Flow sensor is high OR the pressure sensor is higher than a value, the freezer must switch ON. If both conditions are to OFF, the device should remain OFF. Once it is switched ON, there is a delay to switch OFF (actually two delays because switching OFF depends on two relays one after the other).
I log the switching ON and OFF in an array.
The weird point to me is that the log contains more OFF switchings than ON switchings. Maybe it's something obvious that I don't see, but to me the code is OK.
I reboot the device every 5 hours so the millis() don't return to 0.
What do you think the issue is to get more OFFs than ONs in the log?
void Operations::HandleAutomaticCompressor()
{
Flowsensor = digitalAverageRead(FLOW);
if ((Flowsensor==HIGH)||(Pressure>_pressureToOn))
{
_triggerCooling = millis() + (_delay_off_cooling_seconds*1000);
if (IsCompressorON==false)
{
FifoEnqueue("Compressor ON. Flow "+ String(Flowsensor)+" Pressure "+ String(Pressure));
}
IsCompressorON = true;
}
if (millis()<_triggerCooling )
{
digitalWrite(RELAY_COMPRESSOR, HIGH);
digitalWrite(RELAY_COOLING,HIGH);
}
else
{
digitalWrite(RELAY_COOLING,LOW);
}
if (millis()>(_triggerCooling + _delay_compressor_secs*1000))
{
if (IsCompressorON == true)
{
FifoEnqueue("Compressor OFF");
}
IsCompressorON = false;
digitalWrite(RELAY_COMPRESSOR, LOW);
}
}