You are on page 1of 46

PLC programming using CODESYS YouTube

channel - A guide to watching videos in a proper


order

Tohid Alizadeh

January 14, 2023


Contents

1 Introduction 6
1.1 Creating a first project . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2 Exporting and Importing projects . . . . . . . . . . . . . . . . . 7
1.3 Declaring constant variables . . . . . . . . . . . . . . . . . . . . . 7
1.4 Declaring Array type variables . . . . . . . . . . . . . . . . . . . 7
1.5 Creating Global variable list . . . . . . . . . . . . . . . . . . . . . 7
1.6 How to create and use Function blocks in the project . . . . . . . 8
1.7 Protecting the project with password . . . . . . . . . . . . . . . . 8

2 Ladder Logic Diagram 9


2.1 Normally open/closed pushbuttons and normal/negated contacts 9
2.2 Self-holding or Seal-in circuit in Ladder logic . . . . . . . . . . . 9
2.3 Using SR and RS function blocks in Ladder logic . . . . . . . . . 9
2.4 Set/Reset or Latch/Unlatch instructions in Ladder logic . . . . . 10
2.5 Jump and Label instructions in Ladder logic . . . . . . . . . . . . 10
2.6 Using TON (timer on-delay) function blocks in Ladder Logic . . 10
2.7 Using (CTUD) up/down counter function block . . . . . . . . . 10
2.8 Using TP (pulse timer) function block . . . . . . . . . . . . . . . 10
2.9 TOF (timer off-delay) function block in Ladder logic . . . . . . 11
2.10 Combining TON (On-delay timers) to create flashing signal (square
wave) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

3 Function Block Diagram 12

4 Structured Text 13
4.1 Hello ST (the simplest example) . . . . . . . . . . . . . . . . . . 13
4.2 Using Set and Reset instructions in ST . . . . . . . . . . . . . . . 13
4.3 Self-holding program in ST . . . . . . . . . . . . . . . . . . . . . 13
4.4 Using For loop instruction in ST . . . . . . . . . . . . . . . . . . 13
4.5 Using TON and CTU instructions in ST . . . . . . . . . . . . . . 14
4.6 Declaring and using ”Structure” in the structured text (ST) pro-
gramming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.7 IF-ELSEIF instruction in Structured text programming . . . . . 14
4.8 Using CASE instruction in ST . . . . . . . . . . . . . . . . . . . 14

1
4.9 Using While-Do loop instruction in ST . . . . . . . . . . . . . . . 14
4.10 Using Repeat-Until loop instruction in ST . . . . . . . . . . . . . 14
4.11 Using Jump (JMP) instruction and comments in ST . . . . . . . 14
4.12 Using Return instruction and comments in ST . . . . . . . . . . 15
4.13 Using SHift Left (SHL) and SHift Right (SHR) instructions in ST 15
4.14 Unit Conversion in Structured Text (ST) . . . . . . . . . . . . . 15
4.15 Creating and using function blocks in ST . . . . . . . . . . . . . 15
4.16 Creating and using Functions in Structured Text (ST) . . . . . . 15
4.17 R Trig and F Trig (Rising and falling edge detection) instructions
in Structured Text (ST) . . . . . . . . . . . . . . . . . . . . . . . 16

5 Sequential Function Chart 17


5.1 Introduction to SFC . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.2 Different types of actions . . . . . . . . . . . . . . . . . . . . . . 17
5.3 Implicit variables in Steps . . . . . . . . . . . . . . . . . . . . . . 18
5.4 Editor options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5.5 SFC Action Qualifiers . . . . . . . . . . . . . . . . . . . . . . . . 18

6 Continuous Function Chart 19


6.1 First lesson . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
6.2 Composer element in CFC . . . . . . . . . . . . . . . . . . . . . . 19
6.3 Using Limit operator in CFC . . . . . . . . . . . . . . . . . . . . 19
6.4 Selector element in CFC programming . . . . . . . . . . . . . . . 20
6.5 Set/Reset instructions and Execution order in CFC programming 20
6.6 MUX (Multiplexer) function in CFC . . . . . . . . . . . . . . . . 20
6.7 Interlocking using Interlock function block from OSCAT library
in CFC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
6.8 HYSTERSIS function block in CFC . . . . . . . . . . . . . . . . 21
6.9 Using LIMITALARM function block in CFC . . . . . . . . . . . 21
6.10 Using Blink function block in CFC . . . . . . . . . . . . . . . . . 21
6.11 FIFO function block (from OSCAT library) in CFC . . . . . . . 21
6.12 Linear Transformation (LIN TRAFO) function block . . . . . . . 22
6.13 Standard String Functions . . . . . . . . . . . . . . . . . . . . . 22
6.14 GEN (Function Generator) function block in CFC . . . . . . . . 23

7 Instruction List 24

8 Visualization 25
8.1 Displaying dynamic values (in the Text field) . . . . . . . . . . . 25
8.2 Controlling the visibility of objects . . . . . . . . . . . . . . . . . 25
8.3 Creating a vertical Bar display . . . . . . . . . . . . . . . . . . . 25
8.4 Controlling the movement (position) of objects . . . . . . . . . . 26
8.5 Creating momentary switches (NC and NO) . . . . . . . . . . . . 26
8.6 Using ComboBox integer to manipulate the value of an integer
variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
8.7 Using SpinControl to manipulate the value of an integer variable 26

2
8.8 Using Trace to display variables as graphs . . . . . . . . . . . . . 26
8.9 Working with images . . . . . . . . . . . . . . . . . . . . . . . . . 27
8.10 Using the Frame element . . . . . . . . . . . . . . . . . . . . . . . 27
8.11 Enabling Grid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
8.12 VisuSymbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
8.13 Controlling the color of objects . . . . . . . . . . . . . . . . . . . 27
8.14 Text Display Animation . . . . . . . . . . . . . . . . . . . . . . . 28
8.15 Calling a Dialog Box (and using Date Picker) . . . . . . . . . . . 28
8.16 Combo Box Array . . . . . . . . . . . . . . . . . . . . . . . . . . 28
8.17 Getting User Input (Numeric value) in Visualization . . . . . . . 28
8.18 Saving and Loading Data Using Trace . . . . . . . . . . . . . . . 29
8.19 Rotate and Scale visualization elements . . . . . . . . . . . . . . 29
8.20 Adding/removing edges to/from polygon, polyline, and Bezier
curve elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
8.21 Switching between Visualizations . . . . . . . . . . . . . . . . . . 30
8.22 Navigating among Visualization windows using Combo Box In-
teger and Text List . . . . . . . . . . . . . . . . . . . . . . . . . . 30
8.23 Momentary versus Maintained switches - Convert a maintained
switch into a momentary one . . . . . . . . . . . . . . . . . . . . 31
8.24 Switching between Languages . . . . . . . . . . . . . . . . . . . . 31

9 PLC programming examples 32


