/*
Control PID
*/
#include <PID_v1.h>
const int SENSOR = A0;
const int SALIDA = 3;
//Define Variables we'll be connecting to
double setPoint, input, output;
//Specify the links and initial tuning parameters
double Kp=2, Ki=5, Kd=1;
PID myPID(&input, &output, &setPoint, Kp, Ki, Kd, DIRECT);
void setup()
{
//initialize the variables we're linked to
input = analogRead(SENSOR);
setPoint = 100;
//turn the PID on
myPID.SetMode(AUTOMATIC);
Serial.begin(9600);
}
void loop() {
input = analogRead(SENSOR);
myPID.Compute();
analogWrite(SALIDA, output);
Serial.print("SetPoint: ");
Serial.print(setPoint);
Serial.print("\tInput: ");
Serial.print(input);
Serial.print("\tOutput: ");
Serial.println(output);
}