69  PID: Feedback Fundamentals

In 60 Seconds

Feedback loops measure output, compare to a setpoint, and adjust input to minimize the difference. Negative feedback (subtracting measured output from the setpoint) creates stability and self-correction in 99% of IoT control systems. Without feedback, a heater has no way to know when the room reaches the target temperature.

69.1 Learning Objectives

By the end of this chapter, you will be able to:

  • Explain Feedback Concepts: Describe how feedback loops measure output, compare to setpoint, and adjust input
  • Classify Feedback Examples: Categorize feedback mechanisms in everyday devices and IoT systems by type
  • Differentiate Feedback Types: Contrast positive and negative feedback and predict their effects on system stability
  • Design Distributed Feedback: Architect IoT systems that implement feedback across network boundaries with edge fallback
MVU: Minimum Viable Understanding

Core concept: Feedback is when a system uses its output to adjust its input - like checking your speed while driving and adjusting the gas pedal accordingly. Why it matters: Without feedback, systems operate blindly and cannot adapt to changing conditions or disturbances. Key takeaway: Most IoT control applications use negative feedback to maintain stable setpoints, while positive feedback is reserved for specialized applications like signal amplification.

69.2 Prerequisites

Before diving into this chapter, you should be familiar with:

  • Sensor Fundamentals and Types: Understanding sensor characteristics and how they measure physical variables is essential for implementing effective feedback control systems
  • Actuators: Knowledge of actuator types and control methods is critical since feedback systems ultimately drive actuators
  • Processes & Systems: Fundamentals: Familiarity with systems thinking, input-output relationships, and process definitions

Imagine driving a car and trying to maintain exactly 60 mph. You look at the speedometer (sensor), see you’re at 58 mph (error = 2 mph too slow), so you press the gas pedal a bit (control action). You continuously adjust based on what you see - that’s feedback control.

Everyday Analogy: Your home thermostat is a perfect feedback example. It doesn’t just turn heat “fully on” or “fully off.” Instead, it measures room temperature (output), compares to your target, and adjusts heating accordingly.

Term Simple Explanation
Feedback Using output to adjust input, like steering based on where your car is going
Set Point Your desired target value (e.g., 72F room temperature)
Error The difference between where you want to be and where you are
Sensor Device that measures the output (like a thermometer)
Actuator Device that takes action (like a heater or valve)

Why This Matters for IoT: Feedback enables autonomous operation - your smart home can maintain temperature without you constantly adjusting the thermostat.

Feedback is like having a helper who checks your work and tells you how to do better!

69.2.1 The Sensor Squad Adventure: The Perfect Temperature Room

Lila the LED loved her plants, but they were SO picky! Her tomato plants needed the greenhouse to stay at exactly 75 degrees - not too hot, not too cold.

“How do I know when it’s too hot or too cold?” wondered Lila.

Sammy the Sensor had an idea! “I’ll keep checking the temperature and tell you what’s happening. If it’s too cold, we turn on the heater. If it’s too hot, we turn it off!”

Max the Microcontroller set up the system: “Sammy checks the temperature, tells me the number, I compare it to 75, and decide what to do. It’s like a loop that keeps going around and around!”

And that’s exactly what happened. Every few seconds, Sammy checked, Max decided, and the heater adjusted. The plants stayed happy at exactly 75 degrees!

69.2.2 Key Words for Kids

Word What It Means
Feedback When you use information about what happened to decide what to do next
Loop Something that goes around and around, checking and adjusting
Sensor Like your eyes or ears - it notices what’s happening
Target What you’re trying to achieve (like 75 degrees)

69.2.3 Try This at Home!

The Blindfolded Walking Game:

  1. Put a pillow across the room as your target
  2. Close your eyes and walk toward it
  3. Have a friend say “warmer” or “colder” based on your distance
  4. That’s feedback helping you reach your target!

69.3 What is Feedback?

Feedback is a fundamental concept where a portion of a system’s output is routed back to influence the input. This creates a self-regulating mechanism that can improve system performance, stability, and accuracy.

Geometric diagram of PID controller architecture showing three parallel processing paths for Proportional (error magnitude), Integral (accumulated error history), and Derivative (error rate of change) terms, which are summed to produce the control output signal that drives the actuator to minimize setpoint error

