// Arduino PID built-in-example -- Basic.ino
// Manual control -- You are the process.
// raise or lower the slider depending on the PID
// calling for "heating" or "cooling" with the PWM
// of the LEDs.
//
// Built from Basic.ino RC/OPAMP process example:
// https://wokwi.com/projects/412042610362971137
//
// Code from https://github.com/br3ttb/Arduino-PID-Library/blob/master/examples/PID_Basic/PID_Basic.ino
//
// This uses a RC filter and op-amp to act as the
// plant controlled by a PID
//
// It uses these Wokwi custom chips:
// custom-chip-RCfilter.ino
// https://wokwi.com/projects/409325290405496833
// Built from
// https://wokwi.com/projects/409325290405496833
// and https://github.com/drf5n/Wokwi-Chip-RCfilter
// and the op-amp
//
// See also:
// https://wokwi.com/projects/412997833205485569 -- PID_basic.ino with slider
// https://wokwi.com/projects/412042610362971137 -- PID_Basic.ino
// https://wokwi.com/projects/410423413759806465 -- PID_Relay.ino with slider
// https://wokwi.com/projects/411487751748467713 -- PID_AdaptiveTunings.ino
//
//
/********************************************************
* PID Basic Example
* Reading analog input 0 to control analog PWM output 3
********************************************************/
#include <PID_v1.h>
#define PIN_INPUT 0
#define PIN_OUTPUT 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(PIN_INPUT);
Setpoint = 100;
//turn the PID on
myPID.SetMode(AUTOMATIC);
}
void loop()
{
Input = analogRead(PIN_INPUT);
myPID.Compute();
analogWrite(PIN_OUTPUT, Output);
}
Smoother
You are the process. Respond to the PID by
sliding the "Process" slider toward the light
Add disturbances by moving the slider & see
how the PID responds.
+ More
- Less
Variables:
Process
CV(smooth)
CV/PID Out