Arduino-based Motor Control and Pressure Sensing Converging to Setpoint without Input

Hello Arduino experts,

I am currently working on a project that involves controlling a motor to compress an Ambu bag based on pressure readings from a pressure sensor.I am facing an issue where the system converges to the setpoint pressure even when I detach all mechanisms for the motor to compress the Ambu bag.
Hardware Used:

Arduino Mega
Pressure Sensor
Motor with separate power source
Encoder to measure motor angle

Code Snippets:

Here's a quick look at some code inside the void loop:

    if (inHome == 1)   // runs the motor to the setpoint pressure
      {
       if (pressure < setpointPressure)
        {
         digitalWrite(dir1, HIGH);
         analogWrite(pwm1, lastSpeed);
        }
      }

  if (inHome == 0)  // run the motor to the home position
      {
        if ( angle > setpointAngle) 
         {
          // Go home at a constant speed, say, 190
          digitalWrite(dir1, LOW);
          analogWrite(pwm1, 190);
         }
}

if (inHome == 1 && (pressure >= (setpointPressure + 0.015 * setpointPressure)))
      {
     analogWrite (pwm1, 0); 
        inHome = 0; 
      ... rest of my code
       }

else if (inHome == 0 && abs(angle - setpointAngle) <= 0.05 * setpointAngle) 
      {
       analogWrite (pwm1, 0); 
        inHome = 1;  
       ... rest of my code
      }

Issue:

  • When I set a setpointPressure, the system tries to reach that pressure level.
  • Even when I detach any mechanisms that could affect the pressure sensor (like removing the motor's ability to compress the Ambu bag), the sensor still reads values that converge to setpointPressure.

I'd greatly appreciate any insights you could provide.

Thank you!

Hello Arduino experts,

I am currently working on a project that involves controlling a motor to compress an Ambu bag based on pressure readings from a pressure sensor.I am facing an issue where the system converges to the setpoint pressure even when I detach all mechanisms for the motor to compress the Ambu bag.
Hardware Used:

Arduino Mega
Pressure Sensor
Motor with separate power source
Encoder to measure motor angle

Code Snippets:

Here's a quick look at some code inside the void loop:

    if (inHome == 1)   // runs the motor to the setpoint pressure
      {
       if (pressure < setpointPressure)
        {
         digitalWrite(dir1, HIGH);
         analogWrite(pwm1, lastSpeed);
        }
      }

  if (inHome == 0)  // run the motor to the home position
      {
        if ( angle > setpointAngle) 
         {
          // Go home at a constant speed, say, 190
          digitalWrite(dir1, LOW);
          analogWrite(pwm1, 190);
         }
}

if (inHome == 1 && (pressure >= (setpointPressure + 0.015 * setpointPressure)))
      {
     analogWrite (pwm1, 0); 
        inHome = 0; 
      ... rest of my code
       }

else if (inHome == 0 && abs(angle - setpointAngle) <= 0.05 * setpointAngle) 
      {
       analogWrite (pwm1, 0); 
        inHome = 1;  
       ... rest of my code
      }

Issue:

  • When I set a setpointPressure, the system tries to reach that pressure level.
  • Even when I detach any mechanisms that could affect the pressure sensor (like removing the motor's ability to compress the Ambu bag), the sensor still reads values that converge to setpointPressure.

I'd greatly appreciate any insights you could provide.

Thank you!

The best debugging tool that you have is the serial print. Put some prints in strategic places to monitor program flow and variable values.

When posting code, please post the whole program or a minimal verifiable example. Posting snippets potentially leaves out important information.

Did you develop your program in steps and testing between each additional addition? At what point did the error occur?

post the full code

Interesting project and I wish you luck but this could be construed as a "life support" application. Because of the inherited liability if somebody gets hurt especially using parts that are not approved for life support I will abstain from answering your question.

See my previous response to this similar question. Hello Arduino experts, I am currently working on a project that involves controlling a motor to compress an Ambu bag based on pressure readings from - #2

This could be construed as a "life support" application. Because of the inherited liability if somebody gets hurt especially using parts that are not approved for life support I will abstain from answering your question.

How strange! Two different people describing identical problems in identical wording.

Cross post flagged for moderator

I flagged this as a cross post.

A sock puppet? Bad form, old boy.