I got it to work as per the example in the original post, depending on how you define “work”. The LED flashed as I turned a pot I put on A0.

I also try to use serial communication to inspect what’s going on but if I use Serial object board stop working and nothing will be sent to serial monitor.

I didn’t find that, adding serial messages helped. This is the code with debugging prints:

```
/********************************************************
* PID Basic Example
* Reading analog input 0 to control analog PWM output 3
********************************************************/
#include <PID_v1.h>
#include <Streaming.h>
//Define Variables we'll be connecting to
double Setpoint, Input, Output;
//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT);
void setup()
{
//initialize the variables we're linked to
Input = analogRead(0);
Setpoint = 100;
//turn the PID on
myPID.SetMode(AUTOMATIC);
myPID.SetOutputLimits(-128, 127);
Serial.begin (115200);
Serial << "Starting ..." << endl;
}
void loop()
{
Input = analogRead(0);
myPID.Compute();
analogWrite(3,Output + 128);
Serial << "Input: " << Input << " Setpoint: " << Setpoint << " Output: " << Output << endl;
delay (500);
}
```

I had an LED (and resistor) on pin D3. I had a pot wiper on A0, and the other ends of the pot on +5V and Gnd.

I added this line:

```
myPID.SetOutputLimits(-128, 127);
```

Otherwise I don’t see how it could “throttle back” when required. However maybe I just don’t understand PIDs.

However this is the strange part …

With the pot carefully adjusted to give around 100 this was the debugging output:

```
Input: 92.00 Setpoint: 100.00 Output: 2.00
Input: 92.00 Setpoint: 100.00 Output: -104.00
Input: 78.00 Setpoint: 100.00 Output: 75.00
Input: 78.00 Setpoint: 100.00 Output: -54.00
Input: 79.00 Setpoint: 100.00 Output: -55.50
Input: 80.00 Setpoint: 100.00 Output: -47.50
Input: 80.00 Setpoint: 100.00 Output: -27.50
Input: 80.00 Setpoint: 100.00 Output: -17.50
Input: 82.00 Setpoint: 100.00 Output: -32.50
Input: 81.00 Setpoint: 100.00 Output: 9.00
Input: 81.00 Setpoint: 100.00 Output: 8.50
Input: 81.00 Setpoint: 100.00 Output: 18.00
Input: 81.00 Setpoint: 100.00 Output: 27.50
Input: 81.00 Setpoint: 100.00 Output: 37.00
Input: 81.00 Setpoint: 100.00 Output: 46.50
Input: 81.00 Setpoint: 100.00 Output: 56.00
Input: 80.00 Setpoint: 100.00 Output: 78.00
Input: 81.00 Setpoint: 100.00 Output: 65.50
Input: 95.00 Setpoint: 100.00 Output: -90.00
Input: 95.00 Setpoint: 100.00 Output: 52.50
Input: 96.00 Setpoint: 100.00 Output: 42.50
Input: 97.00 Setpoint: 100.00 Output: 42.00
Input: 97.00 Setpoint: 100.00 Output: 53.50
Input: 100.00 Setpoint: 100.00 Output: 17.50
Input: 102.00 Setpoint: 100.00 Output: 22.50
Input: 100.00 Setpoint: 100.00 Output: 66.50
Input: 101.00 Setpoint: 100.00 Output: 34.00
Input: 102.00 Setpoint: 100.00 Output: 31.00
Input: 102.00 Setpoint: 100.00 Output: 40.00
Input: 101.00 Setpoint: 100.00 Output: 51.50
Input: 102.00 Setpoint: 100.00 Output: 28.50
Input: 101.00 Setpoint: 100.00 Output: 50.00
Input: 101.00 Setpoint: 100.00 Output: 39.50
Input: 100.00 Setpoint: 100.00 Output: 51.50
Input: 101.00 Setpoint: 100.00 Output: 29.00
Input: 101.00 Setpoint: 100.00 Output: 38.50
Input: 100.00 Setpoint: 100.00 Output: 50.50
Input: 101.00 Setpoint: 100.00 Output: 28.00
Input: 100.00 Setpoint: 100.00 Output: 50.00
Input: 100.00 Setpoint: 100.00 Output: 40.00
Input: 100.00 Setpoint: 100.00 Output: 40.00
Input: 101.00 Setpoint: 100.00 Output: 27.50
Input: 101.00 Setpoint: 100.00 Output: 37.00
Input: 101.00 Setpoint: 100.00 Output: 36.50
Input: 100.00 Setpoint: 100.00 Output: 48.50
Input: 101.00 Setpoint: 100.00 Output: 26.00
Input: 100.00 Setpoint: 100.00 Output: 48.00
Input: 100.00 Setpoint: 100.00 Output: 38.00
Input: 101.00 Setpoint: 100.00 Output: 25.50
Input: 101.00 Setpoint: 100.00 Output: 35.00
Input: 100.00 Setpoint: 100.00 Output: 47.00
Input: 100.00 Setpoint: 100.00 Output: 37.00
Input: 100.00 Setpoint: 100.00 Output: 37.00
Input: 100.00 Setpoint: 100.00 Output: 37.00
Input: 101.00 Setpoint: 100.00 Output: 24.50
Input: 101.00 Setpoint: 100.00 Output: 34.00
Input: 100.00 Setpoint: 100.00 Output: 46.00
Input: 100.00 Setpoint: 100.00 Output: 36.00
```

