Skip to main content

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.

Author

Matt Kurantowicz, MSc

Author Matt Kurantowicz, MSc

Automation Engineer and PLC Programmer CEO & Co-Founder at ControlByte "I am helping beginners enter the world of industrial automation, PLCs, and industrial AI."

More posts by Matt Kurantowicz, MSc