Welcome back to the free PLC programming minicourse in Codesys! π
In the previous lesson, you installed the Codesys environment and created your first project. Now itβs time for the next step: youβll learn how to use NO (normally open) and NC (normally closed) contacts, as well as coils β the basic building blocks of programming in the Ladder language.
Additionally, youβll compare Ladder logic with Structured Text (ST) and complete your first practical task: creating a self-holding circuit.
Ladder vs Structured Text β Practical Differences
In Codesys, you can program in multiple languages, but in the industrial world, the two most commonly used are:
- Ladder (LD) β a graphical language that resembles electrical schematics
- Structured Text (ST) β a textual language similar to high-level languages like Pascal or C
Example β Simple START β MOTOR Circuit
In Ladder, you start from the left: the Start button (NO contact) controls the motor coil.
In ST, the logic looks like this:
xMotorOnOff := xStartBtn;
π In Ladder, you draw logic using contacts and coils, while in ST, you write it in a single line of code.
To better understand the difference, you can open both programs side by side in Codesys (Window β New Vertical Tab Group) and observe how one Ladder diagram corresponds to a few lines of ST code.
You can either download the base project or use a ready-made template.

Task: Latching Circuit
Time for your first serious exercise πͺ
Goal: After pressing the Start button, the motor should keep running even after the button is released.
In Ladder:
- Right-click on the Start contact.
- Select Insert Contact Parallel Below.
- Assign the variable xMotorOnOff to the parallel contact.
Effect: The motor can now be activated either by pressing Start or through the βself-holdingβ of the coil.
In ST:
xMotorOnOff := xStartBtn OR xMotorOnOff;π Here, the OR operator allows the motor to remain on even after the Start button is released.
Testing the program in the simulator:
- Double-click xStartBtn, set its value to TRUE, and choose Debug β Write Values (CTRL+F7).
- The motor will start and stay in the TRUE state, even when the button goes back to FALSE.
π Congratulations β youβve built your first self-holding circuit!
You can download the current self-holding project template here.
Adding a STOP Button (NC Contact)
The self-holding circuit works, but you also need a way to stop it. For that, youβll use a STOP button with an NC (normally closed) contact.
In Ladder:
- Add a new variable xStopBtn : BOOL;
- Insert a Negated Contact in the rung.
- Assign the variable xStopBtn to it.
How it works:
- When the STOP button is not pressed β the NC contact passes the signal (TRUE).
- When STOP is pressed β the contact opens, breaking the circuit and stopping the motor.
In ST:
xMotorOnOff := (xStartBtn OR xMotorOnOff) AND NOT xStopBtn;This way, the motor runs after Start is pressed, but it can always be stopped with the STOP button.
You can download the ready project here.
Lesson Summary
In this lesson, you learned:
β The difference between Ladder and Structured Text
β How a self-holding circuit works
β How to use an NC contact to stop the motor
β How to express the same logic in both Ladder and ST
These are fundamental concepts that appear in every industrial machine β from simple circuits to complex production lines.




