Vacuum pump control logic

Hello!

I'm trying to figure out the program logic of a vacuum pump controller. The task is quite easy:

  1. I have a bag with atmospheric pressure
  2. I turn the vacuum pump on and I measure the pressure
  3. I reach the maximum needed vacuum (Poff on the graph) and I turn off the vacuum pump
  4. time is passing by and the pressure increases, I have to turn on the pump at Pon until the pressure reaches Poff again.

That's it. I have all the HW working fine But I can't figure out the programming logic. I tried a do while cycle but I miss something.

Can you please help me what would be the program logic/structure?

vacpump

Neither can anyone else with what you have written. Please list the hardware pieces you have an a schematic of how you have them all connected, including all the power supplies.
Then show the software you have tried.

You need to keep track of whether the pump is ON or OFF.

You can use a boolean variable for that.
boolean isPumping = false;

Then you need a couple of variables to hold the Poff and Pon values.

uint16_t pressureOn      = 100;
uint16_t pressureOff     = 150;

Then just need to check the current pressure each loop and add some simple logic about what to do... Something like:

int      SENSOR_PIN       = A0;
int      PUMP_PIN         = 2;
boolean  isPumping        = false;

uint16_t pressureOn      = 100;
uint16_t pressureOff     = 150;
uint16_t currentPressure = 0;

void setup()
{
  pinMode (PUMP_PIN, OUTPUT);
}

void loop()
{
  currentPressure = analogRead(SENSOR_PIN); // Get the current pressure from the sensor.

  if (isPumping)                            // Is the pump on?
  {
    if (currentPressure > pressureOff)      // Have we reached Poff?
    {
      isPumping = false;                    // Turn the pump off.
      digitalWrite(PUMP_PIN, LOW);
    }
  }
  else                                      // Pump is off.
  {
    if (currentPressure < pressureOn)       // Have we dropped below Pon?
    {
      isPumping = true;                     // Turn the pump on.
      digitalWrite(PUMP_PIN, HIGH);
    }
  }
}

Dear red_car,

thank you very much for your fast and good reply!
Tested and working well!

void setup()
{
}

void loop()
{
  // I reach the maximum needed vacuum 
  // (Poff on the graph) and I turn off the 
  // vacuum pump
  if (getVacuum() > Poff)
    VacuumPumpOff();

  // time is passing by and the pressure increases, I 
  // have to turn on the pump at Pon
  if (getVacuum() < Pon)
    VacuumPumpOn();
}

@johnwasser offers a short version.

@red_car's solution avoids constantly turning on a pump that is already on, or off one that has already been turned off.

It may not matter the difference. But if there was something special about firing up the pump you didn't want to or need to or perhaps even shouldn't do again, or a similar function of Turing off powering down the pump, take the longer version that doesn't.

Or consider the current state of the pump within the functions VacuumPumpOn() and VacuumPumpOff() and act accordianly.

a7

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