Towards Industry 4.0 — #2 PLC Programming, “Hello World”

Andi Sama
7 min readOct 24, 2022

--

The Digital Transformation Journey to Industry 4.0 starts by understanding Industry 3.0

Andi Sama CIO, Sinergi Wahana Gemilang with Cahyati S. Sangaji

In Summary- Implementation of "Hello World" using one of PLC's most popular programming languages: Ladder Logic Diagram. Software tools: an Open Source PLC Editor.
- This article's supporting files (open plc source files) are available on Github.
- The implementation of "Extended Hello World" program (with an actual PLC: Siemens) is also available on Github.

Following the discussion on IT/OT convergence towards Industry 4.0 in the previous article “Towards Industry 4.0 — #1 IT/OT Convergence, A Digital Transformation Journey(Andi Sama, Cahyati S. Sangaji), let’s discuss how to build a “Hello World” program in Programmable Logic Controller (PLC).

Programming the PLC using a Ladder Logic Diagram (LAD)

Download Open PLC Editor for Windows here.

We use Open PLC Editor software on Microsoft Windows (Open Source PLC Software, 2022). Open PLC is an open-source PLC application that complies with IEC 61131–3, in which we can design using Ladder Logic, Structured Text, Instruction List, Function Block Diagram, or Sequential Function Chart.

Major OT automation providers such as Rockwell Automation (Allen-Bradley), Siemens, and Mitsubishi have proprietary software for programming the PLC. RSLogix/Studio 5000 for Rockwell, Simatic/TIA Portal for Siemens, Melsoft/iQ Works for Mitsubishi, and CX-One for Omron. Likewise, the software for SCADA (Supervisory Control and Data Acquisition) is also available. Rockwell, Siemens, and Mitsubishi software names for SCADA are FactoryTalk View, WinCC, and MC WORX, respectively.

Hello World in PLC

The most straightforward typical functional program in the ladder logic diagram consists of a left power rail, a digital START push button (input), a digital STOP push button (input), a digital coil (output), and finally, the right power rail. In this case, a coil could be as simple as a lamp or a soft motor starter driving a 3-phase AC motor, for example.

Creating the Program

We implement the “Hello World” program for the PLC using the most popular programming language, the ladder logic diagram.

The ladder Logic Diagram follows the technological advancements by transforming the physical-mechanical relay, physical timer, and physical counter to digital solid-state relay logic, digital timer, and digital counter. When things break, LAD is also the easiest to debug during troubleshooting.

While the example above shows two digital inputs and one digital output (with discrete values of 0 or 1), both input and output can also be analog (with continuous values ranging from 0–10V for voltage or 4–20mA for electrical current, for example).

Before running our program, it needs to be compiled first with no errors, of course.

Start build in D:\Andisama\Code\PLC\Open PLC\Article\Hello World\build
Generating SoftPLC IEC-61131 ST/IL/SFC code...
Collecting data types
Collecting POUs
Generate POU Hello_World
Generate Config(s)
Compiling IEC Program into C code...
Extracting Located Variables...
C code generated successfully.
PLC :
[CC] plc_main.c -> plc_main.o
[CC] plc_debugger.c -> plc_debugger.o
py_ext :
[CC] py_ext.c -> py_ext.o
PLC :
[CC] Config0.c -> Config0.o
[CC] Res0.c -> Res0.o
Linking :
[CC] plc_main.o plc_debugger.o py_ext.o Config0.o Res0.o -> Hello World.dll
Successfully built.
Starting local runtime...
Beremiz_service: 2.01
Release: 2022-08-17
WAMP import failed :
HTTP interface port : 8009
Pyro port : 61166
Current working directory :c:\users\thinkpad\appdata\local\temp\tmpxwzbym
PYRO connecting to URI : PYROLOC://127.0.0.1:61166
PLC did not provide identity and security infomation.
Latest build does not match with connected target.
PLC data transfered successfully.
UI thread started successfully.
PLCobject : No files to purge
PLCobject : NewPLC (7a6f4e0efd7a3011464af288c9371981)
PLC installed successfully.
PLCobject : PLC started
PLCobject : Python extensions started
Starting PLC
DEBUG at 2022-08-24 05:05:47.198000000:
Python extensions started
DEBUG at 2022-08-24 05:05:47.198000000:
PLC started

When we started, the “Hello World” directory was empty. Once the program is created, it creates a few files and directories.

A few initial files and directories are within the “Hello World” directory.
Multiple files & one directory inside the “./Hello World/build/” directory for our “Hello World” program.