PID controller architecture visualization
Figure 69.1: The PID controller combines three control strategies to achieve optimal system response. Understanding feedback is the foundation for implementing effective PID control.

69.4 Everyday Feedback Examples

We encounter feedback constantly in daily life:

  • Thermostat: Room temperature (output) is measured and compared to the desired temperature (input), adjusting heating/cooling accordingly
  • Cruise control: Vehicle speed (output) is monitored and throttle (input) is adjusted to maintain set speed
  • Refrigerator: Internal temperature (output) controls compressor on/off cycles (input)
  • Shower temperature: You feel water temperature and adjust hot/cold knobs

In IoT systems, feedback enables autonomous operation and adaptation to changing conditions.

The “useless box” demonstrates basic feedback in action:

Useless box feedback loop flowchart showing user flipping switch ON, sensor detecting the action, microcontroller processing the state, servo motor arm activating to flip switch OFF, creating a negative feedback loop that opposes the user action and returns the switch to its original position

Flowchart diagram
Figure 69.2: Flowchart showing useless box feedback loop: user flips switch ON, sensor detects, microcontroller processes, servo motor activates mechanical arm to flip switch OFF, creating negative feedback that opposes user action.

Useless Box Feedback Loop: User input triggers sensor detection, microcontroller processing activates servo motor, which mechanically reverses the switch position, creating negative feedback that opposes the user’s action.

This simple system demonstrates negative feedback where the output (switch position) directly counteracts the input (user action), restoring the system to its original state.

69.5 Feedback in IoT Applications

IoT devices leverage feedback for various purposes:

Environmental Control
Smart thermostats, greenhouse automation, HVAC systems
Process Monitoring
Industrial sensors adjusting manufacturing parameters in real-time
Safety Systems
Automatic shutoffs when dangerous conditions detected
Energy Management
Battery monitoring systems adjusting charging rates
Distributed Feedback
Water quality monitoring where local sensors trigger remote actuators

Distributed IoT feedback system block diagram showing edge sensor node measuring dissolved oxygen at 4.2 mg/L, transmitting to cloud platform with rule engine that evaluates the measurement against 5 mg/L threshold and sends activation command to remote actuator node controlling an aeration pump, demonstrating closed-loop feedback across network boundaries

Graph diagram
Figure 69.3: Block diagram showing distributed IoT feedback system with edge sensor node measuring water quality (4.2 mg/L dissolved oxygen), cloud platform with rule engine (IF DO less than 5mg/L THEN activate pump), and actuator node controlling aeration pump, creating closed feedback loop across network.

Distributed IoT Feedback System: Sensor nodes transmit water quality data to cloud platform, where rule engine evaluates conditions and sends commands to remote actuator nodes, creating a closed feedback loop across network boundaries.

This distributed feedback system demonstrates how IoT architectures can implement control loops across multiple devices and network boundaries, with cloud-based decision-making coordinating local sensor and actuator nodes.

69.6 Negative vs Positive Feedback

Understanding the two types of feedback is essential for control system design:

Comparison diagram of negative versus positive feedback: negative feedback loop shows thermostat reducing heat output as temperature approaches setpoint, creating stable regulation; positive feedback loop shows microphone-speaker system amplifying sound that feeds back into microphone, creating unstable runaway amplification
Figure 69.4: Negative feedback (stabilizing) versus positive feedback (amplifying) comparison

Negative vs Positive Feedback Comparison: Negative feedback opposes changes to stabilize the system (thermostat reducing heat as temperature approaches target). Positive feedback amplifies changes, leading to runaway growth or oscillation.

Negative Feedback (most common in IoT):

  • Opposes changes from the set point
  • Provides stability and regulation
  • Example: Thermostat reducing heat as temperature approaches target

Positive Feedback (less common, specialized uses):

  • Reinforces changes from the set point
  • Can cause instability or rapid state changes
  • Example: Schmitt trigger with hysteresis for noise immunity

This variant shows the historical and conceptual progression from simple on/off control to sophisticated PID control, helping students understand why each advancement was necessary.

