Learn PLCs free
Intermediate1 hourPID controlDead-bandOccupied/unoccupied schedulingAnalog scaling

HVAC Zone Temperature Control

Building HVAC control with PID modulation of a hot-water valve, dead-band hysteresis to prevent valve hunting, and scheduled occupied/unoccupied setpoints.

Sequence overview showing inputs flowing into PLC logic and outputs driving actuators, with this example named HVAC Zone Temperature Control.Process flow: inputs → logic → outputsInputsRoomTemp_RawDI, OccupiedMode2 signalsPLC LogicPID control · Dead-bandIntermediate · 1 hourOutputsHeaterValve_Pct1 signals

I/O list

TagTypeDescription
RoomTemp_RawDIAIRTD raw 4-20 mA from temperature sensor
RoomTemp_DegCREALScaled room temperature in °C
HeaterValve_PctAOHot water valve 0-100% open
OccupiedModeDISchedule input from BMS
OccupiedSPREALSetpoint when occupied (e.g., 21°C)
UnoccupiedSPREALSetpoint when unoccupied (e.g., 17°C)

Structured Text code

PROGRAM main
VAR
    Setpoint    : REAL;
    DeadBand    : REAL := 0.5;        (* ±0.5°C around setpoint *)
    HeatNeeded  : BOOL;
    PIDInst     : PID;                 (* IEC 61131-3 PID FB *)
    Kp          : REAL := 5.0;
    Ki          : REAL := 0.1;
    Kd          : REAL := 0.0;
END_VAR

(* Scale 4-20 mA raw to 0-50°C *)
RoomTemp_DegC := (RoomTemp_RawDI - 4.0) / 16.0 * 50.0;

(* Choose setpoint based on schedule *)
IF OccupiedMode THEN
    Setpoint := OccupiedSP;
ELSE
    Setpoint := UnoccupiedSP;
END_IF;

(* Dead-band hysteresis: only call for heat when below SP - DB *)
IF RoomTemp_DegC < Setpoint - DeadBand THEN
    HeatNeeded := TRUE;
ELSIF RoomTemp_DegC > Setpoint + DeadBand THEN
    HeatNeeded := FALSE;
END_IF;

(* PID modulates valve when heat is needed *)
IF HeatNeeded THEN
    PIDInst(SP := Setpoint, PV := RoomTemp_DegC, KP := Kp, KI := Ki, KD := Kd);
    HeaterValve_Pct := PIDInst.OUT;     (* Limit 0-100 *)
    IF HeaterValve_Pct < 0.0 THEN HeaterValve_Pct := 0.0; END_IF;
    IF HeaterValve_Pct > 100.0 THEN HeaterValve_Pct := 100.0; END_IF;
ELSE
    HeaterValve_Pct := 0.0;
END_IF;

How it works

Analog scaling: 4-20 mA raw signal is scaled to 0-50°C engineering units. The scaling formula is universal for 4-20 mA inputs.

Schedule logic: occupied/unoccupied mode (typically driven by BMS time-of-day schedule) selects different setpoints to save energy when the space is unoccupied.

Dead-band hysteresis: the heater turns on when temp drops 0.5°C below SP, off when it rises 0.5°C above. Without dead-band, the valve hunts continuously.

PID modulation: when heat is needed, PID modulates the valve from 0-100% based on the temperature error. Output is clamped to valid range.

More examples