May 23, 2026

4-20 mA Flow Measurement: Principles, Technologies, and PLC Integration

Flow measurement is critical in countless industrial processes: monitoring fluid consumption, controlling chemical dosing, tracking product throughput, and managing utility usage. The 4-20 mA standard provides an ideal method for transmitting flow measurements from diverse flow meter technologies to central PLC systems. This article explores flow measurement principles, various flow meter types, conversion methods, and practical PLC implementations for flow monitoring and control.

Electromagnetic Flow Meter
Figure 1: Industrial Electromagnetic Flow Meter with 4-20 mA Output


Flow Meter Technologies
Figure 2: Flow Measurement Technologies Comparison

May 22, 2026

4-20 mA Temperature Measurement: Applications and Implementation

Temperature measurement represents one of the most common applications of 4-20 mA signal transmission in industrial automation. From chemical reactors and food processing to HVAC systems and power plants, accurate temperature monitoring is critical for process control, safety, and product quality. This article explores the practical aspects of implementing temperature measurement systems using 4-20 mA transmitters, including sensor selection, transmitter configuration, PLC integration, and real-world applications.

Temperature Sensor Types

Industrial RTD Temperature Probe with 4-20 mA Transmitter

Figure 1: Industrial RTD Temperature Probe with 4-20 mA Transmitter in Process Vessel


The foundation of any temperature measurement system is the sensor itself. Several sensor types are compatible with 4-20 mA transmitters, each offering different characteristics suitable for specific applications.

Resistance Temperature Detectors (RTDs) provide excellent accuracy and stability. RTDs use the principle that electrical resistance changes with temperature. Platinum RTDs (Pt100, Pt1000) are most common, offering accuracy within ±0.1°C to ±0.5°C depending on grade. RTDs have excellent long-term stability and are suitable for precision applications in laboratories, pharmaceutical manufacturing, and food processing.

Thermocouples offer wider temperature ranges and faster response times than RTDs. A thermocouple consists of two dissimilar metals joined together, generating a small voltage proportional to temperature. Type K thermocouples (chromel-alumel) are most common, operating from -50°C to 1200°C. Type J thermocouples (iron-constantan) operate from -40°C to 750°C. Thermocouples are ideal for high-temperature applications like furnace monitoring and metal processing.

Thermistors, made from semiconductor materials, provide high sensitivity and fast response. Negative Temperature Coefficient (NTC) thermistors decrease resistance as temperature increases. They're commonly used in HVAC systems, refrigeration, and consumer electronics. However, thermistors have limited temperature ranges (typically -50°C to 150°C) and require individual calibration.

4-20 mA Temperature Transmitters

A temperature transmitter converts the sensor signal to a standardized 4-20 mA output. The transmitter includes signal conditioning circuitry, amplification, and conversion electronics. Most industrial temperature transmitters are two-wire devices, drawing power from the signal loop while outputting the 4-20 mA signal.

Temperature transmitters are configured with minimum and maximum temperature setpoints that define the 4-20 mA output range. For example, a transmitter might be configured for 0°C to 100°C, outputting 4 mA at 0°C and 20 mA at 100°C. Some transmitters offer adjustable ranges, allowing configuration for specific application requirements.

Accuracy specifications for industrial temperature transmitters typically range from ±0.5% to ±1.0% of the full scale. A transmitter configured for 0-100°C with ±0.5% accuracy maintains accuracy within ±0.5°C across the entire range. Response time, typically 100-500 milliseconds, depends on the sensor type and transmitter design.

Temperature Measurement in Chemical Processes

Chemical manufacturing requires precise temperature control to ensure product quality and safety. Consider a reactor where exothermic reactions must be maintained at 65°C ± 2°C. A temperature transmitter with a 0-100°C range outputs 4 mA at 0°C and 20 mA at 100°C.

The PLC reads the current value and converts it to temperature using the standard formula. If the temperature rises above 67°C, the PLC activates cooling systems. If it drops below 63°C, heating systems activate. The PLC continuously monitors the transmitter output, adjusting heating and cooling to maintain the setpoint.

The 4-20 mA signal's noise immunity is particularly valuable in chemical plants where numerous high-power equipment creates electromagnetic interference. The current-based signal remains stable despite the harsh electrical environment, ensuring reliable process control.

HVAC System Temperature Monitoring

Heating, ventilation, and air conditioning systems use multiple temperature sensors to optimize comfort and energy efficiency. A typical commercial HVAC system includes sensors for outdoor air temperature, indoor air temperature, supply air temperature, and return air temperature.

In a building with a central PLC controlling multiple zones, 4-20 mA temperature transmitters provide reliable measurements from each zone. A transmitter configured for -20°C to 50°C provides adequate range for most HVAC applications. The PLC reads all transmitters and adjusts dampers, fan speeds, and heating/cooling equipment to maintain setpoints in each zone.

The distributed nature of HVAC systems makes 4-20 mA signals particularly valuable. Sensors located hundreds of meters from the central control room can transmit accurate temperature data without signal degradation. The current-based signal maintains integrity through long cable runs that would degrade voltage-based signals.

Food and Beverage Processing

Food processing requires strict temperature control for both product quality and food safety. Pasteurization processes, for example, must maintain specific temperatures for specific durations to eliminate pathogens while preserving product quality.

A milk pasteurization system uses multiple temperature transmitters: one monitoring the incoming milk temperature, one monitoring the heating section, one monitoring the holding section, and one monitoring the cooling section. Each transmitter is configured for the appropriate range: perhaps -10°C to 80°C for the cooling section and 40°C to 100°C for the heating section.

The PLC monitors all transmitters and controls heating and cooling equipment to maintain the required temperature profile. If any temperature deviates from setpoint, the PLC can trigger alarms or automatically divert product to waste. The system maintains detailed records of all temperatures for food safety compliance and traceability.

Pharmaceutical Manufacturing

Pharmaceutical manufacturing demands exceptional accuracy and reliability in temperature measurement. Many processes require maintaining temperatures within ±1°C of setpoint. High-accuracy temperature transmitters with ±0.2% accuracy are often specified for these applications.
In a sterile manufacturing environment, transmitters are often mounted in hygienic housings that can be cleaned in place. The 4-20 mA signal transmits through the facility's control wiring to the central PLC. The PLC logs all temperature data, creating audit trails required by regulatory agencies.

Redundant temperature measurement is common in pharmaceutical applications. Two independent transmitters measure the same parameter, and the PLC compares their readings. If they diverge beyond a threshold, the system alerts operators to investigate potential problems.

Power Plant and Utility Applications

Power plants use temperature measurement throughout their operations: boiler outlet temperature, steam temperature, condenser cooling water temperature, and numerous other critical measurements. These measurements span wide ranges, from ambient temperature to several hundred degrees Celsius.
A coal-fired power plant might use a temperature transmitter configured for 0-400°C to monitor superheated steam temperature. The transmitter outputs 4 mA at 0°C and 20 mA at 400°C. The PLC reads this value and adjusts fuel flow to maintain optimal steam temperature for maximum efficiency.
The reliability of 4-20 mA signals is critical in utility applications where measurement failures can result in equipment damage or power outages. The current-based signal's inherent diagnostics (4 mA minimum) allow the system to detect broken wires or failed transmitters immediately.

Temperature Alarm Implementation

A practical PLC implementation includes temperature alarm logic. Consider a system monitoring a reactor temperature with a 0-100°C transmitter:
ORGANIZATION_BLOCK "TemperatureControl"
VAR
raw_count : INT;
temperature : REAL;
high_alarm : BOOL;
low_alarm : BOOL;
high_setpoint : REAL := 70.0;
low_setpoint : REAL := 60.0;
END_VAR;

BEGIN // Convert raw count to temperature temperature := (raw_count - 819) / 3276 * 100; // Check alarm conditions IF temperature > high_setpoint THEN high_alarm := TRUE; ELSIF temperature < high_setpoint - 2 THEN high_alarm := FALSE; END_IF; IF temperature < low_setpoint THEN low_alarm := TRUE; ELSIF temperature > low_setpoint + 2 THEN low_alarm := FALSE; END_IF;
END_ORGANIZATION_BLOCK

Conclusion

Temperature measurement using 4-20 mA transmitters provides reliable, accurate monitoring for diverse industrial applications. From chemical processes to HVAC systems, food processing to power plants, 4-20 mA temperature measurement remains the standard choice for critical temperature control. Understanding sensor types, transmitter configuration, PLC integration, and alarm implementation enables automation professionals to design and maintain effective temperature monitoring systems that ensure product quality, operational safety, and regulatory compliance.

Key Takeaways

RTDs, thermocouples, and thermistors each offer different characteristics for temperature measurement
Temperature transmitters convert sensor signals to standardized 4-20 mA outputs
Transmitter configuration defines the temperature range corresponding to 4-20 mA
PLC programs convert raw counts to temperature using standard formulas
Alarm logic protects processes from temperature excursions
4-20 mA signals provide reliable measurement in harsh industrial environments

May 20, 2026

Clean Code for PLCs: Best Practices for Writing Readable and Maintainable SCL

The principles of clean code—established in software engineering decades ago—apply equally to PLC programming.

 

Title: Clean Code Principles Framework - Description: Clean Code Principles Framework

 

The diagram above illustrates how multiple clean code principles converge to produce readable, maintainable code that delivers long-term value. As SCL adoption grows and PLC projects become more complex, the importance of writing maintainable, readable code cannot be overstated. A PLC program that runs correctly today but is incomprehensible to the next engineer who maintains it creates technical debt and increases the risk of costly errors. This article explores best practices for writing clean, professional SCL code that stands the test of time.

 

The Cost of Messy Code

Before diving into best practices, it is worth understanding why clean code matters in industrial automation. A poorly written PLC program might function correctly initially, but as systems evolve and requirements change, maintenance becomes increasingly difficult. Engineers spend more time deciphering existing code than writing new code. Bugs are harder to identify and fix. Testing becomes unreliable. The cost of these inefficiencies multiplies over the lifetime of a system, often exceeding the initial development cost many times over.

 

In safety-critical applications, messy code introduces additional risks. If an engineer cannot quickly understand how a system works, they cannot confidently make changes or troubleshoot issues. This can lead to safety incidents and regulatory compliance problems.

 

Naming Conventions: The Foundation of Clarity

Clear, descriptive names are the foundation of readable code. Variable, function, and block names should immediately convey their purpose. Avoid cryptic abbreviations or single-letter variables (except in mathematical contexts where conventions are well-established).

 

Poor Example:

VAR

    x, y, z : REAL;

    t1, t2 : INT;

    f : BOOL;

END_VAR

 

Good Example:

VAR

    motor_speed_rpm : REAL;

    motor_temperature_celsius : REAL;

    pressure_bar : REAL;

    timer_delay_seconds : INT;

    timer_elapsed_seconds : INT;

    motor_fault_detected : BOOL;

END_VAR

 

Adopt a consistent naming convention across your organization. Common approaches include:

 

        Snake_case: motor_speed_rpm, temperature_sensor_input

        camelCase: motorSpeedRpm, temperatureSensorInput

        Hungarian notation: fMotorFault, iMotorSpeed (where prefix indicates type)

 

The specific convention matters less than consistency. Choose one and apply it uniformly across all projects.

 

Comments: Explain the Why, Not the What

Comments should explain the reasoning behind code, not simply restate what the code does. Code that is well-written and properly named largely explains itself. Comments should address the "why"—the business logic, design decisions, and non-obvious implications.

 

Poor Comment:

// Increment counter

counter := counter + 1;

 

Good Comment:

// Increment counter to track number of bottles processed

// Reset occurs when daily production target is reached

counter := counter + 1;

 

Use comments to document assumptions, constraints, and potential pitfalls. Explain complex algorithms and non-obvious optimizations. Comment edge cases and error conditions.

 

Function Design: Single Responsibility Principle

Each function should have a single, well-defined responsibility. A function that does multiple things is harder to test, reuse, and maintain. Apply the Single Responsibility Principle (SRP) from software engineering to PLC code.

 

Poor Design:

FUNCTION_BLOCK ProcessData

    // Reads sensors, validates data, calculates statistics, and logs results

    // Does too many things

END_FUNCTION_BLOCK

 

Good Design:

FUNCTION_BLOCK ReadSensors

    // Responsibility: Read sensor inputs and perform basic validation

END_FUNCTION_BLOCK

 

FUNCTION_BLOCK CalculateStatistics

    // Responsibility: Calculate statistical metrics from validated data

END_FUNCTION_BLOCK

 

FUNCTION_BLOCK LogResults

    // Responsibility: Format and log results to persistent storage

END_FUNCTION_BLOCK

 

Smaller, focused functions are easier to test, understand, and reuse. They also facilitate code reuse across different projects.

 

DRY Principle: Don't Repeat Yourself

Duplicated code is a maintenance nightmare. When a bug is found in duplicated logic, it must be fixed in every location. When requirements change, all copies must be updated. Use functions and function blocks to eliminate duplication.

 

Poor (Duplicated Code):

// In Module A

IF sensor_value > threshold THEN

    alarm_triggered := TRUE;

    log_event("High sensor value detected");

    send_notification("Alert: Sensor threshold exceeded");

END_IF;

 

// In Module B

IF another_sensor > threshold THEN

    alarm_triggered := TRUE;

    log_event("High sensor value detected");

    send_notification("Alert: Sensor threshold exceeded");

END_IF;

 

Good (Reusable Function):

FUNCTION TriggerAlarm

VAR_INPUT

    sensor_name : STRING;

    sensor_value : REAL;

END_VAR

    alarm_triggered := TRUE;

    log_event(CONCAT("High ", sensor_name, " value detected"));

    send_notification(CONCAT("Alert: ", sensor_name, " threshold exceeded"));

END_FUNCTION

 

// Usage in both modules

TriggerAlarm("sensor_value", sensor_value);

TriggerAlarm("another_sensor", another_sensor);

 

Modularity and Encapsulation

Organize code into logical modules, each with a clear interface. Use User Defined Types (UDTs) and function blocks to encapsulate related data and operations. This promotes code reuse and makes systems easier to understand.

 

Example: Encapsulated Motor Controller

TYPE MotorController

    speed_setpoint : REAL;

    current_speed : REAL;

    temperature : REAL;

    fault_detected : BOOL;

   

    FUNCTION_BLOCK MotorController

        // Initialize motor controller

    END_FUNCTION_BLOCK

   

    FUNCTION Start

        // Start motor with safety checks

    END_FUNCTION

   

    FUNCTION Stop

        // Stop motor gracefully

    END_FUNCTION

   

    FUNCTION UpdateSpeed

        // Update motor speed based on setpoint

    END_FUNCTION

END_TYPE

 

This encapsulation makes it clear what operations are available on a motor controller and ensures consistent behavior.

 

Error Handling and Defensive Programming

Write code that anticipates and handles errors gracefully. Use return codes or exceptions to signal error conditions. Validate inputs before processing them.

 

Example: Defensive Function

FUNCTION CalculateAverage

VAR_INPUT

    values : ARRAY[1..100] OF REAL;

    count : INT;

END_VAR

VAR_OUTPUT

    average : REAL;

    error : BOOL;

END_VAR

 

// Validate input

IF count <= 0 OR count > 100 THEN

    error := TRUE;

    average := 0.0;

    RETURN;

END_IF;

 

// Calculate average

VAR sum : REAL := 0.0;

FOR i := 1 TO count DO

    sum := sum + values[i];

END_FOR;

 

average := sum / count;

error := FALSE;

 

Code Organization and Structure

Organize your SCL projects with a clear directory structure and naming convention. Group related function blocks, functions, and data types together. Use meaningful section comments to delineate different parts of the code.

 

Example Project Structure:

Project/

├── GlobalData/

   ├── DataTypes.scl (UDTs and custom types)

   ├── Constants.scl (Project-wide constants)

   └── GlobalVariables.scl (Global variables)

├── MotorControl/

   ├── MotorController.scl (Motor control function block)

   └── MotorFunctions.scl (Helper functions)

├── Sensors/

   ├── SensorReader.scl (Sensor input handling)

   └── SensorCalibration.scl (Calibration functions)

└── Main/

    └── Main.scl (Main program logic)

 

Testing and Validation

Write code with testability in mind. Use function blocks that can be instantiated and tested independently. Create unit tests for critical functions. Document test cases and expected results.

 

Example: Testable Function

FUNCTION_BLOCK PIDController

    // Designed to be tested independently

    // Inputs and outputs are clearly defined

    // No dependencies on external systems

END_FUNCTION_BLOCK

 

// Test case

VAR

    pid : PIDController;

    setpoint, process_value : REAL;

    output : REAL;

END_VAR

 

// Test 1: Zero error should produce zero output

setpoint := 100.0;

process_value := 100.0;

pid(setpoint := setpoint, process_value := process_value);

output := pid.output;

// Assert output ≈ 0.0

 

Documentation

Maintain comprehensive documentation that explains the overall architecture, key algorithms, and design decisions. Document assumptions about hardware, communication protocols, and external systems. Keep documentation synchronized with code changes.

 

Documentation Checklist:

        System architecture and data flow

        Function and function block descriptions

        Variable definitions and their units

        Error codes and their meanings

        Safety considerations and interlocks

        Known limitations and future improvements

        Change history and version control information

 

Conclusion

Clean code is not a luxury in PLC programming—it is a necessity. As automation systems become more complex and the cost of downtime increases, the ability to quickly understand and modify code becomes critical. By following these best practices—clear naming, focused functions, comprehensive comments, modularity, error handling, and thorough documentation—engineers create code that is reliable, maintainable, and professional.

 

The investment in writing clean code pays dividends throughout the system's lifecycle. Bugs are easier to find and fix. New team members can understand the code quickly. Changes can be made confidently. In the long run, clean code reduces costs, improves reliability, and enables innovation. For any engineer serious about their craft, mastering these practices is essential.

 

References

[1] Clean Code: A Handbook of Agile Software Craftsmanship - Robert C. Martin

[2] Code Complete: A Practical Handbook of Software Construction - Steve McConnell

[3] Siemens TIA Portal Programming Guidelines - https://support.industry.siemens.com/cs/document/109742519