Control system evolution timeline showing progression from simple on/off bang-bang control with oscillating output, to proportional control reducing oscillation but leaving steady-state error, to PI control eliminating error but potentially overshooting, to full PID control achieving optimal response with fast settling, minimal overshoot, and zero steady-state error
Figure 69.5: This evolutionary view demonstrates why PID control exists: each term was added to solve a specific limitation of simpler approaches. Understanding this progression helps students grasp when full PID is necessary versus when simpler P or PI control suffices.

Artistic visualization of a feedback control loop showing the circular flow of information from setpoint through error calculation, controller processing, actuator action, plant response, sensor measurement, and back to error calculation, emphasizing the continuous self-regulating nature of closed-loop control systems

Feedback control loop visualization
Figure 69.6: Feedback control creates a continuous cycle of measurement, comparison, and correction. This self-regulating behavior enables systems to maintain desired operating conditions despite disturbances and changing environmental factors.

69.7 Worked Example: Designing Feedback Control for a Smart Greenhouse

Scenario: A tomato greenhouse uses an ESP32 microcontroller, a DHT22 temperature/humidity sensor, a 1,500W heater (relay-controlled), and a ventilation fan (PWM-controlled). The target temperature is 24C during day and 18C at night. Design the feedback control system, calculate response times, and compare on/off control versus proportional control.

Step 1: Characterize the System (Plant Model)

First, measure how the greenhouse responds to heating input:

Greenhouse thermal characteristics:
  Volume: 50 m3 (5m x 5m x 2m)
  Air mass: 50 m3 x 1.2 kg/m3 = 60 kg
  Specific heat of air: 1,005 J/(kg.C)
  Thermal capacity: 60 x 1,005 = 60,300 J/C

  Heater power: 1,500 W
  Heating rate: 1,500 / 60,300 = 0.025 C/second = 1.5 C/minute

  Heat loss rate (winter, outdoor = 5C, indoor = 24C):
  U-value (polycarbonate walls): 3.5 W/(m2.C)
  Surface area: 70 m2
  Heat loss: 3.5 x 70 x (24 - 5) = 4,655 W

  Net heating: 1,500 - 4,655 = -3,155 W (heater alone cannot maintain 24C!)

The thermal time constant determines how fast the greenhouse responds to heating. Using Newton’s Law of Cooling:

\[ \tau = \frac{m \cdot c_p}{U \cdot A} = \frac{60 \text{ kg} \times 1{,}005 \text{ J/(kg·°C)}}{3.5 \text{ W/(m}^2\text{·°C)} \times 70 \text{ m}^2} = \frac{60{,}300}{245} \approx 246 \text{ seconds} \]

This means the greenhouse temperature reaches 63% of a step change in ~4 minutes. For control loop design, sample every \(\tau/10 \approx 25\) seconds. Faster sampling wastes energy; slower sampling risks overshoot.

Problem identified: The heater cannot overcome winter heat loss. Solution: add a second 2,000W heater (total 3,500W). Net heating becomes 3,500 - 4,655 = still negative at peak loss, but with solar gain during day (~2,000W average), total is 3,500 + 2,000 - 4,655 = 845W net positive.

Step 2: On/Off Control (Bang-Bang) Analysis

Simple approach: heater ON when temperature is below setpoint, OFF when above.

On/Off control behavior:
  Setpoint: 24C
  Sensor reads 23.8C -> Heater ON (3,500W)
  Heating rate: (3,500 + 2,000 - 4,655) / 60,300 = 0.014 C/s
  Time to reach 24C: 0.2 / 0.014 = 14 seconds

  But sensor delay (DHT22): 2 seconds between readings
  Thermal lag (sensor to air): ~30 seconds
  Relay switching delay: 50 ms (negligible)

  Actual overshoot: heater stays on 32 seconds past setpoint
  Overshoot amount: 0.014 x 32 = 0.45C
  Temperature oscillates: 23.5C to 24.5C (1C band)
  Cycle time: ~4 minutes (ON 2 min, OFF 2 min)
Metric On/Off Control Target
Temperature band +/- 0.5C +/- 0.3C
Heater cycles per hour 15 <5
Energy waste (overshoot) ~8% <3%
Relay lifetime at 15 cycles/hr ~2 years 10+ years

Problem: On/off control oscillates too widely, shortens relay life, and wastes energy. Tomatoes need +/- 0.3C stability for optimal growth.

