// Arduino PID built-in-example -- Basic.ino
// 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);
}
Loading chip...chip-analog-rcfilter
Smoother
Loading chip...chip-opamp
Plant
Disturbance
ScopeBreakout
Variables: Process Disturbance CV(smooth) CV/PID Out