# controlling pressure using PID

**URL:** <https://forum.arduino.cc/t/controlling-pressure-using-pid/386157>\
**Category:** General Guidance\
**Created:** [May 16, 2016, 2:38am UTC](https://forum.arduino.cc/t/controlling-pressure-using-pid/386157 "2016-05-16T02:38:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mar\_nia](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@mar\_nia](https://forum.arduino.cc/u/mar_nia)\
**Post date:** [May 16, 2016, 2:38am UTC](https://forum.arduino.cc/t/controlling-pressure-using-pid/386157/1 "2016-05-16T02:38:48Z")

</div>

Hi

The objective of my project is the user can control the pressure from air pump to cuff.  
It range in 0-130mmHg. The target pressure is defined by the setpoint variable.

And I want the setpoint to change over time.If the any idea to alter the code?

Thanks

---

<div class="post-metadata">

**Author:** ![dave-in-nj](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@dave-in-nj](https://forum.arduino.cc/u/dave-in-nj)\
**Post date:** [May 16, 2016, 2:44am UTC](https://forum.arduino.cc/t/controlling-pressure-using-pid/386157/2 "2016-05-16T02:44:17Z")

</div>

what code ?

---

<div class="post-metadata">

**Author:** ![mar\_nia](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@mar\_nia](https://forum.arduino.cc/u/mar_nia)\
**Post date:** [May 16, 2016, 2:56am UTC](https://forum.arduino.cc/t/controlling-pressure-using-pid/386157/3 "2016-05-16T02:56:20Z")

</div>

```cpp
#include <PID_v1.h>

const int analogInPin = A0;  // Analog input pin 
int sensorValue = 0;         // value read from the pressure sensor via the amplifier stage
float outputValue = 0;            
int motor_pin = 5;

double Setpoint, Input, Output;

//Define Initial PID Terms
double Kp = 2;
double Ki = 5;
double Kd = 1;

//Specify the initial tuning parameters
PID myPID(&Input, &Output, &Setpoint,Kp,Ki,Kd, DIRECT);

void setup()
{
Serial.begin(9600);  
pinMode(motor_pin,OUTPUT);

//Setpoint =  ;                                     

myPID.SetSampleTime(200);               // Initialise sample rate in ms (200ms default)
myPID.SetOutputLimits(0, 255);         // Initialise Output range - 0 to 255 suitable for AnalogWrite
myPID.SetMode(AUTOMATIC);            // Turn the PID on
}

void loop()
{
  // read the analog in value:
 sensorValue = analogRead(analogInPin);            
 outputValue = map(sensorValue, 10, 1023, 0, 100); //The zero value of sensor is around 10
 
 // print the results to the serial monitor:
 Serial.print("sensor = " );                       
 Serial.print(sensorValue);      
 Serial.print("\toutput = ");      
 Serial.println(outputValue); 
myPID.Compute();                                    // Compute output using PID terms
analogWrite(motor_pin, Output);          // PWM output
}

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 5:51pm UTC](https://forum.arduino.cc/t/controlling-pressure-using-pid/386157/4 "2021-05-05T17:51:49Z")

</div>

Closed on May 5, 2021, 5:51pm UTC


