Learn SIEMENS-TIA-PORTAL with Real Code Examples
Updated Nov 26, 2025
Code Sample Descriptions
1
Hello World in Siemens TIA Portal (SCL - Structured Control Language)
IF Start_Button = TRUE THEN
Motor_Output := TRUE;
ELSE
Motor_Output := FALSE;
END_IF;
A basic SCL program in TIA Portal setting an output when a condition is met.
2
Timer Example in TIA Portal (SCL)
TON_DB(IN := Start_Button,
PT := T#5s,
Q => Motor_Output,
ET => Elapsed_Time);
Using an on-delay timer (TON) in SCL.
3
Counter Example in TIA Portal (SCL)
IF Pulse = TRUE THEN
Counter := Counter + 1;
END_IF;
A simple up-counter that increments when a signal is TRUE.
4
Move Instruction in TIA Portal (SCL)
Temp_Value := Sensor_Value;
Copying a value into a variable using SCL.
5
Analog Input Scaling in SCL
Scaled := (Raw_AI * 100.0) / 27648.0;
Scaling raw analog input (0–27648) to engineering units.
6
Start/Stop Motor Logic (SCL)
IF Start = TRUE THEN
Motor := TRUE;
END_IF;
IF Stop = TRUE THEN
Motor := FALSE;
END_IF;
Basic motor latch logic using start/stop switches.
7
Edge Detection (SCL)
Prev_Signal := Current_Signal;
Current_Signal := Input;
Rising_Edge := Current_Signal AND NOT Prev_Signal;
Detecting a rising edge of a signal.
8
Array Loop in SCL
Sum := 0;
FOR i := 1 TO 10 DO
Sum := Sum + Values[i];
END_FOR;
Summing values of an INT array.
9
Simple FB With Input/Output (SCL)
Double_Value := In_Value * 2;
A Function Block that outputs double the input value.
10
PID Call in TIA Portal (SCL)
PID_DB(
PV := Process_Value,
SP := Setpoint,
OUT => Control_Output
);
Calling a PID controller block in SCL.