9.1 Programming Retentive on-delay timer . . . . . . . . . . . . . . . 32
9.2 Simple LD programming example - Water level control . . . . . 32
9.3 Simple LD programming example - using On-delay timers . . . . 33
9.4 Ladder Logic Diagram programming example . . . . . . . . . . . 33
9.5 Ladder logic diagram (LLD) programming example . . . . . . . . 33
9.6 Simulating 7-segment displays . . . . . . . . . . . . . . . . . . . . 33
9.7 Structured Text (ST) programming example - Traffic light control 34
9.8 Structured Text (ST) programming example - Traffic control . . 34
9.9 ST programming example - Programming state machines . . . . 34
9.10 SFC programming example- Traffic light control in the intersection 35
9.11 SFC Example - Traffic lights control with a single SFC step -
Action qualifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
9.12 CFC programming example - Tank Simulation . . . . . . . . . . 35
9.13 String Animation Example . . . . . . . . . . . . . . . . . . . . . 35

10 Sample Course Projects 36


10.1 Sample project 01 - Candy packaging simulation . . . . . . . . . 36
10.2 Sample project 02 . . . . . . . . . . . . . . . . . . . . . . . . . . 36
10.3 Sample project 03 - Postal mail sorting - open source code . . . . 37
10.4 Sample project 04 - Recycling plant - Open source code . . . . . 37
10.5 Sample project 05 - Simulation of Elevator - open source code . . 37
10.6 Sample project 06 - Car parking simulation . . . . . . . . . . . . 37

3
11 SoftMotion 38
11.1 Introduction to SoftMotion with CFC . . . . . . . . . . . . . . . 38
11.2 Analog clock simulation . . . . . . . . . . . . . . . . . . . . . . . 38
11.3 Using MC PositionProfile function block . . . . . . . . . . . . . . 38
11.4 Robotics - An introductory tutorial: Simulating SCARA-2 robot 39

12 Debugging and Troubleshooting 40


12.1 Watch Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
12.2 Alarm Management tutorial . . . . . . . . . . . . . . . . . . . . . 40
12.3 Debugging the code in the structured text (ST) in ST . . . . . . 41
12.4 PLC Cycle time using Cycle time function block from OSCAT
library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
12.5 CODESYS V3.5.7.0, visualization bug . . . . . . . . . . . . . . . 41
12.6 CODESYS V3.5.7.0, visualization bug - RESOLUTION . . . . . 41
12.7 Visualization Issue - Resolution 02 . . . . . . . . . . . . . . . . . 42

13 Miscllanous 43
13.1 Text List - Dynamic Text . . . . . . . . . . . . . . . . . . . . . . 43
13.2 An introduction to Recipes - Part 01 - Recipe management through
Visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

14 Additional Resources 44
14.1 CODESYS online help and CODESYS Forum . . . . . . . . . . . 44
14.2 Facebook Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
14.3 CODESYS group YouTube Channel . . . . . . . . . . . . . . . . 44
14.4 Jakob Sagatowski YouTube channel . . . . . . . . . . . . . . . . 44
14.5 Gary Pratt YouTube channel . . . . . . . . . . . . . . . . . . . . 45
14.6 Brian Hobby YouTube channel . . . . . . . . . . . . . . . . . . . 45
14.7 SquishyBrained YouTube channel . . . . . . . . . . . . . . . . . . 45
14.8 Carlos Abner YouTube channel . . . . . . . . . . . . . . . . . . . 45

4
Foreword

CODESYS is becoming more and more popular in the industrial automation do-
main as one of the main brand-independent platforms for implementing indus-
trial automation projects. Over the last six years, I have created video tutorials
and uploaded them on my Youtube channel (www.youtube.com/@TohidAlizadeh)
to help my students, among others, understand the usage of CODESYS. I have
classified the videos using YouTub playlists to help the viewers find the video
that helps them in achieving a specific task easily. However, I have received
many requests from the audience to create a kind of road map for using the
video tutorials in a more organized way. Therefore, I am preparing this docu-
ment and will update it occasionally, to provide a guideline for using my video
lectures. This guideline will be heavily based on my published videos, but
eventually, it could be used as a reference to learn PLC programming using
CODESYS.
I will try to keep this document short and to the point, avoiding additional
explanations and will keep it freely available!
Please don’t forget to SUBSRIBE and share the videos to support me.

5
Chapter 1

Introduction

In this chapter, the necessary information about CODESYS will be provided.


CODESYS is a platform independent which makes learning PLC programming
easier and transferrable from one brand to another. Traditionally, every PLC
brand has its own programming environment and an adapted version of the
IEC611-31-3 standard programming languages. Therefore, to be able to work
with a specific PLC, one should learn the programming environment details and
the specific features first. To use a PLC from another brand, a similar process
should be followed. While in the case of using CODESYS, the programming
environment would be common among several different brands, and learning it
from one brand will make one able to smoothly switch to using a PLC from an-
other brand. PLC Manufacturers of different brands apply some changes to the
original CODESYS version to make it suitable for their brand, but it mostly in-
volves including pre-installed libraries and some appearance specifications. So,
it is not a big deal to switch from one brand to another.
To download and install CODESYS, you can refer to CODESYS store, create
a user, and then while you are logged in, search for CODESYS 3. You can
download and install the 32-bit or 64-bit version, depending on your system. In
this tutorial, I mostly assume that you will use CODESYS only in the simula-
tion mode, or use the soft PLC (CODESYS Control Win) which is installed at
the time of installing CODESYS. As an alternative, CODESYS is also available
through the repositories of some brands such as EATON and FESTO. You can
directly refer to those repositories and download a version of the CODESYS
which is personalized for that brand. There will be not much difference for the
purposes of this tutorial/manual.

1.1 Creating a first project


Once you have CODESYS installed, to create a new project you have to run it by
double-clicking on its icon on the desktop for example, similar to any Windows-

6
based application. Follow this video tutorial to learn more details and the steps
you need to take to add a visualization to the project as well. After watching
the video you should learn how to create an empty project, where to develop
the code and how to insert a very simple visualization, and then how to compile
and run the code in the Simulation mode.
Click here to watch the video on YouTube

1.2 Exporting and Importing projects


When you create a new project and develop it, many files are created in a
directory, related to the project, and all of them are needed in order to have the
project working properly. Now, if you want to transfer the project to someone
else, it wouldn’t be nice to copy all of such files and send them. Instead, you
can create a CODESYS archive as one file and transfer that. The other party
should import the archive and it will be extracted properly with CODESYS. In
this video, you will learn how to export and import the project as an archive.
Click here to watch the video on YouTube

1.3 Declaring constant variables


The variables in the program can be forced with values in the run time. However,
as a programmer, you may want to have some variables which are not accessible
by the operators, and they have to keep a constant value. In this video, you will
learn how to declare such variables, which are not changeable in the run time
by forcing value.
Click here to watch the video on YouTube

1.4 Declaring Array type variables


Array variables can contain more than one variable in their elements, similar to
vectors. Instead of declaring 10 variables of the same type, you can declare one
array variable of length 10 and put the values inside the array, for example. In
this video, you will learn how to declare the Array variables and how to access
the elements of the array in the program.
Click here to watch the video on YouTube

1.5 Creating Global variable list


To be able to use a variable in the CODESYS environment, you need to declare
the variable. However, each variable has a scope within which it is accessible (in
the main program, inside a specific function block, ...). To create variables that
are accessible all along the project, you can create a Global variable list and
declare the variables over there. These variables will be accessible anywhere in

