Morning All,
This is my first post on here and I am pretty new to the Arduino.
My problem is I cannot seem to get my code to work to control a proportional relief valve by measuring a pressure sensor.
I have written seperate programs to control the solenoid and read the sensor so I know they are both working but I cannot seem to get the PID control to work, It just outputs the max to my solenoid and maintains.
sensor outputs 0-5v and solenoid is controlled with 0-5v
see code below.
#include <PID_v1.h>
// code to increase pressure to 140 bar in 35 bar increments with 10 second delay inbetween increases before unloading to zero, waiting 20 seconds and repeating.
double Setpoint, Input, Output;
//tuning parameters P,I,D = 2,5,1,
PID myPID(&Input, &Output, &Setpoint, 2, 5, 1, DIRECT);
void setup() {
Input = analogRead(A0);
myPID.SetMode(AUTOMATIC);
}
void loop() {
//reduce P part of controller to slow down pressure increase, fine tune with the I and D parts
Setpoint = 90; //ten bit number for 35 bar assuming full scale 0-400 bar = 0-1023
Input = analogRead(A0); //read input from pressure sensor
myPID.Compute(); //compute relavent output from tuning parameters and sensor reading
analogWrite(5, Output); //send output to propertional valve
delay(10000); //10 second delay
Setpoint = 179; //ten bit number for 70 bar assuming full scale 0-400 bar = 0-1023
Input = analogRead(A0);
myPID.Compute();
analogWrite(5, Output);
delay(10000);
Setpoint = 256; //ten bit number for 100 bar assuming full scale 0-400 bar = 0-1023
Input = analogRead(A0);
myPID.Compute();
analogWrite(5, Output);
delay(10000);
Setpoint = 358; //ten bit number for 140 bar assuming full scale 0-400 bar = 0-1023
Input = analogRead(A0);
myPID.Compute();
analogWrite(5, Output);
delay(10000);
analogWrite(5, 0); //unload to minimum pressure
delay(20000); //20 second delay before restarting
}