0
0
FreertosHow-ToBeginner · 4 min read

PLC Programming for HVAC System: Basics and Example

To program a PLC for an HVAC system, you write ladder logic or structured text to control components like fans, heaters, and sensors based on temperature inputs. The program reads sensor data, applies control logic, and outputs commands to HVAC devices to maintain desired conditions.
📐

Syntax

PLC programming for HVAC typically uses Structured Text (ST) or Ladder Logic. Here is a simple Structured Text syntax pattern:

  • IF condition THEN action ELSE alternative_action END_IF;
  • READ sensor inputs (e.g., temperature)
  • WRITE outputs (e.g., fan ON/OFF)

This structure lets you check sensor values and control HVAC devices accordingly.

structured_text
IF TemperatureSensor > SetPoint THEN
    Fan := TRUE;  // Turn fan ON
ELSE
    Fan := FALSE; // Turn fan OFF
END_IF;
💻

Example

This example shows a simple PLC program in Structured Text that controls a heater and fan based on temperature readings to maintain a set temperature.

structured_text
VAR
    TemperatureSensor : REAL;  // Current temperature
    SetPoint : REAL := 22.0;   // Desired temperature in Celsius
    Heater : BOOL := FALSE;    // Heater output
    Fan : BOOL := FALSE;       // Fan output
END_VAR

// Control logic
IF TemperatureSensor < SetPoint THEN
    Heater := TRUE;   // Turn heater ON if too cold
    Fan := FALSE;    // Fan OFF when heating
ELSIF TemperatureSensor > SetPoint THEN
    Heater := FALSE;  // Turn heater OFF if too hot
    Fan := TRUE;      // Turn fan ON to cool
ELSE
    Heater := FALSE;  // Turn both OFF if temperature is just right
    Fan := FALSE;
END_IF;
Output
When TemperatureSensor < 22.0: Heater=TRUE, Fan=FALSE When TemperatureSensor > 22.0: Heater=FALSE, Fan=TRUE When TemperatureSensor = 22.0: Heater=FALSE, Fan=FALSE
⚠️

Common Pitfalls

Common mistakes in PLC HVAC programming include:

  • Not handling sensor noise or fluctuations, causing devices to switch ON/OFF rapidly.
  • Forgetting to initialize variables, leading to unpredictable outputs.
  • Using only simple ON/OFF control without hysteresis, which can wear out equipment.
  • Ignoring safety interlocks or emergency stop conditions.

Adding hysteresis prevents rapid switching:

structured_text
// Without hysteresis (bad)
IF TemperatureSensor > SetPoint THEN
    Fan := TRUE;
ELSE
    Fan := FALSE;
END_IF;

// With hysteresis (better)
IF TemperatureSensor > SetPoint + 0.5 THEN
    Fan := TRUE;
ELSIF TemperatureSensor < SetPoint - 0.5 THEN
    Fan := FALSE;
END_IF;
📊

Quick Reference

ConceptDescriptionExample
IF StatementChecks a condition to control outputsIF Temp > SetPoint THEN Fan := TRUE; END_IF;
VariablesStore sensor inputs and outputsTemperatureSensor : REAL; Fan : BOOL;
HysteresisPrevents rapid switching by adding a marginIF Temp > SetPoint + 0.5 THEN Fan := TRUE;
InitializationSet default values to avoid errorsSetPoint := 22.0; Heater := FALSE;
Safety InterlocksEmergency stops or overridesIF EmergencyStop THEN Fan := FALSE; Heater := FALSE;

Key Takeaways

Use sensor inputs and IF conditions to control HVAC devices in PLC programs.
Add hysteresis to avoid rapid ON/OFF switching and protect equipment.
Initialize all variables to known states before running control logic.
Include safety checks to handle emergency stops or faults.
Structured Text is a clear and effective language for HVAC PLC programming.