7
the project. In this video, you will learn how to create the Global variable list
and call the variables in the program.
Click here to watch the video on YouTube

1.6 How to create and use Function blocks in


the project
Function blocks are very useful in PLC programming (with any language): they
decrease the amount of effort in developing a program, they make the code more
compact and readable, and so on. There are some function blocks ready to use
by default, such as Timers and counters. However, you can create your own
function block and use them in the project. In this video, you will learn how to
create function blocks and use them in the main program.
Click here to watch the video on YouTube

1.7 Protecting the project with password


In this video, you will learn how to protect your CODESYS project using a
password. To open the project, the user needs to have a password. You can
also remove the password later on.
Click here to watch the video on YouTube

8
Chapter 2

Ladder Logic Diagram

Ladder Logic Diagram or LLD (sometimes referred to as LD as well), is one of


the basic standard PLC programming languages. It originated from the Relay
Logic Diagrams and is a graphical language.

2.1 Normally open/closed pushbuttons and nor-


mal/negated contacts
In this video, you will learn the differences between the normally open and nor-
mally closed push buttons and between normal (examine if closed) and negated
(examine if open) contacts in the ladder logic program.
Click here to watch the video on YouTube

2.2 Self-holding or Seal-in circuit in Ladder logic


In this video, you will learn the idea of self-holding or Seal-in circuits in Ladder
logic. This is a way to keep the output devices energized after pressing and
releasing a momentary push button.
Click here to watch the video on YouTube

2.3 Using SR and RS function blocks in Ladder


logic
In this video, you will learn how to insert the RS and SR function blocks into
the Ladder logic program, how they operate and what is the difference between
the two.
Click here to watch the video on YouTube

9
2.4 Set/Reset or Latch/Unlatch instructions in
Ladder logic
In this video, you will learn how the Set/Reset or Latch/Unlatch coil instructions
can be used in Ladder logic.
Click here to watch the video on YouTube

2.5 Jump and Label instructions in Ladder logic


In this video, you will learn how to use the Jump and Label instructions in
CODESYS.
Click here to watch the video on YouTube

2.6 Using TON (timer on-delay) function blocks


in Ladder Logic
In this video, you will see how to use a TON (on-delay timer) function block in
CODESYS, with Ladder Logic Diagram as the programming language. TON
or on-delay timers are used to create a delay after they receive a True pulse
at their input. The TON function block has two inputs and two outputs. The
inputs are EN (enable) and PT (Preset time), and the outputs are Q (the main
boolean output) and EL (Elapsed time). As soon as the EN input has a False to
True transition, the timing starts and when PT time has passed the Q output
becomes true and remains true. Whenever the EN input becomes False, the Q
output becomes False, immediately.
Click here to watch the video on YouTube

2.7 Using (CTUD) up/down counter function


block
In this video, you will see how to insert an up/down counter into the ladder
logic program and how to provide the inputs and observe the outputs of the
function block.
Click here to watch the video on YouTube

2.8 Using TP (pulse timer) function block


In this video, you will see how to use a TP (pulse timer) function block in
CODESYS.
Click here to watch the video on YouTube

10
2.9 TOF (timer off-delay) function block in Lad-
der logic
In this video, you will see how to use the TOF (off-delay timer) function block
in CODESYS.
Click here to watch the video on YouTube

2.10 Combining TON (On-delay timers) to cre-


ate flashing signal (square wave)
In this video, you will learn how to combine the TON (on-delay timers) with
each other to generate a flashing signal (square wave).
Click here to watch the video on YouTube

11
Chapter 3

Function Block Diagram

Function Block Diagram is another graphical language used for programming


PLCs. This language uses blocks to perform the processing of data and the
blocks are connected to each other using the inputs and outputs (somehow
similar to Matlab/Simulink, or Labview). In the CODESYS environment, you
can easily convert LLD to FBD and vice versa. In this video, you will learn
the basics of programming PLCs with Function Block Diagramming (FBD)
language.
Click here to watch the video on YouTube

12
Chapter 4

Structured Text

Structured text (ST) is a textual PLC programming language.

4.1 Hello ST (the simplest example)


In this video, you will learn how to start programming PLC using ST, following
a very simple example.
Click here to watch the video on YouTube

4.2 Using Set and Reset instructions in ST


In this video, you will learn how to use the Set and Reset instructions in the
structured text.
Link to the video: https://youtu.be/0ltQMjkYTjs Click here to watch
the video on YouTube

4.3 Self-holding program in ST


In this video, you will learn how to write the self-holding program in the struc-
tured text.
Click here to watch the video on YouTube

4.4 Using For loop instruction in ST


In this video, you will learn how to use the FOR loop in structured text.
Click here to watch the video on YouTube

13
4.5 Using TON and CTU instructions in ST
In this video, you will learn how to use the TON and CTU instructions (func-
tions) in the structured text.
Click here to watch the video on YouTube

4.6 Declaring and using ”Structure” in the struc-


tured text (ST) programming
In this video, you will learn how to create and use the Structure variables in
ST.
Click here to watch the video on YouTube

4.7 IF-ELSEIF instruction in Structured text


programming
In this video, you will learn how to use the IF-THEN-ELSEIF-THEN-END IF
structure in structured text programming.
Click here to watch the video on YouTube

4.8 Using CASE instruction in ST


In this video, you will learn how to use the CASE instruction in ST.
Click here to watch the video on YouTube

4.9 Using While-Do loop instruction in ST


In this video, you will learn how to use the WHILE-DO-LOOP in ST.
Click here to watch the video on YouTube

4.10 Using Repeat-Until loop instruction in ST


In this video, you will learn how to use the Repeat-Until loop in ST.
Click here to watch the video on YouTube

4.11 Using Jump (JMP) instruction and com-


ments in ST
In this video, you will learn how to use the JMP instruction and how to provide
comments in ST.
Click here to watch the video on YouTube

14
4.12 Using Return instruction and comments in
ST
In this video, you will learn how to use the Return instruction in ST.
Click here to watch the video on YouTube

4.13 Using SHift Left (SHL) and SHift Right


(SHR) instructions in ST
In this video, you will learn how to use the SHR and SHL instructions in ST.
Click here to watch the video on YouTube

4.14 Unit Conversion in Structured Text (ST)


In this video, you will learn how to introduce, implement and use unit conversion
(both forward and backward) in Structured text (ST) programming.
Click here to watch the video on YouTube

4.15 Creating and using function blocks in ST


In this video, you will learn how to create and use Function Blocks (FB) in
CODESYS, using Structured Text (ST) programming languages. The example
here is quite simple (addition, subtraction, ...), however, it explains the way of
creating FB, declaring an instance of FB in the main program, calling it, and
accessing the outputs. FB can have input, local, and output variables, based on
your needs. You can also access the global variables within FB. Click here to
watch the video on YouTube

4.16 Creating and using Functions in Structured


Text (ST)
In this video, you will learn how to create and use Functions (F) in CODESYS,
using Structured Text (ST) programming languages. Functions are different
from Function Blocks (FB), in the sense that they usually provide one output,
there is no need to instantiate them in the project, and you just refer to their
outputs by referring to the name of the function and providing the inputs. The
example here is quite simple (multiplication, division, and addition), however, it
explains the way of creating F, calling it, and accessing the output. FB can have
input, local, and output variables, based on your needs. You can also access the
global variables within FB.
Click here to watch the video on YouTube

