PLC Programming

CODESYS Ladder Logic Tutorial: Lesson 1 - Your First Ladder Logic Program

MSc. Matthew Kurantowicz 5 min read Updated

In this first lesson of our Codesys mini-course, we’ll write a very simple program that turns on a motor. Even if you don’t have real hardware yet, you’ll be able to follow along using the built-in Codesys simulator.

What Is CODESYS and Why Start with Ladder Logic?

CODESYS is a free IEC 61131-3 development system for PLC programming. One programming environment covers all five IEC languages - Ladder Diagram (LD), Function Block Diagram (FBD), Structured Text (ST), Sequential Function Chart (SFC) and Instruction List - and it is used by many PLC platforms: WAGO, Schneider Electric, Eaton, Finder Opta, Raspberry Pi and others. Beckhoff TwinCAT is also built on CODESYS technology, so the editor and the concepts you learn here will feel familiar there too.

This CODESYS ladder logic tutorial is written for a beginner. You do not need any equipment: the CODESYS Control Win soft PLC runs on your Windows PC, and the simulation mode lets you test the program without a controller. Ladder logic is the best place to start because each rung reads like an electrical circuit - contacts on the left, a coil on the right. You can watch the whole lesson in the video above and follow the steps below.

Step 1. Install and Launch Codesys

Download and install Codesys (this tutorial uses Codesys V3.5 SP19 Patch 4).
Open the Codesys Installer, which helps you manage different versions.
Click Start to launch the environment.

Step 2. Create a New Project

  1. In the project management screen, click New Project.
  2. Choose Standard Project.
  3. Select a folder (e.g. Documents) and name it CodeSys_Motor_V01.
  4. Select the device: Codesys Control Win V3 x64.
  5. Choose the programming language: Ladder Diagram (LD).
  6. Click OK - Codesys creates the project structure.

Step 3. Build the Ladder Logic

Open the default program: PLC_PRG.
From the Toolbox → Ladder Elements, drag:

  • Normally Open Contact → represents the start button.
  • Coil → represents the motor output.

Step 4. Declare Variables

In the declaration section between VAR and END_VAR, add:

VAR
    xStartBtn   : BOOL;   // Start button
    xMotorOnOff : BOOL;   // Motor control output
END_VAR

👉 Rules:

  • Use prefixes (x = BOOL).
  • Use camelCase names (xStartBtn, xMotorOnOff).

Now, connect variables to the Ladder instructions:

  • Contact → xStartBtn
  • Coil → xMotorOnOff

Step 5. Test in Simulation

  1. Go to Online → Simulation.
  2. Choose Login and confirm.
  3. Click Start - your PLC is running.
  4. To test, double-click the contact. The variable xStartBtn changes to TRUE, which sets xMotorOnOff to TRUE → motor ON.

Shortcut: Ctrl + F7 writes values directly.

Step 6. Run It on Real Hardware (Optional)

In this tutorial, Matt uploads the program to a Finder Opta PLC with extension modules connected to an inverter and motor.
But you can use WAGO PLCs, Raspberry Pi, or any other device supported by Codesys.

When the Start button is pressed:

  • xStartBtn = TRUE
  • PLC output goes high
  • Inverter receives the signal
  • Motor starts spinning 🚀

How the Ladder Rung Works

The program you just created has a single rung. The PLC scans it in a loop: it reads the state of xStartBtn, evaluates the rung from left to right and writes the result to xMotorOnOff. A normally open contact passes power when its variable is TRUE, so the coil is energized only while the start button is pressed. When you release the button, the motor stops - that is why the next lesson adds a Stop button and a latch (seal-in) branch.

Useful ladder elements you will find in the CODESYS ToolBox as you continue:

  • Contact and Negated contact - normally open and normally closed contacts that check a BOOL variable.
  • Coil, Set coil and Reset coil - write the result of the rung to an output or keep it latched.
  • Box - inserts a function block from the standard library, for example TON timers, CTU counters or R_TRIG edge detection.
  • Parallel contact - creates an OR branch, used for the seal-in circuit.

Common Beginner Mistakes in CODESYS

  • The device is not running. After Login, the application is in STOP until you click Start (F5).
  • Variables are not assigned. A contact or coil shown with ??? has no variable - click it and select the variable from the declaration.
  • Simulation is still enabled. Before you connect to a real controller, uncheck Online - Simulation, otherwise CODESYS keeps working with the simulator.
  • Gateway or device version mismatch. For real hardware, the device description in the project must match the runtime installed on the controller.

What to Learn Next

This getting started guide is the first lesson of our CODESYS series. Continue with Lesson 2: NO and NC contacts and coils, where you build the start/stop latch circuit. If you want a complete, structured path that also covers Structured Text, timers, counters and visualization, join the Basic PLC Structured Text Programming in CODESYS course. More free video lessons are available in the CODESYS tutorial playlist on our YouTube channel.

CODESYS Ladder Logic Tutorial - FAQ

Is CODESYS free?

Yes. The CODESYS development system can be downloaded free of charge from the CODESYS Store, including the simulation mode and the Control Win soft PLC for learning. Licenses are needed for runtime systems on some target devices and for selected add-ons.

What PLC can be programmed with CODESYS?

Any controller whose manufacturer uses the CODESYS runtime, for example devices from WAGO, Schneider Electric, Eaton, Finder (Opta), Bosch Rexroth and many others, as well as Raspberry Pi with the CODESYS Control for Raspberry Pi runtime. Each manufacturer provides a device description that you add to the project.

How long does it take to learn ladder logic?

The basics - contacts, coils, latching, timers and counters - can be learned in a few weeks of regular practice in the simulator. Writing complete machine programs takes longer and comes with practice on real projects.

Conclusion

Congratulations! 🎉 You’ve just written and tested your first Ladder program in Codesys.

  • You know how to declare variables.
  • You know how to simulate logic without hardware.
  • You know how to upload to a real PLC.

👉 In the next lesson, we’ll expand this project to add a Stop button and motor latch circuit.

Online courses

Want to program PLCs in practice?

Siemens, CODESYS, communication and safety courses with a certificate and instructor support. Start with a free mini-course.

See courses
Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare