PID Controller Calculator – Step Response, Ziegler-Nichols Tuning, PID Simulation
PID Controller Calculator — Step Response Simulation
A PID (Proportional-Integral-Derivative) controller is the most widely used feedback control algorithm in engineering, deployed in virtually every industry that requires automated regulation of a physical quantity — from drone attitude stabilization to temperature control in chemical reactors. This free online PID calculator simulates the closed-loop response of a first-order plant under PID control, computing five performance metrics (rise time, settling time, overshoot, steady-state error, peak output) and rendering the response as an interactive SVG graph. All computation runs in WebAssembly directly in your browser — no server, no installation, no data upload.
Enter your PID gains (Kp, Ki, Kd) and choose one of four input types: Step (unit step to test transient response), Ramp (linearly rising setpoint to test velocity tracking), Sine (sinusoidal reference to test bandwidth), or Square wave (periodic step for repetitive stability assessment). In Advanced mode, configure the plant gain K and time constant τ to match your real system. The Ziegler-Nichols reference table provides starting-point gain formulas computed from the ultimate gain Ku and ultimate period Tu — toggle it below the results grid.
The simulation uses Euler integration with a fixed timestep of dt = 0.01 s and a maximum of 10,000 steps (100 s equivalent). For simulations with more than 500 display points, the curve is subsampled uniformly to maintain rendering performance while preserving the true peak and settling behavior.
The PID Control Law — How It Works
The PID controller computes a control signal u(t) as the weighted sum of three terms, each responding to a different aspect of the error signal e(t) = setpoint(t) − output(t):
u(t) = Kp·e(t) + Ki·∫e(t)dt + Kd·de(t)/dt
Discrete-time implementation (firmware / this simulator):
error = setpoint - y
integral += error * dt
derivative = (error - prev_error) / dt
u = Kp*error + Ki*integral + Kd*derivative
prev_error = error
Proportional Term — P
The proportional term Kp · e(t) produces an output directly proportional to the current error. It is the primary driver of response speed: a large Kp makes the controller react aggressively to any deviation. In embedded firmware this corresponds to: // u_p = Kp * (setpoint - measured). Too small a Kp results in a sluggish response that may not reach the setpoint within the required time; too large a Kp causes overshoot and sustained oscillation. Most tuning procedures begin by setting Ki = Kd = 0 and adjusting Kp until the transient response shape is acceptable.
Integral Term — I
The integral term Ki · ∫e dt accumulates all past error to produce a correction that grows as long as any steady-state offset persists. Without Ki, a proportional controller always leaves a non-zero steady-state error because the output is zero only when the error is zero, which requires a non-zero plant input to overcome friction or gravity. The integrator forces the output to climb until the error is truly zero. The firmware pattern is: integral += error * dt; u_i = Ki * integral;. The risk is integral windup when the actuator saturates — always implement a windup clamp in production code.
Derivative Term — D
The derivative term Kd · de/dt reacts to the rate of change of the error, providing anticipatory damping. When the output is approaching the setpoint rapidly, the derivative term applies a braking force that reduces overshoot. The firmware pattern is: derivative = (error - prev_error) / dt; u_d = Kd * derivative;. Because differentiation amplifies noise, real systems always apply a low-pass filter or use derivative-on-measurement (differentiating the output y rather than the error e) to avoid chattering.
The Three Gains Explained
Kp — Proportional Gain
Kp scales the instantaneous error directly into the control output. Increasing Kp speeds up the response and reduces steady-state error in a P-only controller, but past a critical value it causes sustained oscillation. For a first-order plant with K = 1 and τ = 1, a Kp around 2–5 typically gives a fast but not excessively oscillatory step response. Use the simulator: set Ki = 0, Kd = 0, then raise Kp from 0.5 to 5 and observe the overshoot percentage and rise time trade-off.
Effect of Kp on step response (K=1, τ=1, Ki=0, Kd=0):
Kp = 0.5→ slow rise, ~30% steady-state error, no overshootKp = 2.0→ moderate rise, ~10% steady-state error, slight overshootKp = 5.0→ fast rise, low steady-state error, 15–25% overshootKp = 20+→ very fast, large overshoot, may oscillate
Ki — Integral Gain
Ki accumulates error over time to eliminate steady-state offset — the one problem that Kp alone cannot solve. Even a small Ki (0.1–0.5) is sufficient to drive steady-state error to zero for most first-order plants. Increasing Ki makes the offset disappear faster but risks integral windup and increased oscillation, particularly if Ki exceeds Kp/τ. Tune Ki after Kp is set: start at Ki = 0.1, verify the steady-state error card reaches near zero, and reduce if overshoot or oscillation increases.
Effect of Ki on steady-state error (Kp=2, Kd=0, K=1, τ=1):
Ki = 0→ persistent steady-state error (~30%)Ki = 0.2→ SSE eliminated slowly, minimal extra overshootKi = 1.0→ SSE eliminated quickly, small overshoot increaseKi = 5.0→ risk of integral windup, large oscillation
Kd — Derivative Gain
Kd acts on the rate of error change to damp overshoot and reduce settling time. Even a small Kd (0.05–0.2 for typical first-order plants) significantly reduces overshoot without meaningfully lengthening rise time. However, Kd is the most sensitive gain to noise — in noisy environments the derivative must be filtered. In simulation (no noise), Kd can be increased until overshoot is nearly eliminated; in hardware, filter the measurement first.
Effect of Kd on overshoot (Kp=2, Ki=0.5, K=1, τ=1):
Kd = 0→ overshoot ~20%, settling ~4 sKd = 0.1→ overshoot ~10%, settling ~2.5 sKd = 0.3→ overshoot ~2%, settling ~1.8 sKd = 1.0→ critically damped / over-damped
Input Types: Step, Ramp, Sine, Square Wave
Different input types reveal different aspects of PID controller performance. A single step response shows transient behavior, but it does not reveal how the controller tracks a moving target, how it performs at different frequencies, or how it handles repeated disturbances. This simulator supports all four standard test inputs to give a complete picture of controller behavior.
Step Input
The unit step input applies a setpoint of 1.0 at t = 0 (from an initial output of 0). This is the standard test for characterizing PID transient response. The step response reveals rise time (speed), overshoot (aggressiveness), settling time (damping), and steady-state error (integral effectiveness). It is the most informative single-shot test for initial tuning: start with a step input and tune Kp, Ki, Kd until all five metric cards are satisfactory before switching to other input types.
Ramp Input
The ramp input linearly increases the setpoint from 0 to 1 over the full simulation time. It tests the controller's ability to track a moving target without accumulating a growing lag. A P-only controller cannot track a ramp without a permanent velocity error proportional to the ramp rate; adding Ki (integral action) dramatically reduces this error. Use the Ramp input to verify that your Ki is large enough to track the expected rate of change in your application — for example, a motor accelerating at a constant rate, a conveyor speeding up, or a temperature setpoint changing linearly during a soak.
Sine Input
The sine input applies setpoint(t) = sin(2π·f·t) at the frequency set by the Frequency (Hz) field. The output oscillates between −1 and +1, which is why the Y-axis extends into negative values for this input type. The sine input tests bandwidth: at low frequencies the output tracks the setpoint closely (near-unity amplitude, near-zero phase lag); at higher frequencies the output amplitude decreases and phase lag increases. Compare the output amplitude to the setpoint amplitude to estimate bandwidth attenuation. This is particularly useful for audio amplifier feedback loops, vibration control, and any system that must follow oscillatory references.
Square Wave Input
The square wave input alternates the setpoint between 0 and 1 at the specified frequency. Each half-period is effectively a step disturbance, making the square wave ideal for testing repetitive disturbance rejection and evaluating whether the PID response is consistent across multiple setpoint changes. It is widely used in drone motor tuning (Betaflight performs step-response tests using square inputs on rate loops), servo drive characterization, and any application where the setpoint toggles between two states repeatedly. Look for consistent overshoot and settling across cycles — diverging oscillations indicate marginal stability.
Plant Model G(s) = K / (τs + 1)
This calculator simulates a first-order linear time-invariant plant described by the transfer function G(s) = K / (τs + 1). This model represents the most common category of physical systems: those that respond to a step input with a smooth exponential approach to a final steady-state value, characterized entirely by two parameters — DC gain K and time constant τ. The discrete-time Euler integration equations used in the simulation are:
Plant update equations (Euler, dt = 0.01 s):
dydt = (K * u - y) / tau
y_new = y + dydt * dt
where u is the PID output, y is the plant output, K is DC gain, and tau is the time constant.
Choosing K and τ
K (plant gain) determines the steady-state output per unit control input — a motor with K = 2 would reach 2 rad/s of angular velocity for a 1 V sustained input. τ (time constant) determines how quickly the plant responds: at t = τ, the output reaches 63.2% of its final value; at t = 5τ, the response is essentially complete (99.3%). A large τ (slow plant) requires a larger Kp to achieve acceptable rise time but tolerates smaller Kd. A small τ (fast plant) responds quickly but is more sensitive to noise and delay. Default values K = 1, τ = 1 represent a normalized plant suitable for most tuning exercises; in Advanced mode you can increase τ to 5–10 s to simulate a slow thermal system, or decrease it to 0.1 s for a fast electrical loop.
Step Response Metrics
Rise Time
Rise time is the elapsed time from t = 0 until the output first reaches 90% of the setpoint value (the 90%-crossing definition used in this calculator). A short rise time indicates an aggressive, fast controller; it is primarily controlled by Kp. The fundamental trade-off is that shorter rise time almost always produces more overshoot — the controller pushes the plant hard to speed up crossing, which carries excess momentum past the setpoint. Rise time is reported as N/A for Ramp and Sine inputs where the setpoint is not a fixed target.
Settling Time (±2%)
Settling time is the time after which the output remains permanently within ±2% of the setpoint for the rest of the simulation. The ±2% tolerance band is the most widely used industrial standard (some applications use ±5% for non-critical loops or ±0.5% for precision control). Settling time captures both the speed of the initial response and the decay of any oscillation — a controller with fast rise time but large oscillation can have a long settling time. All three gains affect settling time: Kp drives the initial response, Ki eliminates the final offset, and Kd damps the oscillation. Settling time is reported as N/A for Ramp and Sine inputs.
Overshoot
Overshoot is computed as (peak_output − setpoint) / setpoint × 100%. It measures how far the output exceeds the target. Acceptable overshoot is application-specific: temperature control typically accepts 5–10%; drone attitude loops tolerate 15–25% on inner rate loops for fast disturbance rejection; precision positioning (CNC, robotics, optics) requires 0% to avoid tool overshoot past the target position. The Ziegler-Nichols classic formula deliberately targets ~25% overshoot for fastest disturbance rejection.
Steady-State Error
Steady-state error is computed as | setpoint_final − output_final | at the end of the simulation. A well-tuned PID with non-zero Ki will drive this to near zero for a step input. Persistent steady-state error indicates that Ki is too small (or zero), the simulation time is too short for the integral to accumulate, or the plant parameters are such that the proportional term alone is insufficient. For Ramp inputs, steady-state error measures the velocity tracking lag.
Peak Output
Peak output is the maximum value reached by the plant output during the entire simulation. It equals the setpoint for a critically damped or overdamped step response, and exceeds the setpoint by the overshoot amount for underdamped responses. For Sine inputs, the peak output is the maximum of the sine tracking. Peak output is useful for actuator sizing: if the peak control signal u would exceed the actuator's range (motor voltage limit, valve opening limit), the gains must be reduced or anti-windup clamping must be applied.
PID Tuning Methods
Manual Tuning Sequence
- Set Ki = 0, Kd = 0. Use a Step input. Increase Kp from a small value (e.g. 0.5) until the system responds quickly to the step. If the output oscillates without settling, reduce Kp by 20–30%.
- Add Kd first (optional). Increase Kd from 0.0 to reduce the overshoot from Kp tuning. Kd is most effective before Ki is added because the integral does not yet complicate the dynamics.
- Add Ki. Increase Ki gradually from 0.1 until the steady-state error card reaches zero. Reduce Ki if oscillation reappears or settling time lengthens.
- Verify on other input types. Switch to Ramp to confirm velocity tracking, then to Square to confirm repetitive disturbance rejection.
- Fine-tune. Adjust Kp ±10% and Kd ±20% around the current values to optimize the overshoot vs. settling time trade-off.
Ziegler-Nichols Classic Method
The Ziegler-Nichols closed-loop procedure determines Kp, Ki, Kd from two measured quantities: the Ultimate Gain Ku (the Kp value at which the system sustains constant, undamped oscillation with Ki = Kd = 0) and the Ultimate Period Tu (the period of those oscillations in seconds). To find Ku: set Ki = 0, Kd = 0 in this simulator; increase Kp until the step response oscillates with constant amplitude and does not decay.
Once Ku and Tu are known, the ZN formulas give controller gains for five controller types (see the reference table below the metrics). The classic ZN PID sets Kp = 0.6×Ku, Ki = 2×Kp/Tu, Kd = Kp×Tu/8, intentionally producing ~25% overshoot for aggressive disturbance rejection. The 'low overshoot' variant uses Kp = 0.33×Ku for ~5% overshoot; the 'no overshoot' variant uses Kp = 0.2×Ku for <1% overshoot at the cost of slower response.
Rules of Thumb
- Increasing Kp: faster rise time, more overshoot, can cause oscillation if too high
- Decreasing Kp: slower, more stable, but may leave steady-state error (P-only)
- Increasing Ki: eliminates steady-state offset faster, risk of windup, increases overshoot
- Decreasing Ki: more stable but slower offset elimination; zero Ki leaves persistent offset
- Increasing Kd: reduces overshoot and settling time, amplifies noise
- Decreasing Kd: less noise sensitivity, but more overshoot and longer settling
Cohen-Coon Method
The Cohen-Coon method is an alternative to Ziegler-Nichols designed specifically for first-order plants with time delay (dead time). If your plant exhibits a pure delay θ before responding (not modeled in this calculator's G(s) = K/(τs+1)), the Cohen-Coon formulas use the plant gain K, time constant τ, and delay θ identified from an open-loop step test to compute Kp, Ki, Kd. Cohen-Coon typically produces less aggressive gains than ZN and is preferred for chemical process control where dead time is significant. The Advanced mode in this simulator lets you verify Cohen-Coon gains against the idealized first-order plant response.
Advanced PID Topics
Integral Windup
Integral windup is the most common practical problem in PID implementations. It occurs when the control signal u is physically clamped (motor at maximum voltage, valve fully open) but the integrator continues to accumulate error. When the setpoint is finally reached, the oversized integral drives a large negative control output — causing severe undershoot and slow recovery. Firmware mitigation pattern:
integral += error * dt;
u = Kp*error + Ki*integral + Kd*derivative;
// Anti-windup clamp:
if (u > U_MAX) { u = U_MAX; integral -= error * dt; }
if (u < U_MIN) { u = U_MIN; integral -= error * dt; }
Derivative Kick
Derivative kick is a large impulse in u that occurs when the setpoint changes suddenly. Since de/dt = d(SP−y)/dt and SP jumps by a large amount in one timestep, the derivative term produces a spike of magnitude Kd × ΔSP / dt. For dt = 0.01 s and ΔSP = 1.0, the spike is 100×Kd — potentially enormous. The solution is derivative-on-measurement: compute −dy/dt instead of d(SP−y)/dt. The output y changes smoothly, so no kick occurs. The damping effect is identical.
Cascade PID
Cascade (nested) PID uses two controllers in series: an outer position/speed controller whose output becomes the setpoint for an inner torque/current controller. The inner loop runs at a much higher rate (typically 10–100× faster) and must be tuned first. Common in robotics (outer joint-position PID, inner motor-current PID), drone control (outer altitude PID, inner attitude PID, inner-inner rate PID in Betaflight), and industrial servo drives (outer position, inner velocity, inner-inner current). The first-order plant in this simulator represents a single loop; cascade structures require separate simulation of each loop.
Real-World Applications of PID Control
- Drone flight stabilization: Every quadrotor runs at minimum three PID loops — roll rate, pitch rate, and yaw rate — updated at 1–8 kHz. Flight controllers such as Betaflight and ArduPilot expose Kp, Ki, Kd per axis and provide step-response test tools (blackbox logging) that work exactly like this simulator.
- Robot joint control: Industrial robot manipulators use PID position controllers on each joint servo. The derivative term is critical for damping oscillation at the end of fast moves, while the integral term eliminates gravity-induced steady-state sag on vertical axes.
- Temperature regulation: Ovens, 3D printer hot ends, reflow soldering stations, autoclaves, and HVAC systems — temperature PID is the single most common PID application by volume. Because thermal systems are slow (τ often 30–300 s), tight Kd is rarely needed; PI control is usually sufficient.
- Motor speed and torque control: DC and BLDC motor drive electronics use PID current loops (inner, fastest), velocity loops (middle), and position loops (outer, slowest). Electric vehicles, conveyor drives, and industrial pumps all rely on this structure.
- Process plant control: Pressure, flow, liquid level, and pH control in oil refineries, water treatment plants, pharmaceutical manufacturing, and food processing. DCS systems (Honeywell, Emerson, Siemens) implement thousands of PID loops, each tuned by process engineers.
- Power electronics: Voltage-mode and current-mode control in DC-DC converters (buck, boost, buck-boost), UPS inverters, and battery chargers use PID-like compensators with update rates of 50–500 kHz. At these frequencies, digital PID is implemented in fixed-point arithmetic on a DSP or FPGA.
- CNC and precision motion: Machining centers, 3D printers, and semiconductor lithography stages use zero-overshoot PID configurations (or more complex feedforward + PID) to achieve sub-micron positioning accuracy. Any overshoot here physically moves the cutter past the intended path, creating scrapped parts.
Frequently Asked Questions
How do I tune Kp without Ki and Kd?
Set Ki = 0 and Kd = 0, select Step input, and gradually increase Kp from 0.5 upward. Watch the rise time card shrink and the overshoot card grow. The optimal Kp-only value is subjective: stop when the rise time meets your requirement even if a small steady-state error remains. For a P-only loop, steady-state error is expected — you will eliminate it with Ki in the next step. If the output oscillates without settling, Kp is too high; reduce by 20–30%.
What happens if Ki is too large?
An excessively large Ki causes the integral term to accumulate faster than the plant can respond, driving the output far past the setpoint (integral windup). In simulation you will see a large overshoot followed by a slow, oscillatory recovery. In real hardware with actuator limits, the integrator winds up to its maximum value during saturation and then drives a large reverse output when the setpoint is reached. Always pair a large Ki with an anti-windup mechanism (integrator clamping or back-calculation).
How is derivative kick different from derivative action?
Normal derivative action (Kd × de/dt) damps oscillation by applying a braking force as the error decreases — this is the desired behavior. Derivative kick is the pathological case: when the setpoint steps by a large amount in one timestep, de/dt spikes to ΔSP/dt regardless of Kd, causing a huge impulse in u. The fix is derivative-on-measurement: compute −dy/dt instead of d(SP−y)/dt. You get the same damping without the step-change spike because the measured output y changes smoothly.
What is a critically damped response?
A critically damped system reaches its setpoint as fast as possible without any overshoot. It corresponds to a damping ratio ζ = 1 in second-order system analysis. For PID control, critical damping is achieved by balancing Kp (for speed) and Kd (for damping) precisely. In this simulator, a critically damped step response shows zero overshoot in the metric card while having the fastest rise time among all non-overshooting configurations. Increase Kd until overshoot just disappears to approach critical damping.
Why does adding Kd sometimes make things worse?
Kd amplifies high-frequency noise in the error signal. In simulation (no noise) Kd is always beneficial; in real hardware, a large Kd applied to a noisy sensor signal produces high-frequency chatter in the control output that can cause actuator heating, mechanical vibration, and wear. Additionally, if Kd is very large relative to Kp and the plant has a significant time delay, the derivative action can actually destabilize the loop because it reacts to stale noise rather than true future error. Apply a derivative filter (cutoff at 5–20× bandwidth) before increasing Kd beyond 0.3–0.5 in practice.
What plant gain K and time constant τ should I use?
Use K = 1, τ = 1 for generic PID tuning exercises. To represent a specific system, identify K from an open-loop step test (K = final output / step input magnitude) and τ from the time it takes to reach 63.2% of the final output. For a slow thermal system (oven, HVAC), τ = 30–300 s and K depends on heater power vs. temperature sensitivity. For a DC motor velocity loop, τ = L/R (mechanical time constant, typically 0.01–0.5 s). For a fast electrical loop (DC-DC converter), τ may be as small as 0.0001 s, requiring a much higher loop bandwidth than the 0.01 s timestep in this simulator.
How do I interpret a Sine input result?
With a Sine input, compare the output amplitude to the setpoint amplitude (both ±1.0 at the setpoint level). If the output amplitude is significantly less than 1.0 and the output visibly lags the setpoint, the sine frequency exceeds the controller bandwidth. Reduce the frequency until the output tracks the setpoint well — that frequency is your closed-loop bandwidth in Hz. The steady-state error card shows the peak absolute tracking error. A well-tuned PID should track a sine at half its bandwidth frequency with less than 10% amplitude error.
Can I use this for a real control system?
This simulator provides a first-order plant model without actuator saturation, time delay, sensor noise, or nonlinearities — ideal for understanding PID gain interactions and for initial gain selection. Gains tuned here should be treated as starting points that require hardware validation. Real systems introduce saturation (anti-windup needed), dead time (use Smith Predictor or Cohen-Coon), noise (filter Kd), and nonlinearities (gain scheduling may be needed). The Ziegler-Nichols formulas in the reference table translate directly to real hardware once Ku and Tu are measured on the physical plant.
What is the difference between P, PI, and PID control?
P control (Kp only): fast response, permanent steady-state error in most plants, simple. PI control (Kp + Ki): eliminates steady-state error, sufficient for most slow or medium-speed plants (temperature, flow, pressure) where noise is low and derivative action is unnecessary. PID control (all three): fastest settling and best disturbance rejection, required for fast plants with significant overshoot (motor drives, drone attitude loops, servo positioning). Adding I to P reduces steady-state error at the cost of some additional overshoot; adding D to PI reduces that overshoot at the cost of noise sensitivity. Most industrial loops use PI; only about 20% of industrial loops actually benefit from D action.
Related Tools
- Robot Arm FK/IK Calculator — Robot arm kinematics for learning & practice: FK/IK, DH tables, Jacobian—aligned with cobots, industrial robots, humanoid arms, and AI robotics workflows. Robot programming friendly (CSV export). 2–6 DOF, SCARA, UR/KUKA-style presets, 3D visualization. Runs in your browser.
- LLM Token Calculator — Free AI token calculator for GPT, Claude, Gemini, and custom models. Count prompt tokens, compare context window usage, estimate API cost, and keep text in your browser.
- Drone Calculator — Calculate drone thrust, TWR, hover throttle, flight time, and battery C-rating safety. Compare up to 4 motor/battery/propeller configurations side by side.
- PWM & Servo Calculator — Calculate PWM period, duty cycle, high/low time, servo angle-to-pulse-width mapping, and ESC throttle position. Supports standard (1000–2000 µs) and wide-range (500–2500 µs) servos. Runs in your browser.
- SPI Calculator — Calculate SPI clock frequency from MCU clock and divider, transfer time, throughput, and bit/word periods. Browse all 8 clock dividers in a single table with speed class indicators. Supports SPI Mode 0–3 (CPOL/CPHA), MSB/LSB first, and word sizes of 8/16/32 bits. Runs in your browser.