Step 3: Proportional Control Design

Instead of full ON/OFF, use PWM to vary heater power proportionally to the error:

Proportional control:
  Error = Setpoint - Measured
  Heater_PWM = Kp x Error

  Proportional band: 2C (heater goes from 0% at setpoint to 100% at 2C below)
  Kp = 100% / 2C = 50%/C

  At 23C (1C below setpoint):
    Error = 24 - 23 = 1C
    Heater_PWM = 50% x 1 = 50% = 1,750W

  At 23.5C (0.5C below):
    Heater_PWM = 50% x 0.5 = 25% = 875W

  At 23.8C (0.2C below):
    Heater_PWM = 50% x 0.2 = 10% = 350W (gentle maintenance)

Step 4: Compare Results

Metric On/Off Proportional (Kp=50) Improvement
Temperature stability +/- 0.5C +/- 0.15C 3.3x better
Heater cycles/hour 15 0 (continuous PWM) Infinite relay life
Average power used 1,850W 1,620W 12% energy savings
Steady-state error 0C (oscillates) 0.12C (offset) Needs integral term
Response to door opening 45 sec to recover 25 sec to recover 44% faster
Daily energy cost (@$0.12/kWh) $5.33 $4.67 $241/year savings

Step 5: Implement on ESP32

// Simplified proportional feedback loop
const float SETPOINT = 24.0;
const float KP = 50.0;  // %/degree C
const int HEATER_PIN = 25;
const int SENSOR_PIN = 4;

void loop() {
    float temperature = readDHT22(SENSOR_PIN);
    float error = SETPOINT - temperature;

    // Proportional control: 0-255 PWM range
    int pwm = constrain(error * KP * 2.55, 0, 255);
    analogWrite(HEATER_PIN, pwm);

    // Log for monitoring
    Serial.printf("Temp=%.1fC Err=%.2f PWM=%d\n",
                   temperature, error, pwm);
    delay(2000);  // Match DHT22 sample rate
}

Key lesson: The feedback loop transforms a simple heater into an intelligent climate system. On/off control works but oscillates – proportional control smooths the response. The remaining 0.12C steady-state offset (caused by the proportional-only approach needing some error to generate output) is eliminated by adding an integral term (PI control), covered in the PID Control Theory chapter. For this greenhouse, proportional control alone saves $241/year in energy and extends relay life from 2 years to indefinite.

69.8 Interactive: Thermal Time Constant Calculator

Calculate the thermal time constant for a space and determine the appropriate control loop sampling interval.

69.9 Knowledge Check

Key Takeaway

Feedback is the mechanism that transforms passive IoT devices into intelligent, self-correcting systems. The essential loop – measure, compare, correct – applies whether the feedback is local (a thermostat reading room temperature) or distributed across a network (cloud-coordinated sensor-actuator pairs). Negative feedback provides the stability needed for 99% of IoT control applications, while the key design challenge is ensuring the feedback loop remains intact even when network connections fail.

Step 1: Evaluate the Need for Feedback

Question If YES → Feedback Needed If NO → Open-Loop Acceptable
Does output depend on unpredictable disturbances? Wind affects drone position → GPS feedback required Coffee maker timer (predictable heating time)
Must output precisely match a target? Temperature ± 0.5°C for fermentation → Feedback required Fan runs at 70% speed (approximate comfort)
Are consequences of error severe? Medical device dosing (patient safety) → Feedback required Notification LED brightness (cosmetic only)
Does environment change over time? Battery voltage drops (heater power varies) → Feedback compensates LED blink rate (powered source, consistent)

Step 2: Choose Feedback Implementation Architecture

Architecture When to Use Latency Reliability Cost
Local Edge Feedback Process time constant <10 sec (HVAC, motor control) <50 ms Works offline $15-50 for MCU + sensor
Cloud-Coordinated Feedback Process time constant >60 sec (daily irrigation, weekly reports) 100-500 ms Requires connectivity $0 hardware (cloud compute)
Hybrid (Local + Cloud) Critical control + optimization (building HVAC) <50 ms local fallback Resilient $30-70 per zone controller

Step 3: Calculate Control Loop Timing

Rule of thumb: Control loop frequency must be 10x faster than process response time.

