Compressor runs, making big noise on the sensor. Even with average of 32 readings and exponential filtering, readings may vary up to 10%.
It is not possible to cut into the compressor, nor to use other sensors like accelerometer or mic to feel if it stopped.
It simply has to be detected with the sensor. I have PX3 Series pressure transducer and Arduino Mega 2560.
analogRead is being compared to see if it had actually stopped pumping air. Pressure drop exists, and can be felt, but maximum pressure sometimes peaks too high. Sometimes it bounces in such a way that the code detects that it cut mid way. Thus +28 used to as threshold.
Code below works, yet sometimes keeps hanging for 10-15 seconds after compressor had stopped.
I am pretty certain that there must be more elegant solution.
<
float smoothsensor(int readTimes){
int i=0;
while(i<readTimes)
{
int RawValue = analogRead(inputPin);
ADCFilter.Filter(RawValue);
readings = readings + RawValue;
i++;
}
average = readings/readTimes;
readings = 0;
return average;
}/>
<
Serial.println("diditstop STARTS");
while ((pressurenow+28) >= maximumpressure)
{
Serial.println("diditstop FIRST CONDITION MAXIMUM PRESSURE IS ");
delay(50);
pressurenow = smoothsensor(numReadings);
maximumpressure = max(maximumpressure, pressurenow);
psidec = topsi(smoothsensor(numReadings));
if (maximumpressure>(pressurenow+28))
{
Serial.println("diditstop SECOND CONDITION adn pressure now is ");
delay(50);
pressurenow = smoothsensor(numReadings);
//loopmap = map(pressurenow, 210, 419, 1500, 4100);
psidec = topsi(smoothsensor(numReadings));
maximumpressII = max(maximumpressII, pressurenow);
Serial.print("maximumpressure = ");
Serial.println(maximumpressure);
float presmaxlaurie = topsi(maximumpressure);
Serial.println(presmaxlaurie);
Serial.println(maximumpressII);
for(j=0; j<10 && maximumpressure==maximumpressII; j++){
Serial.println("diditstop while max==max THIRD CONDITION adn pressure now is ");
delay(50);
pressurenow = smoothsensor(numReadings);
psidec = topsi(smoothsensor(numReadings));
maximumpressII = max(maximumpressII, pressurenow);
Serial.print("maximumpressure ");
Serial.println(maximumpressure);
Serial.print("maximumpressII ");
Serial.println(maximumpressII);
Serial.println(psidec);
Serial.print("j counter is now :");
Serial.println(j);
}
if (j>9) {
return maximumpressure;
}
}
}
/>