PLC Programming Using CODESYS YouTube Channel
PLC Programming Using CODESYS YouTube Channel
Tohid Alizadeh
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
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
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
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
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
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
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
8
Chapter 2
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
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
11
Chapter 3
12
Chapter 4
Structured Text
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
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
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
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
18
Chapter 6
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.
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
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
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
22
input string.
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
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
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.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
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
28
new value into a variable. Different options are explained in the video.
Click here to watch the video on YouTube
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
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
31
Chapter 9
PLC programming
examples
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
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
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
35
Chapter 10
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
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
37
Chapter 11
SoftMotion
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
39
Chapter 12
Debugging and
Troubleshooting
This chapter includes videos created for debugging, monitoring, and troubleshoot-
ing.
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
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.
43
Chapter 14
Additional Resources
In this chapter, you can find a list of additional resources for learning CODESYS.
44
a complete course containing 18 parts on his channel. I strongly recommend
watching his videos.
45