Process Time Constant Required Loop Frequency Implementation
Motor position 100 ms 10 Hz (100 ms loop) Edge MCU only
Room temperature 5 min 0.033 Hz (30 sec loop) Edge or cloud acceptable
Greenhouse climate 30 min 0.0056 Hz (3 min loop) Cloud coordination works
Soil moisture (irrigation) 4 hours 0.0007 Hz (24 min loop) Cloud-only sufficient

Example: Smart thermostat decision

  • Process: Room heating/cooling
  • Time constant: Typical room reaches 95% of setpoint change in 5-15 minutes
  • Disturbances: Door opening, sunlight, occupancy (unpredictable) → Feedback required
  • Precision: ± 1°C acceptable for comfort (not critical) → Simple feedback (on/off or P-only)
  • Loop frequency: 15 min / 10 = 90 sec loop → Edge MCU can handle, but cloud also viable
  • Reliability: Heating should work during internet outage → Edge feedback with cloud telemetry

Decision: ESP32 running local P-control (Kp = 10, 60-second sampling), sending temperature logs to cloud for scheduling and energy analytics. Total cost: $25 (ESP32 + DHT22 sensor + relay).

Common mistake: Running PID in cloud for fast processes (motor control, drone stabilization). Network latency (100-500 ms) exceeds process time constant (10-100 ms), causing instability. Always run feedback locally for processes faster than 10 seconds.

Key Concepts

  • Feedback Loop: A control architecture where the system’s output is measured and subtracted from the setpoint to compute error, which drives corrective action — enabling automatic compensation for disturbances and parameter variations
  • Error Signal: The difference between desired setpoint and measured process variable (e = r - y), the fundamental input to a PID controller that drives all three control terms
  • Process Variable (PV): The measured physical quantity being controlled (temperature, pressure, speed, pH) that the PID controller drives toward the setpoint through actuator manipulation
  • Manipulated Variable (MV): The actuator output controlled by the PID algorithm (heater power, valve position, motor speed) that influences the process variable through the plant dynamics
  • Steady-State Error: The residual difference between setpoint and process variable that persists after transient response settles — a pure proportional controller always has steady-state error; adding integral action eliminates it
  • Disturbance: An uncontrolled input that causes the process variable to deviate from setpoint — a PID feedback loop automatically detects and corrects for disturbances through the error signal without requiring knowledge of disturbance magnitude
  • Open-Loop Gain: The product of all gains around the control loop (controller × plant × sensor), determining how aggressively the system responds to error — gains above the stability limit cause sustained oscillation or divergence

Common Pitfalls

Tuning PID gains without characterizing the process (step response test, frequency response sweep) and understanding its time constant, delay, and gain. Blind gain adjustment leads to trial-and-error oscillations that could damage equipment. Always characterize the plant first.

Treating the sensor as instantaneous. Temperature sensors with thermal mass, pressure transducers with fluid columns, and current sensors with filtering all introduce dynamics that add phase lag to the feedback loop. Include sensor time constants in stability analysis.

Using the same PID tuning for both disturbance rejection (holding constant setpoint against disturbances) and setpoint tracking (following a changing reference). Aggressive integral for fast setpoint tracking causes overshoot in disturbance rejection. Tune separately for the primary use case.

Adding multiple nested feedback loops (cascade control) without understanding the inner/outer loop bandwidth separation requirement. The inner loop must be at least 3–5× faster than the outer loop. Violating this ratio causes the loops to fight each other.

69.10 Summary

This chapter covered the fundamentals of feedback in control systems:

  • Feedback Definition: Output information routed back to influence input, creating self-regulating systems
  • Everyday Examples: Thermostats, cruise control, and refrigerators all use feedback
  • IoT Applications: Environmental control, safety systems, energy management, and distributed feedback across networks
  • Feedback Types: Negative feedback stabilizes systems (most common), positive feedback amplifies changes (specialized uses)
  • Foundation for PID: Understanding feedback is essential for implementing proportional-integral-derivative control

69.11 What’s Next

The next chapter explores Open-Loop and Closed-Loop Systems, comparing systems that operate with and without feedback, including decision frameworks for choosing the appropriate control architecture.

Previous Current Next
Process Control and PID Feedback Fundamentals Open & Closed Loop Systems