15
4.17 R Trig and F Trig (Rising and falling edge
detection) instructions in Structured Text
(ST)
In this episode, I will show you how to use the edge detection instructions in
the structured text (ST) in CODESYS. First I will explain the way in which
these instructions operate, and then using an example, I will explain how these
instructions could be used. I have also created a simple visualization for the
example project. After watching the video, you are asked to extend the project
and introduce additional features.
Click here to watch the video on YouTube

16
Chapter 5

Sequential Function Chart

This chapter includes all the videos related to SFC programming.

5.1 Introduction to SFC


Sequential function chart (SFC) is a graphical standard PLC programming lan-
guage. The basic idea is to have steps and corresponding actions. The switching
between the steps is controlled by the transition conditions. While entering and
exiting the step, or when the step is active, different actions could be pro-
grammed to be taken. In this video, you will learn the basics of SFC using a
simple example.
Click here to watch the video on YouTube

5.2 Different types of actions


Actions in SFC could be categorized into two main categories: 1. IEC conform-
ing actions and 2. IEC extending actions. For the first category, the actions
appear on the right side of the Step, and they have two fields: The first field is
called qualifier and it determines the way in which the action will be executed
(while the step is active, for a period of time), and the second field contains the
name of the action. The actions belonging to the second category, are the ”Step
Entry”, ”Step active”, and ”Step Exit” actions, appearing in the Lower left cor-
ner, top right, and lower right corner of the Step, respectively. In this video, you
will see the difference between a ”Step active” action and an IEC conforming
action with the qualifier ”N”, which means that ”The action is active as long
as the step is active”. However, since it is an IEC-conforming action, it will be
executed at least two times, while entering the step and one time when exiting
the step.
Click here to watch the video on YouTube

17
5.3 Implicit variables in Steps
In this video, you will learn about the Implicit variables in the SFC. You will
learn how to use two kinds of implicit variables (state and time) available for the
Steps in SFC. Everything is explained through the traffic light control system
example.
Click here to watch the video on YouTube

5.4 Editor options


In this video, you will learn how to change the appearance of the SFC program-
ming environment, in terms of the sizes of elements, the font, and some more
things. In this way, you can personalize the SFC programming environment
based on your needs and desire.
Click here to watch the video on YouTube

5.5 SFC Action Qualifiers


In this video, you will learn about the SFC action qualifiers which are used for
IEC actions and determine how an action should be executed.
Click here to watch the video on YouTube

18
Chapter 6

Continuous Function Chart

Continuous Function Chart (CFC) is a language similar to FBD but with greater
flexibility. It is not a standard PLC programming language, but quite useful
and popular.

6.1 First lesson


In this video, you will learn the very first steps in using Continuous Function
Chart (CFC) to program PLCs using CODESYS. CFC is an extension to the
IEC 61131-3 standard, which is based on the function block diagram (FBD)
language but has its own features, such as the freedom of placing the elements
in the programming environment.
Click here to watch the video on YouTube

6.2 Composer element in CFC


In this video, you will learn about the functionality of Composer, an element of
CFC programming language, and also how to use it, through a simple example.
You will review how to create Structure type variables and how to create a
function block and use it in the project as well.
Click here to watch the video on YouTube

6.3 Using Limit operator in CFC


In this video, you will learn how to use the Limit operator in CODESYS. The
programming language is chosen as CFC, however, you can use the same oper-
ator within the other programming languages as well.
Click here to watch the video on YouTube

19
6.4 Selector element in CFC programming
In this short video, you will learn how to use the Selector element in the CFC
programming environment. The selector is an element in CFC that helps to
separate the fields of a structure variable.
Click here to watch the video on YouTube

6.5 Set/Reset instructions and Execution order


in CFC programming
In this video, you will learn about using Set and Reset instructions in the CFC
programming language. You will learn how to convert a Boolean output into
a Set or Reset one and how to make it a normal one. On the other hand, you
will see how to make a self-holding circuit in CFC. Furthermore, the execution
order of instructions is also discussed here using an example. Negating an input
element is also shown in the example.
Click here to watch the video on YouTube

6.6 MUX (Multiplexer) function in CFC


In this short video tutorial, you will learn to use the MUX (Multiplexer) function
in the CFC (Continuous Function Chart) programming. MUX is a function that
has several inputs and only one output. One of the inputs (The first one) is
an integer variable that determines which of the other inputs appear on the
output. If the first input is 0, then the second input will appear on the output,
if the first input is 1, then the third input will be on the output and etc. I
have explained this using an example in which TPs (Pulse timers) are used to
generate a blinking with variable pulse width. The frequency of the blinking is
provided by the output of the MUX, which receives several inputs. In addition
to the MUX, a MUL (multiplication) and one AND function are used in the
example as well. You will also learn how to increase the number of inputs of a
function box and how to negate some of them, if necessary. I hope you enjoy
this video, and do not hesitate to like, comment, and share it to support me!
Thanks for watching.
Click here to watch the video on YouTube

6.7 Interlocking using Interlock function block


from OSCAT library in CFC
In this video, I will explain Interlocking using a simple example. The Inter-
lock function block from the OSCAT library is used in the project, which is
developed using the structured text programming language. When two Boolean
variables are interlocked, they can not become true simultaneously. Meaning

20
that one could become TRUE only if the other one is False. A typical example
would be the elevator: The door of the elevator should not be opened while the
cabin is moving, and the cabin should not move while the door is open. In the
video, I also show how to implement the same function block using the CFC
programming language.
Click here to watch the video on YouTube

6.8 HYSTERSIS function block in CFC


In this video, you will learn how to use the HYSTERESIS function in CODESYS,
within the CFC programming environment. HYSTERESIS is used to improve
the performance of the system in the On/Off control, to prevent the actuators
(like cooler, heater, etc) from turning on and off repeatedly for small fluctuations
in the control variable (like room temperature, liquid level, etc.) HYSTERESIS
is a function available from the UTIL library, which by default does not come
with the project and you have to add the library manually to your project.
Click here to watch the video on YouTube

6.9 Using LIMITALARM function block in CFC


In this video, you will learn about the functionality of the LIMITALARM func-
tion block, and how to use it in the CFC PLC programming. Using Slider and
Text box elements are also explained within the example. You will also learn
how to add a library to your project.
Click here to watch the video on YouTube

6.10 Using Blink function block in CFC


In this video, you will learn how to use the BLINK function block in the CFC
programming environment. The BLINK function is used to create the blinking
signal (turning on and off repeatedly), where you can determine the On time
and Off time using two input arguments. You can also activate/deactivate the
function using another input argument. You will learn how to add the Util
library into the project, which includes BLINK as one of the function blocks.
Click here to watch the video on YouTube

6.11 FIFO function block (from OSCAT library)


in CFC
In this video, you will learn about using FIFO (First In First Out) function
block, which is provided by the OSCAT library. There are two versions of
FIFO: FIFO 16 and FIFO 32, and the only difference is the number of data
elements that you can store in the array, or indeed the size of the underlying

