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
#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
}