Pressure sensor needs to detect compressor cutoff

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;
}
}
}
/>

Please edit your post to use code tags instead of quote tags. Also, post ALL the code, rather than a snippet.

If you put restriction it in the line to the pressure transducer and mount remotely from it , it will help with pressure noise .

It might help to say why you want to do this , what are you trying to show - couldn’t you just detect the motor running for example .

Hammy is correct but also add an accumulator on the sensing side of the restriction. if sized correctly it will get rid of the vibration (pulcing) you are seeing in your measurements.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.