21
array. I have used FIFO 16 in this example, but you can use whichever fits your
needs. The FIFO function block has several inputs and three outputs.
I have used a slider to determine the value of the input data and buttons to
read or write the data into the array. Since FIFO is not provided by CODESYS,
you need to download (from oscat.de) and install the OSCAT library and add
it to the project, as described in the video. You can also use this function block
using another programming language such as FBD or ST, just like the other
function blocks.
Click here to watch the video on YouTube

6.12 Linear Transformation (LIN TRAFO) func-


tion block
In this video, you will learn how to use the Linear Transformation function
block in the CODESYS environment. You will also learn how to add a library
to your CODESYS project if the function block is not one of those which are by
default added to the project. Also, this example uses CFC as the programming
language, you can easily use the LIN TRAFO function block within any other
programming language, such as FBD, ST, etc. you just need to know how to
provide the inputs and how to get the outputs.
Click here to watch the video on YouTube

6.13 Standard String Functions


In this video, you will learn about the standard CODESYS functions to work
with Strings. There are several functions including LEN, LEFT, RIGHT, MID,
CONCAT, INSERT, DELETE, REPLACE, and FIND. In this video, I only
explain how all these functions act on the strings, and in another video, I will
show you how to use some of these functions to have an animated text field.
Here is a brief explanation of those functions:
LEN: Provides the length of the input string as an integer value.
LEFT: Extracts a part of the input string (left side to the provided position)
RIGHT: Extracts a part of the input string (right side to the provided position)
MID: Extracts a part of the input string (given number of characters), starting
at the given position
CONCAT: Combines two strings with each other and generates another string
as its output
INSERT: Inserts a string within another one, starting from the given position
and with the determined number of characters
DELETE: Removes the given number of characters starting from the given
position
REPLACE: Replaces a part of the input string with another string
FIND: Finds the position of the first occurrence of a given string within the

22
input string.
Click here to watch the video on YouTube

6.14 GEN (Function Generator) function block


in CFC
In this video, I explain the way of using the Function Generator (GEN) function,
which is a part of the Util library. As the first step, you need to add the library to
your project. With the Gen function, you can determine the type of waveform,
the amplitude, and the frequency. In this project, a Radio Button is used to
determine the type of waveform, and a Trace element is used to display the
generated waveform. A slider is also used to determine the amplitude. I have
used CFC as the programming language, but you can use any of the other
languages.
Click here to watch the video on YouTube

23
Chapter 7

Instruction List

Instruction List (IL) is a textual standard PLC programming that is not widely
used these days, mostly due to its very basic way of writing commands. In the
following video, you will learn the basic steps of using IL as the programming
language. This is the only (and probably the last) video tutorial that I have
made for IL, and I believe there is not much demand for it! Each line (or rung)
of code in the Ladder diagram, which is called a network in CODESYS, would
be replaced by several lines of code in IL. This is an easy example of a PLC
program, and the same program in LD is already have published (refer to the
link provided in the first comment of the video).
Click here to watch the video on YouTube

24
Chapter 8

Visualization

This chapter includes mostly videos with an emphasis on visualization. After


following this chapter, you will learn how to add a visualization to the project,
how to insert and configure different visualization elements and make the link
between visu elements and the PLC tags. You will also learn how to switch
between different visualization windows.

8.1 Displaying dynamic values (in the Text field)


In the HMI panels or visualization screens, you may need to display some process
values which change over time. This could be done in a couple of ways. In this
video, you will see how to display it as a numerical value in a Text field.
Click here to watch the video on YouTube

8.2 Controlling the visibility of objects


In the HMI panels or visualization screens, you may need to make the objects
on the screen visible, or invisible, based on your design needs. In this short
video, you will learn where to find the visibility property for the objects and
how to associate it with some Boolean variable.
Click here to watch the video on YouTube

8.3 Creating a vertical Bar display


In the HMI panels or visualization screens, Bar displays could be used as the
indicators of some process variables. By default, the Bar displays in CODESYS
are horizontal and there is no property for them to make them vertical. In this
video, you will learn a very simple and intuitive way to make the bar displays
vertically.
Click here to watch the video on YouTube

25
8.4 Controlling the movement (position) of ob-
jects
In the HMI panels or visualization screens, some objects, representing items in
the process, may need to be dynamically moved in the screen, to simulate the
real location of the corresponding objects in the process, such as the objects
located on a conveyor belt. In this video, you will where to find the position
property for the objects and how to associate them with some dynamic variables.
Click here to watch the video on YouTube

8.5 Creating momentary switches (NC and NO)


In the CODESYS visualization, the available switches are not momentary. This
means that once you change the state of a switch, it will remain in that state.
On the other hand, for the Start and Stop switches, usually we need momentary
switches. In this video, you will learn how to create normally open (NO) and
normally closed (NC) momentary switches or push buttons.
Click here to watch the video on YouTube

8.6 Using ComboBox integer to manipulate the


value of an integer variable
In the HMI panels or visualization screens, some integer variables (such as set-
point) would need to be tuned through the user input. ComboBox integer is one
of the elements through which you can manipulate the value of such variables.
In this video, you learn how to associate a ComboBox integer with an integer
variable.
Click here to watch the video on YouTube

8.7 Using SpinControl to manipulate the value


of an integer variable
In the HMI panels or visualization screens, some integer variables (such as set-
point) would need to be tuned through the user input. SpinControl is one of
the elements through which you can manipulate the value of such variables. In
this video, you learn how to associate a SpinControl with an integer variable.
Click here to watch the video on YouTube

8.8 Using Trace to display variables as graphs


In the HMI panels or visualization screens, you may need to display some process
variables as graphs. Trace is one of the elements which is used for this purpose.

26
In this video, you will learn how to use the Trace element, and how to configure
it to display the variables as a graph, changing over time.
Click here to watch the video on YouTube

8.9 Working with images


In the HMI panels or visualization screens, you may need to use images in your
project, to display a special item, or as a background for the screen. In this
video, you will learn how to add images to the project and how to use them.
Click here to watch the video on YouTube

8.10 Using the Frame element


In the HMI panels, or visualization screens, you may have a lot of objects and
processes to display, and for that, you may use more than one screen. Using the
Frame element, you can switch between the screens in the project. In this video,
you will learn how to use the Frame element, through a very simple example.
To use the Frame element, you need to have more than one visualization in the
project.
Click here to watch the video on YouTube

8.11 Enabling Grid


In this video, you will learn how to enable the Grid in the visualization, how to
have an Active or passive grid, and how to change the size of the grid.
Click here to watch the video on YouTube

8.12 VisuSymbols
In this video, you will learn how to include the VisuSymbols in the visualization
of CODESYS, which would save you time later.
Click here to watch the video on YouTube

8.13 Controlling the color of objects


In this video, you will learn how to change the color of an object in the visual-
ization based on the value of a Boolean variable.
Click here to watch the video on YouTube

27
8.14 Text Display Animation
In this short video, you will learn how to use the text display animation in the
visualization of the CODESYS. The basic idea is to change the font size of the
text in the display, which could be associated with an integer variable. The
font size is one of the properties of the text, which is visible when you have the
Expert view checked. In this simple example, a Pulse timer is used to generate
the clock pulse, and the MOD operator is used to keep the value of the size
below a given value.
Click here to watch the video on YouTube

8.15 Calling a Dialog Box (and using Date Picker)


In this video, you will learn how to create a dialog box and call it in the
CODESYS visualization. A dialog box is indeed a visualization window that is
set to behave as a dialog box. To call it from the main visualization window,
you can use a button, which opens a dialog as you click on it. Within the dialog
box, we are using a Date Picker element (with some buttons) to set the start
and due dates.
Click here to watch the video on YouTube

8.16 Combo Box Array


In this video, you will learn about the Combo Box Array, which is one of the
visualization elements. You need to declare an array variable of type string and
associate it with the source data for the Combo box array. Then, while running,
when one element of that array is selected using the combo box, the correspond-
ing index will be returned. You also will learn how to declare and initiate the
array of strings. controlling the visibility of the items in the visualization is also
considered here, by performing simple calculations directly in the visualization
and determining the invisibility of the items.
Click here to watch the video on YouTube

8.17 Getting User Input (Numeric value) in Vi-


sualization
In this video, you will learn how to get the user input in the form of a numeric
value in the visualization. The operator or user will be able to click on a field and
then enter his desired value for the specified variable. There are several options
to get input from the user. S/he can provide the input using a keyboard, or a
keypad/Numpad in the form of a dialogue box. You need to determine this in
the ”inputconfiguration” field, ”OnMouseClick” option, and using the ”write a
variable”. Meaning that, when the user clicks on the element, S/he can write a

28
new value into a variable. Different options are explained in the video.
Click here to watch the video on YouTube

8.18 Saving and Loading Data Using Trace


In this video, I will show you how to save the data and load it in the CODESYS
environment using the Trace element. You can save the data in the format
of a CSV file or alternatively a Text file. To save the data, right-click on the
Trace and select Save data, then choose a location and a name for the file and
determine the type of the file from the menu. If you choose to save the data
only in the form of a CSV file, you can open the data file with Excel, extract the
data and plot it, if you wish. The CSV file will have some information about
the application, device, trace, and variable on the top part and the actual data
in the lower part. The data will consist of time stamps in milliseconds and the
data of the variable. To load the data into the Trace, right-click on the trace
and choose Load data and then select the file and the data will be displayed
on the trace. Saving the data in the text format, you will have three rows of
information on top, and then the actual data.
Click here to watch the video on YouTube

8.19 Rotate and Scale visualization elements


In this short video, you will learn how to rotate and scale the visualization
elements (a rectangle in this case). There are two types of rotation: Rotate
and Rotate Internally, and they differ in the way that the object will rotate.
In the case of normal rotation, the element will rotate with respect to a point,
by keeping the alignment of the element unchanged and rotating. In the case
of internal rotation, the alignment does not remain the same and the object
rotates around the rotation point. By the scale property, you can increase or
decrease the size of the element. If you set the scale property to 0, the element
will disappear. If you set it to 1000, the element will look the same as the
original, and setting it to 2000 will double the size of the element.
Click here to watch the video on YouTube

8.20 Adding/removing edges to/from polygon,


polyline, and Bezier curve elements
Polygon, Polyline, and Bezier curve visualization elements have a given number
of edges by default. If you need more edges for any of them, there are 2 ways
to follow: 1. After inserting the elements, hover your mouse on one edge, the
cursor will change shape, hold the CTRL-key down, and left-click by mouse.
One edge will be added for each left mouse click, as long as the CTRL key
is down. Then you can move the edges and modify the shape. 2. Select the

29
element in the visualization toolbox, and left-click in the visualization window.
For each left mouse click, one edge will be added. To stop, do a right mouse
click. In order to remove one edge from any of those elements, you need to hold
the CTRL and Shift keys down and do a left-mouse click. With each click, one
edge will be removed. In this way, you can create your desired visualization
elements easily.
Click here to watch the video on YouTube

8.21 Switching between Visualizations


In this video, you will learn how to switch between different visualizations, using
buttons to perform the switching. In the properties of the button, in the Input
configuration, On Mouse click, Change Shown Visualization, and choose the
corresponding visualization. As an alternative, you can use the CurrentVisu
variable and assign a value to this variable to control the shown visualization.
To do so, you need to add the VisuelemBase library to the project and activate
the ”use CurrentVisu variable” in the visualization manager.
Click here to watch the video on YouTube

8.22 Navigating among Visualization windows


using Combo Box Integer and Text List
In this video, you will learn how to navigate between different visualization
windows using Combo Box Integer and Text List and the CurrentVisu variable.
As the first step, you have to add the VisuElemBase library to the project and
activate the ”use CurrentVisu variable” in the visualization manager. You also
need to add a Text List to the project and use the names of the visualization
windows as its entries, with proper IDs. In each Visualization window, insert
a Combo Box Integer element and determine the created Text List as its text
list input and the variable as an integer variable declared in the main program.
Then use a Case instruction (if you use ST as the programming language) to
determine the value of the VisuElemBase.CurrentVisu variable based on the
selected value of the integer variable through the Combo Box Integer. This
way, you can easily navigate among all the visualization windows which could
be quite useful if you have many visualizations in your project.
Click here to watch the video on YouTube

30
8.23 Momentary versus Maintained switches -
Convert a maintained switch into a mo-
mentary one
In this video tutorial, you will learn to convert maintained or stationary switches
into momentary ones which behave like pushbuttons. You can do this by chang-
ing the ”element behavior” property of the switch from ”Image Toggler” to
”Image Tapper”.
Click here to watch the video on YouTube

8.24 Switching between Languages


In this video, you will learn how to switch between different languages that are
used for displaying text in the visualization such as English, German, Turkish,
Spanish, etc. To do so, you have to add each language to the Global Text List
or the manually added Text List and provide the translation of the text in the
corresponding language. Then, in the visualization, insert buttons to perform
the switching between the display language. In the properties of the button,
in the Input configuration, On Mouse click, Change Language, and choose the
corresponding language.
Click here to watch the video on YouTube

31
Chapter 9

PLC programming
examples

In this chapter, I am collecting the PLC programming examples which are


created using different standard programming languages.

9.1 Programming Retentive on-delay timer


You can get the archive of the project from this link:
Click here to download the project archive.
In this video, you will learn how to create a function block for a retentive
on-delay timer. Retentive timers keep their elapsed time and do not start from
zero once their input gets off and on. CODESYS does not have Retentive on-
delay timers and in case you need one, you should create your own. It is quite
important to pay attention to the order in which the program rungs/branches
appear. You can try to exchange their position and see that the timer will not
work as you expect.
Click here to watch the video on YouTube

9.2 Simple LD programming example - Water


level control
In this video, a simple water level control is taken into account, for which a
PLC program using Ladder logic diagram (LD) language is developed. You will
learn how to implement the program in the CODESYS environment and how
to create a simple user interface. The main components of LD programming
language are used in this example, including Normal contact, Negated contact,
output coil, Set coil, and Reset coil.
Click here to watch the video on YouTube

32
9.3 Simple LD programming example - using
On-delay timers
In this video, you will learn how to use the On-delay timers, through a very
simple example, using LD programming language. On-delay timers are the
most commonly used timers in PLC programming.
Click here to watch the video on YouTube

9.4 Ladder Logic Diagram programming exam-


ple
In this video, I am providing the solution to a problem in the quiz of my ROBT
308 - Industrial Automation course. I have explained how to develop the code,
and how the order of rungs of the code is important when you have a given
output coil in different rungs. The problem is to run a motor and a pilot lamp
based on the state of two limit switches. The programming language is a ladder
logic diagram.
Click here to watch the video on YouTube

9.5 Ladder logic diagram (LLD) programming


example
In this video, I explain a PLC program using Ladder Logic Diagram (LLD)
language. The process consists of two conveyors, controlled by two motors,
Motor1 and Motor2. The metal plates are moving on the first conveyor, and
they are collected on the second one. Once there are 15 plates stacked on the
second conveyor, the first motor stops, and the second one runs for 7 seconds,
and then the process repeats. To start the process a Start pushbutton is used
and to stop it, a Stop pushbutton. In the visualization, there is a pushbutton to
simulate the optical sensor, providing a pulse once there is a plate transferred
from the first conveyor to the second.
Click here to watch the video on YouTube

9.6 Simulating 7-segment displays


In this video, you will learn how to create 7-segment displays in the CODESYS
visualization and how to make it show the number that you want. I have
explained all the steps that you need to take, and you can do it in a similar
way. If you feel lazy to replicate it but still want to try it by running the code,
Click here to download the project archive
Click here to watch the video on YouTube

33
9.7 Structured Text (ST) programming exam-
ple - Traffic light control
In this video, you will learn how to develop a simple PLC program using Struc-
tured Text (ST) programming language. The example system is the traffic light
control in an intersection, where there are one north-south and one east-west
traffic light set. The code in LD is provided. Four on-delay timers are used to
create the sequence.
Click here to watch the video on YouTube

9.8 Structured Text (ST) programming exam-


ple - Traffic control
In this video, I explain the project developed by one of the subscribers of the
Channel, ”Siddharth dc”. This is to make the channel more interactive! The
example system is the traffic light control in an intersection, where there are one
north-south and one east-west traffic light set. There is also a push button that
could be pressed by pedestrians to stop cars in both directions. The pedestrians
have a higher priority, meaning that as far as they press the push button, the
cars will not be able to cross the intersection!
Click here to watch the video on YouTube

9.9 ST programming example - Programming


state machines
In this video, I explain a CODESYS project that Mr. Jamal Muhammad devel-
oped and asked me to publish on my YouTube channel. Thanks a lot, Jamal!
He also has provided the Dropbox link for downloading the source, which you
can find it below. Basically, the program written in structured text (ST) is
using the CASE structure to have the state machine implementation. There are
two main POUs, each one using one CASE structure, where one POU is called
inside the other one. The visualization is simple enough to reconstruct, with
two pushbuttons and two pilot lamps.
Click here to watch the video on YouTube

I think I have provided enough explanations in the video, if you need more,
you can refer to Jamal directly. Here is the updated Dropbox link:
Click here to download the project

34
9.10 SFC programming example- Traffic light
control in the intersection
In this video, you will learn how to develop a PLC program using Sequential
Function Chart (SFC) programming language. Creating the project, adding
Steps and Transitions, creating Parallel branches, Adding different types of
Actions, and determining a background image in the visualization are covered
in this video. Everything is explained through the traffic light control system
at an intersection.
Click here to watch the video on YouTube

9.11 SFC Example - Traffic lights control with


a single SFC step - Action qualifiers
In this video tutorial, you will learn to use the IEC actions of SFC in order to
control a traffic light system in an intersection using a single SFC step.
Click here to watch the video on YouTube

9.12 CFC programming example - Tank Simu-


lation
This video is a CFC programming example, in which a liquid tank is simulated
using the CODESYS Visualization elements and the CFC programming. There
are two liquid pumps (inlet and outlet), which could be turned off completely
or opened partially. There are lower and higher limits on the level of the liquid
in the tank. Two BLINK functions and one LIMITALARM function are used
in the program.
Click here to watch the video on YouTube

9.13 String Animation Example


In this video, you will see the underlying PLC code in CFC and visualization
settings that make the string visualization happen. You can change the text,
the font size, and the movement speed of the text. Several function blocks are
used to generate the code, including the standard string functions such as LEN,
LEFT, RIGHT, and CONCAT. A BLINK function is used to generate the clock
for the system, in calling the user-made function block. Within the user-made
function block, using CFC programming language, the Left most letter of the
string is taken out and put on the right of the string. Calling the function
repeatedly results in a moving text. In the visualization, a button is used to
change the string, using the OnClick property and writing a string variable.
Click here to watch the video on YouTube

35
Chapter 10

Sample Course Projects

In this chapter, you can find samples of course projects done by undergraduate
students at the department of robotics and mechatronics of Nazarbayev Univer-
sity. A brief explanation and demonstration are provided to give you an idea of
what could be done with CODESYS.
These videos are also included in the following playlist for your convenience:
Click here to watch the videos on YouTube

10.1 Sample project 01 - Candy packaging sim-


ulation
This course project was done in the Spring semester of 2015, by Tasbolat Taun-
yazov and Yuliya Nekhoroshikh. In this project, the program is developed using
Structured Text language. Visualization is also developed to provide a human-
machine interface.
Click here to watch the video on YouTube
The source code for this project is public. Click here to download the
project archive.

10.2 Sample project 02


This course project was done in the Spring semester of 2015, by Tasbolat Taun-
yazov and Yuliya Nekhoroshikh. In this project, the program is developed using
Structured Text language. Visualization is also developed to provide a human-
machine interface.
Click here to watch the video on YouTube
The source code for this project is public. Click here to download the
project archive.

36
10.3 Sample project 03 - Postal mail sorting -
open source code
The source code for this project is released now! You can get the source code
by following the link in the first comment.
In this video, I will explain to you in brief one of the course projects for the
industrial automation course, to give you a sense of what you can do with
CODESYS in the simulation mode. The project is about sorting items in a
postal station.
Click here to watch the video on YouTube

10.4 Sample project 04 - Recycling plant - Open


source code
The source code for this project is released now! You can get the source code
by following the link in the first comment.
In this video, I briefly explain one of the course projects for the industrial
automation course, done using CODESYS. The idea is to have a single-track
waste separation. The programming part is done using structured text (ST).
Click here to watch the video on YouTube

10.5 Sample project 05 - Simulation of Elevator


- open source code
The source code for this project is released now! You can get the source code
by following the link in the first comment.
In this short video, I will show and explain to you a project that two of my
former students (Farabi and Nursultan) had done in the Spring of 2015 for the
industrial automation course, at Nazarbayev University, Astana, Kazakhstan.
It is indeed the simulation of a 5-level elevator for which the structured text
(ST) is used as the programming language.
Click here to watch the video on YouTube

10.6 Sample project 06 - Car parking simulation


In this video, I am demonstrating a course project for an industrial automation
course, done by three undergraduate students at Nazarbayev University (NU).
They have simulated a car parking place where the parking cost is also calculated
for each car based on the amount of time that the car was parked. You can
replicate the project if you follow the video closely.
Click here to watch the video on YouTube

37
Chapter 11

SoftMotion

This chapter includes the video lectures created for SoftMotion.

11.1 Introduction to SoftMotion with CFC


In this short video tutorial, you will learn how to get started with SoftMotion.
The code is prepared using the CFC (continuous function chart) programming
language. Three main functions from the SM3 basic library are used, together
with their corresponding visualization elements to have a simple single-axis mo-
tion. The functions are MC Power, MC MoveRelative, and MC MoveAbsolute.
In the upcoming videos, I will provide more details about the other functions
coming with the SM3 library.
Click here to watch the video on YouTube

11.2 Analog clock simulation


You can download the archive of the project from this link:
Click here to download the project archive.
In this video tutorial, you will learn how to use a virtual drive as a rotational
one, instead of a linear one. You will also learn how to use the ”Date and time
picker” element of the visualization, and how to convert the date and time into
hours, minutes, and seconds.
Click here to watch the video on YouTube

11.3 Using MC PositionProfile function block


In this video, I will explain the usage of the MC PositionProfile function block,
provided by the SM3 library. MC.PositionProfile is a function block that is used
to pass an array of time, and position pairs to an axis to follow. Time values
are considered as delta time or the time difference between going from the last

38
position to the current one. The position can be dealt with as absolute or rel-
ative. The main input to the function block, apart from the ”Axis” input, is
the TimePosition, which is of the ”SM3 Basic.MC TP REF” type. In the visu-
alization, an element is provided to determine the inputs to the function block
through the operator. The example provided here is a simple one, just to show
how the function block could be used and accessed through the visualization.
Click here to watch the video on YouTube

11.4 Robotics - An introductory tutorial: Sim-


ulating SCARA-2 robot
In this video tutorial, you will learn the first steps in simulating a robotic plat-
form in the CODESYS environment. A simple 2 DOF robot (SCARA-2) is
simulated, by introducing two axes, powering them up, creating an axis group,
and enabling the group. A visualization is also created to provide the input
values and observe the behavior of the robot.
Click here to watch the video on YouTube

39
Chapter 12

Debugging and
Troubleshooting

This chapter includes videos created for debugging, monitoring, and troubleshoot-
ing.

12.1 Watch Lists


In this video, you will learn how to use the Watch List in order to monitor and
value force several variables. To do so, you have to add a Watch List to the
project from the View menu. In the Watch List, you need to add the variables
one by one. You can have up to 4 watch lists and a special one including the
forced variables.
Click here to watch the video on YouTube

12.2 Alarm Management tutorial


In this video tutorial, I explain how to do simple alarm management, by creating
two simple alarms of different classes and configuring the required elements.
Alam configuration should be added to the application in the project, and then
an Alarm Group should be added in order to introduce the alarm conditions. I
should also mention that I have not covered all the details here, only the basic
configurations. I hope you find the tutorial useful.
Click here to watch the video on YouTube

40
12.3 Debugging the code in the structured text
(ST) in ST
In this video, you will learn the basics of debugging in the Structured Text
programming environment in CODESYS.
Click here to watch the video on YouTube

12.4 PLC Cycle time using Cycle time function


block from OSCAT library
In this short video, I will show you how to get the cycle time of the PLC
using a function block called Cycle Time, provided by the OSCAT library. the
cycle time may vary based on the PLC that you are using, the complexity of
the program, the number of inputs and outputs, and a few other facts. The
function block has1 input (rst or reset) and several outputs.
You may need to know the PLC cycle time in various situations, such as using an
integrator. The cycles output could also be used in a specific scenario, when, for
example, you want to call a function block every 200 cycles. You can have a look
at the contents of the function block by double-clicking on it. The underlying
language is structured text.
Click here to watch the video on YouTube

12.5 CODESYS V3.5.7.0, visualization bug


In this video, a bug (most likely) of XSOFT-CODESYS V3.5.7.0 is shown when
you want to include visualization in the project. Having a visualization object,
and trying to log in, you will face the error, in which the ”Program loaded -
Exception” error message will appear, preventing you from executing the code.
Click here to watch the video on YouTube

12.6 CODESYS V3.5.7.0, visualization bug - RES-


OLUTION
Here, I explain a way to resolve the visualization problem with the latest version
of the XSOF-CODESYS V3.5.7.0. I should emphasize that there might be other
solutions, however, this one works, at least for simulation purposes. Please let
me know if you have any other solution to the problem.
Click here to watch the video on YouTube

41
12.7 Visualization Issue - Resolution 02
Here is a solution to the visualization issue of the latest version of CODESYS
(3.5.7), thanks to my student Roman Kruchinin, who found it on CODESYS
forum. You do not need to have the older versions installed and switch back
to those versions.
Click here to watch the video on YouTube

42
Chapter 13

Miscllanous

This chapter contains videos that can’t directly be categorized in the previous
chapters.

13.1 Text List - Dynamic Text


In this short video, you will learn how to use the text list in order to change
the text displayed on an object dynamically. To do so, you have to add a Text
List to the project and in the Dynamic Text properties of the visualization, the
object, choose that Text List as the input. In the Text List, you need to provide
ID and text. The ID should be updated by clicking on the visualization object.
Click here to watch the video on YouTube

13.2 An introduction to Recipes - Part 01 - Recipe


management through Visualization
In this video tutorial, you will learn Recipes, how to add them to a project and
how to manage them through visualization.
Click here to watch the video on YouTube

43
Chapter 14

Additional Resources

In this chapter, you can find a list of additional resources for learning CODESYS.

14.1 CODESYS online help and CODESYS Fo-


rum
Codesys help, available online, might be the first place where you would look
for help.
CODESYS forum is anopther great place where you can actually ask for help
and opinion of the other users, or check out to see if someone already has faced
the similar problem.

14.2 Facebook Groups


CODESYS and PLC programming using CODESYS are the two main FaceBook
groups where you can share your experience and ask for help.

14.3 CODESYS group YouTube Channel


CODESYS group, the developer of CODESYS software publishes great videos,
once in a while, in their YouTube channel channel, including informative
videos on recent updates and also educational ones.

14.4 Jakob Sagatowski YouTube channel


Jakob is maintaining a YouTube channel and a blog on programming and
working with Twincat PLCs. The programming environment is based on CODESYS,
therefore, by following his videos you will learn CODESYS. He has published

44
a complete course containing 18 parts on his channel. I strongly recommend
watching his videos.

14.5 Gary Pratt YouTube channel


Gary Pratt, the author of Book of CODESYS, has some great videos on his
YouTube channel, mostly focused on object-oriented industrial programming.

14.6 Brian Hobby YouTube channel


Brian Hobby has published five videos on his YouTube channel around 8 years
ago explaining the basics of the five standard programming languages.

14.7 SquishyBrained YouTube channel


This YouTube channel has many videos explaining several topics which has
receiived a lot interest from audience.

14.8 Carlos Abner YouTube channel


Carlos is sharing videos in his YouTube channel on a regular basis. He is speak-
ing mostly in Spanish but still you can follow his videos to understand some
topics well.

45

You might also like