As PLC projects grow in complexity, organizing data becomes critical for both readability and maintainability. Using individual variables quickly becomes inefficient and error-prone, especially when dealing with repeated structures such as sensor arrays, motor configurations, or control parameters. This is where User-Defined Data Types (UDTs) come into play.
UDTs allow engineers to define their own structured data types that group multiple related variables under a single object. These structures can then be reused throughout a project, dramatically improving consistency, reducing code duplication, and simplifying troubleshooting
This chapter introduces the concept of structured data in the TIA Portal and explains how to create and implement UDTs in real-world automation projects. You’ll learn how to design logical, scalable data structures and use them effectively inside data blocks and function blocks.
Objectives
By the end of this chapter, you will be able to:
- Understand the concept and purpose of structured data and UDTs in PLC programming.
- Create custom data types (UDTs) in TIA Portal for common industrial use cases.
- Implement UDTs within global and instance data blocks (DBs).
- Use arrays of UDTs to manage large sets of related components (e.g., sensors, actuators).
- Apply best practices for naming, organizing, and documenting structured data.
Why UDTs Are Important
Using UDTs introduces several advantages into your PLC project architecture:
- Consistency: All devices or components that share the same data structure can be initialized and handled in a uniform way.
- Reusability: A single UDT definition can be reused across many blocks or functions, reducing programming time.
- Scalability: Adding more components (e.g., 50 temperature sensors) becomes a matter of extending an array, not duplicating logic.
- Maintainability: Well-structured data is easier to troubleshoot, monitor, and modify over time.
- Clarity: Your code becomes more readable for both yourself and other engineers who may work on the project in the future.
When to Use UDTs
UDTs are particularly useful in the following scenarios:
- Grouping sensor or actuator data (e.g., status, value, diagnostics).
- Creating configuration profiles for devices such as motors, valves, or pumps.
- Defining control parameters (e.g., setpoints, limits, gains) for PID or motion logic.
- Structuring communication data with external systems or PCBs.
Practical Example: Handling an Array of Buttons Using a UDT and IN_OUT
To demonstrate the benefits of structured data and reusable logic, let’s consider a typical scenario in automation systems — managing a set of input buttons and their corresponding feedback.
Creating the UDT
A UDT named button is defined with two substructures:

Creating New PLC Data Type
- command: Contains control signals such as .enable (Bool)
- feedback: Contains status signals such as .enabled (Bool)
This structure allows a clean separation between control inputs and feedback outputs for each button.

Structure of a PLC Data TypePicture 3: Use this Data Type to create an array of buttons
Creating an Array of Buttons
In a global data block, an array of 10 buttons is created:
This models a panel or interface with 10 independent buttons, each having its own command and feedback data

Array of UDT on a Global Data Block
Function Block with IN_OUT Parameter
A function block (FB) is created with the following interface:
Using IN_OUT allows the function block to read and modify the original data in the calling block, maintaining data integrity across the project without needing intermediate variables or return values.
Implementation Logic
Inside the function block, a FOR loop is used to iterate through all 10 buttons. For each one, the code checks whether the command.enable flag is set. If it is, the feedback.enabled is set to true. Otherwise, it is set to false.

FB – UDT as inOut variable

Call the FB on OB and map the buttons of Data block to the input of FB
This simple loop-based logic demonstrates several key programming practices:
- How to efficiently iterate over structured data using loops
- How to use IN_OUT parameters to directly interact with DB data
- How structured design improves readability and modularity
Why This Matters
Without using UDTs and arrays, the same logic would require 10 individual IF statements, each targeting separate variables. This not only increases code size but also leads to duplication and higher risk of errors.
By combining UDTs, arrays, and structured access, the code becomes significantly more scalable, clean, and easy to maintain — especially when the number of elements increases or the logic becomes more complex.
If you found this helpful, please consider supporting with a small donation. Thank you!
Leave a Reply