I confess I don’t understand why the output varies all over the place when the input is practically the same (or is exactly the same) as the set point.

Eventually (quite a while later) it settled down to outputting -128:

```
Input: 100.00 Setpoint: 100.00 Output: -107.00
Input: 100.00 Setpoint: 100.00 Output: -117.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -120.00
Input: 100.00 Setpoint: 100.00 Output: -108.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 100.00 Setpoint: 100.00 Output: -108.50
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 100.00 Setpoint: 100.00 Output: -109.00
Input: 100.00 Setpoint: 100.00 Output: -119.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -122.00
Input: 101.00 Setpoint: 100.00 Output: -122.50
Input: 101.00 Setpoint: 100.00 Output: -123.00
Input: 101.00 Setpoint: 100.00 Output: -123.50
Input: 101.00 Setpoint: 100.00 Output: -124.00
Input: 101.00 Setpoint: 100.00 Output: -124.50
Input: 101.00 Setpoint: 100.00 Output: -125.00
Input: 101.00 Setpoint: 100.00 Output: -125.50
Input: 100.00 Setpoint: 100.00 Output: -113.50
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -126.50
Input: 100.00 Setpoint: 100.00 Output: -114.50
Input: 100.00 Setpoint: 100.00 Output: -124.50
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -127.50
Input: 100.00 Setpoint: 100.00 Output: -115.50
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 100.00 Setpoint: 100.00 Output: -116.00
Input: 100.00 Setpoint: 100.00 Output: -126.00
Input: 100.00 Setpoint: 100.00 Output: -126.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 100.00 Setpoint: 100.00 Output: -116.50
Input: 100.00 Setpoint: 100.00 Output: -126.50
Input: 100.00 Setpoint: 100.00 Output: -126.50
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 100.00 Setpoint: 100.00 Output: -118.00
Input: 100.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 100.00 Setpoint: 100.00 Output: -118.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 100.00 Setpoint: 100.00 Output: -118.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 100.00 Setpoint: 100.00 Output: -118.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 100.00 Setpoint: 100.00 Output: -118.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 100.00 Setpoint: 100.00 Output: -118.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 100.00 Setpoint: 100.00 Output: -118.00
Input: 100.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 100.00 Setpoint: 100.00 Output: -118.00
Input: 100.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 100.00 Setpoint: 100.00 Output: -118.00
Input: 100.00 Setpoint: 100.00 Output: -128.00
Input: 100.00 Setpoint: 100.00 Output: -128.00
Input: 101.00 Setpoint: 100.00 Output: -128.00
Input: 100.00 Setpoint: 100.00 Output: -118.00
```

Maybe the parameters aren’t right, but I wouldn’t want this controlling my car.