Arduino process-control library covering the complete control chain from signal conditioning to closed-loop PID control.
Spanish documentation is available in README_ES.md.
PIDControl is organized around a simple process-control workflow:
Signal acquisition
|
v
Signal filtering
|
v
Process identification
|
v
Controller tuning
|
v
Closed-loop control
The library can also be used only as a PID controller without using the filtering, identification or tuning modules.
PIDControlFilters provides reusable filters for conditioning the process variable before it reaches the controller or the identification algorithms.
Available filters:
MovingAverageFilter<N>for random measurement noise.MedianFilter<N>for isolated spikes and outliers.LowPassFilterfor continuous analog noise.ComplementaryFilterfor combining two estimates of the same variable.
Example:
#include <PIDControlFilters.h>
using namespace PIDControlFilters;
MedianFilter<5> median;
LowPassFilter lowPass(1.0);
double pvMedian = median.Update(PVRaw);
double PV = lowPass.Update(pvMedian, dt);A median filter followed by a first-order low-pass filter is useful when the signal contains both isolated spikes and continuous noise.
PIDControl provides two non-blocking identification methods.
StepTest identifies a first-order plus dead-time model and returns:
Kpprocess gainT0dead timeTpprocess time constant
FOPDTModel model = stepTest.GetModel();Engineering ranges can also be defined to calculate normalized process gain:
stepTest.SetOutputLimits(0, 60);
stepTest.SetPVLimits(15, 45);
stepTest.SetOutputRange(0, 100);
stepTest.SetPVRange(0, 80);KpNormalized = Kp * OPspan / PVspan
The safety limits used during the test are deliberately separated from the full engineering ranges.
RelayTest performs a non-blocking relay experiment and returns:
Kuultimate gainTuultimate period
Compact API example:
RelayTestConfig cfg;
cfg.amplitude = 10.0;
cfg.hysteresis = 0.5;
cfg.cycles = 3;
cfg.useCurrentReference = true;
cfg.maxTestTimeMinutes = 15.0;
cfg.outputMin = 20.0;
cfg.outputMax = 60.0;
cfg.pvMin = 15.0;
cfg.pvMax = 48.0;
relay.Start(cfg);PIDTuning converts the identification results into PI or PID tuning proposals.
The library never auto-applies a proposed tuning. The user must apply it explicitly with PIDTuning::Apply() or SetTunings().
FOPDTModel model = stepTest.GetModel();
PIDTuning tuning(model);
PIDTuningResult pi = tuning.IMC_PI(); // default Tf = 2*T0
PIDTuningResult pid = tuning.Lambda_PID(); // default Tf = 2*T0Both tuning methods use Tf as the tuning parameter that determines the desired closed-loop response speed.
Available presets for Tf:
AGGRESSIVE = T0
NORMAL = 2*T0
ROBUST = 3*T0
RelayTestResult r = relay.GetResult();
PIDTuningResult pi =
PIDTuning::TyreusLuybenPI(r.Ku, r.Tu);
PIDTuningResult pid =
PIDTuning::TyreusLuybenPID(r.Ku, r.Tu);PIDControl supports:
- PID, PI-D and I-PD structures
- MAN/AUTO operation
- DIRECT and REVERSE control action
- PV Tracking
- bumpless transfer
- conditional-integration anti-windup
- configurable output limits
- configurable sample time
A minimal controller can be created with:
PIDControl pid(&PV, &OP, &SP, Kc, Ki, Kd);The default configuration is:
Mode MAN
Structure PI_D
Action REVERSE
PV Tracking ON
Output limits 0..100
Sample time 100 ms
A complete declaration can also be used when the configuration must be explicit. Using a named variable for PV Tracking makes the final argument easier to understand:
const bool pvTracking = true;
PIDControl pid(
&PV, &OP, &SP,
Kc, Ki, Kd,
PIDType::PI_D,
PIDAction::REVERSE,
pvTracking
);In this declaration:
PIDType::PI_D controller structure
PIDAction::REVERSE control action
pvTracking = true PV Tracking enabled
Typical loop:
void loop()
{
PV = ReadProcessVariable();
pid.Compute();
WriteOutput(OP);
}PIDControl can be used directly from this point without using the filtering, identification or tuning modules if suitable Kc, Ki and Kd values are already known.
extras/PIDControl_TCLab_UNO_R4_Test_v1.4.2.ino demonstrates the complete chain on Arduino UNO R4 WiFi + TCLab.
The serial interface provides compact identification commands:
STEP(10,2,UP,POS,0.3,60,0.10,0.4,30,0,60,15,45,0,80,0,100)
RELAY(10,0.5,3,CURRENT,15,20,60,15,48)
Stored identification results can be reprinted while they remain in memory:
IDENT
IDENT STEP
IDENT RELAY
See docs/TCLAB_TEST.md for the full command interface.
PIDControlFiltersStepTestRelayTestPIDTuningPIDControl
docs/FILTERS.mddocs/STEP_TEST.mddocs/RELAY_TEST.mddocs/PID_TUNING.mddocs/API.mddocs/TCLAB_TEST.mddocs/TERMINOLOGIA.md
PIDControl is released under the MIT License.
Copyright (c) 2026 Garikoitz Martinez.