The content of the generated “generated_plc.st” source file. The file is the base structured text file to be compiled into the machine codes for the runtime environment.

PROGRAM Hello_World
VAR
Start_PB AT %I0.0 : BOOL := FALSE;
Stop_PB AT %I0.1 : BOOL := FALSE;
Motor_Starter AT %Q0.0 : BOOL := FALSE;
END_VAR
Motor_Starter := NOT(Stop_PB) AND (Motor_Starter OR Start_PB);
END_PROGRAM
CONFIGURATION Config0RESOURCE Res0 ON PLC
TASK task0(INTERVAL := T#20ms,PRIORITY := 0);
PROGRAM instance0 WITH task0 : Hello_World;
END_RESOURCE
END_CONFIGURATION
Files & directory inside the “./Hello World/project_files/” directory for our “Hello World” program. Empty at this moment.

Once compiled, we can run the compiled program in simulated mode within the Open PLC Editor, meaning it is not running on the actual PLC hardware. We can deploy the compiled program to real hardware, though.

Running the Program

When the power is applied, the rungs are energized.

Power rails (the thick black line on the left, with +24VDC voltage) energize the rungs. The thick black line on the right is the ground. A rung is a line in which we design our logic graphically in the ladder logic diagram. As the simulated program runs, the energized rungs (lines) turn from BLACK to GREEN.

Our program starts when the START push button (Start_PB) is ON (changed from 0 to 1). Start_PB is NO type, Normally Open — meaning it is disconnected when it is not pressed. When the button is pressed, the connection is connected.

The motor starter is energized when the Start_PB push button is pressed (ON).

When the START push button (Start_PB) is connected, the Motor_Starter is energized, and the motor will be ON (running).

The Motor_Starter will keep running (ON) even when the Start_PB is released (OFF). This is due to the parallel connection of Motor_Starter that is provided as the “lock mechanism” to the Start_PB.

The motor starter is still energized when the Start_PB push button is released (OFF).

When the STOP push button (Stop_PB) is pressed, the connection from power to the soft motor starter is disconnected. The de-energized rungs turn from GREEN to BLACK. The motor is OFF. Stop_PB button is NC type, Normally Closed— it means it is connected when it is not pressed.

When the Stop_PB is ON, the motor starter is de-energized.

Implementation with different Software — Siemens

To give a different perspective, we are now implementing the “Hello World“ program using another software from Siemens, TIA Portal (Totally Integrated Automation Portal). Still using the same programming language: ladder logic diagram.

Initially, when there is no power to the rungs.
When the power is applied, the rungs are energized.
The motor starter is energized when the Start_PB push button is pressed (ON).
The motor starter is still energized when the Start_PB push button is released (OFF).
When the Stop_PB is ON, the motor starter is de-energized.

Note that this program is still running in a simulation. However, when the actual PLC is available (e.g., this program is configured with a compact Siemens PLC called “CPU 1214C DC/DC/Rly” 6ES7 214–1HG40–0XB0), the compiled program can be downloaded to PLC and runs inside the actual PLC hardware.

For additional information, this configured PLC has the following configuration:

- work memory 100 KB.
- 24VDC power supply with DI14 x 24VDC SINK/SOURCE, DQ10 x relay and AI2 on board.
- 6 high-speed counters and 4 pulse outputs on-board.
- signal board expands on-board I/O.
- up to 3 communication modules for serial communication; up to 8 signal modules for I/O expansion.
- PROFINET IO controller, I-device, transport protocol TCP/IP, secure Open User Communication, S7 communication, Web server, OPC UA: Server DA.

Looking Forward

To better understand operational technologies, interested readers may refer to the following articles on enabling the digital transformation journey towards Industry 4.0 by understanding Industry 3.0. To publish in the next couple of weeks.

  • Implement a ladder logic diagram, the most popular graphical-based PLC programming language, to control the mixer “Towards Industry 4.0 — #3 PLC Programming, A Mixer Use Case with Ladder Logic Diagram”. The implementation also runs in simulated mode within open-source Open PLC Editor software.
  • Implement another graphical-based PLC programming language, Sequential Function Chart, in a use case for simulating a one-way traffic light controller with pedestrian override “Towards Industry 4.0 — #4 PLC Programming, A Traffic Light Controller Use Case with SFC + SCADA”. Running in simulated mode within an open-source Open PLC Runtime software and accessed remotely by SCADA for visualization with open-source ScadaBR software.

--

--