Getting_started_guide_CODESYS_3S.md

August 12, 2026 · View on GitHub

Getting started guide (CODESYS 3S runtime)

Getting to know CODESYS 3

If you have experience with programming in CODESYS 3 you can skip this part. Otherwise, it's advised to gain some experience by checking the sources below:

Setup CODESYS 3S

  1. Download CODESYS 3 from the CODESYS store. Note that you need to create an account to be able to download the installer.
  2. Install your device target package. Steps explained in this YouTube video, steps might differ slightly depending on your device target.

Both the WAGO-PFC100 and WAGO-PFC200 target packages can be downloaded for free. Using the free version, the PLC is able to run the CODESYS runtime for 2 hours, after which the program stops running. A license is required to remove this limitation.

Creating a project

  1. Create a new project in CODESYS 3S.

Restoring the project POUs

This will restore the basic POUs (building blocks) of the project, note that you can reuse this step to update or import new POUs in the future.

  1. Go to the POUs section of the project and select the top level item:
Restore POUs navigation
  1. Select ProjectImport PLCopenXML... and open src/Exports/PLCopen.xml:
Restore POUs top level
  1. Import all items:
Restore POUs import all

Adding a device

This will add a device to the project, in this example a PFC200 is used. Adapt to your needs if necessary.

  1. Return to the 'Devices' tab of the project, right click on the root item and 'Add Device':
Add device
  1. Add your device, in this example a WAGO PFC200 is used:
Add device PFC200
  1. Remove the default application from the device:
Add device remove default application

Restoring the PLC logic

  1. Select the PlcLogic item and go to ProjectImport PLCopenXML..., then open src/Exports/PLCopen.xml:
Restore PLC logic
  1. Import all items.

Libraries

  1. Go to the Library Manager menu and remove all WAGO libraries:
drawing
  1. Go to the Library Manager menu, press Download missing libraries and install all missing libraries:
drawing
  1. Go to the Library Manager menu and install all libraries from the src/Libraries folder.
drawing
  1. In case the IoDrvPfc200 library gives issues, remove it and reinstall it from the Library Repository:

    • Remove the existing Library

      drawing
    • Select Add library and then Advanced...

      drawing
    • Search for the IoDrvPfc200 and add it (step might vary depending on your Device target)

      drawing
  2. In case some library references are not resolved because they point to an older/newer version that is not installed on the system, update the placeholder:

drawing
  1. If there is still a Download missing libraries button in the Library Manager, press it. This should fix the last missing libraries.

Although all libraries are restored now, it's still not possible to build the project. Reason for this is that the IO configured in the project doesn't exist yet in the device in the project tree.

Updating the configured devices to your PLC device configuration

As the IO modules installed on your PLC will most likely differ from the ones configured in the project an update is required.

  1. Turn on your PLC with a network cable plugged in. Make sure that the device you are using to follow these steps is on the same network.

  2. From the Device section in the project select Scan network.. and Select your PLC:

    Scan network and connect to PLC
  3. From the module configuration section in the project, perform Scan for Devices..

    Scan to update modules
  4. Set the Show Differences to Project checkbox.

    Scan to update modules show differences
  5. Using the tools in the middle of the screen, update the project Configured Devices to the Scanned Devices.

    Scan to update modules perform update

Executing the steps above will most likely introduce build errors. This is normal! The current program uses every input and output of the configured device modules, so adjusting or removing them naturally causes build issues. These build issues will be fixed in the next topic where the program logic is adjusted to your PLC configuration.

Make sure to update the PLC device configuration to your exact PLC device setup in order to avoid issues.

Adjusting the home automation logic to your needs

MQTT config

Update the configured MQTT broker IP and port to connect to your broker: Update MQTT config

Naming modules

Select your input and output modules and create a variable for each input and output. Advised approach: DO_{Digital Output number} and DI_{Digital Input number}:

Update MQTT config

Pushbutton Input Logic

For each input linked to a pushbutton a function block needs to be created: Input pushbutton logic

To get started:

  1. Remove all existing FB_DI_PB_XXX function blocks except the first one.
  2. In the MAIN_INIT action remove all references to FB_DI_PB_XXX function blocks except the first one.
  3. In the READ_PUSHBUTTONS action remove all references to FB_DI_PB_XXX function blocks except the first one.
  4. In the READ_PUSHBUTTONS action update FB_DI_PB_001 to read the physical input variable created in the previous step "Naming modules".

For more information on the FB_INPUT_PUSHBUTTON_MQTT function block, check the dedicated docs.

Output Switch Logic

For each output linked to a switch or relay a function block needs to be created: Output switch logic

To get started:

  1. Remove all existing FB_DO_SW_XXX function blocks except the first one.
  2. In the MAIN_INIT action remove all references to FB_DO_SW_XXX function blocks except the first one.
  3. In the WRITE_SWITCHES action remove all references to FB_DO_SW_XXX function blocks except the first one.
  4. In the WRITE_SWITCHES action update FB_DO_SW_001 to write the physical output variable created in the previous step "Naming modules".
  5. Link the input pushbutton from the previous step to switch the FB_DO_SW_001 output to toggle the output when the pushbutton receives a single press: TOGGLE :=FB_DI_PB_001.SINGLE

For more information on the FB_OUTPUT_BINARY_MQTT function block, check the dedicated docs.

Persistent Variables

In order to be able to maintain the state of the outputs through power cycles Persistent Variables are used. To update the Persistent Variables if you created or removed Function Blocks perform the following steps:

  1. Go the Persistent Variables and remove everything:

    Output switch logic
  2. Go to Declarations and select Add all instance paths

    Output switch logic

This will add all PERSIST variables from the project. Note that the project needs to be built before being able to perform this step.

Building the project

Once all IO references in the project actually exist on the device as well you should be able to build the project:

  1. Build the project (F11)!
drawing

Uploading and running the project

To upload and run the project on your PLC perform the following steps:

  1. From the menu, select online and then login:

    select online and then login
  2. Select Login with download and press OK:

    login with download
  3. Start the application on your PLC:

    start the application

Note that you might need to rescan your network from the Device Communications tab to execute these steps successfully. In addition make sure that the physical switch on your PLC is in 'RUN' mode (if applicable).