Help with signal conditioning

You must determine the first derivative (steepness and direction of the graph) and use that to make your decisions in the code.

That way you do not need to wait until the baseline is reached, you can wait until a certain value is reached.

assuming the signal is analog, give this code a try

int oldval = 0;
int newval = 0;

void setup()
{
  Serial.begin(115200);
  Serial.println("Square breathing 0.1");
}

void loop()
{
  newval = analogRead(A0);  // measure the wind
  int derivative = (newval - oldval);  // first derivative of the signal
  oldval = newval;  // remember previous value

  // OUTPUT CAN BE COPIED TO EXCEL
  Serial.print(millis());
  Serial.print(";");
  Serial.print(oldval);
  Serial.print(";");
  Serial.print(newval);
  Serial.print(";");
  Serial.print(derivative);
  Serial.print(";");

  // SQUARE OUTPUT (% as example)
  if (derivative > 0) Serial.println(100);
  else Serial.println(0);
}

Please post the graph ...