Factory IO Examples

Factory IO · PLC · Ladder · Codesys · TIA Portal

This page contains a collection of solved examples for the Factory IO software, which is a 3D simulation platform for industrial automation. The examples cover various scenarios and challenges, and provides solutions using different PLC programming environments such as Codesys and TIA Portal and different communication protocols like Modbus, Profinet or OPC-UA.

All factory IO files and project resources are available in the repository: https://github.com/elcesarlokuelo/elcesarlokuelo.github.io/tree/main/assets/Downloads/Solved_factoryIO_examples

Each example will include a description of the problem, the implemented solution in the chosen PLC code language, and the corresponding software and communication protocol used. For all the examples there will be a video demonstration of the solution in action within the Factory IO simulation environment, and a link for downloading the project files.

Assembler

The objective in this scene is to assemble parts made of lids and bases using a two-axis pick and place. For this example I used CODESYS and Modbus TCP to communicate with Factory IO. The PLC program is written in Ladder logic, using a finite state machine to control the pick and place operation.

First we define the necessary I/O as global variables, looking at the Factory IO driver configuration. We also have to link the variables to the corresponding Modbus addresses in the PLC configuration, in the holding registers, coils or discrete inputs.

The control logic is implemented as a state machine using Set/Reset coils, where each state (E0 to E13) represents a step in the assembly sequence. Pressing Start initiates two parallel branches: one state machine for the lids conveyor and another for the bases conveyor, since both parts are handled independently until they reach the clamping station. Each state is activated by a condition (a sensor detecting a part, a clamp closing, an axis finishing its move) and immediately resets the previous state, ensuring only one state is active at a time per branch. Timers are used where there is no direct sensor feedback, such as during the Z-axis movement or the pick and place cycle. The sequence finishes by counting the finished pieces with a falling-edge triggered counter and returning the system to its initial states, ready for a new cycle.

Assembler (Analog)

This example is very similar to the previous one, but in this case we use analog inputs and outputs to control the pick and place axes and positions. I used Codesys and Modbus TCP to communicate with Factory IO. The PLC program is written in Ladder logic, using a finite state machine to control the pick and place operation.

For this example i used the CADe_SIMU software to create a grafcet diagram of the process, making it easier to then translate it into the PLC ladder program.

We also have to define the necessary I/O as global variables, looking at the Factory IO driver. Then we have to link the variables to the corresponding Modbus addresses in the PLC configuration, in the holding registers, coils or discrete inputs.

I use 2 different functions to implement the toggle button logic for the stop push button and the counter for the total finished pieces.

The program implements a finite state machine with three parallel branches: one tracks the lid sensor on conveyor 1, another tracks the base sensor on conveyor 2, and the third controls the robotic arm's movement (X/Z positioning, grabbing and releasing parts using position comparisons). State E0 acts as the master reset, restarting all three branches when Start is pressed. At the end of the program, the states are mapped to the physical outputs: conveyors, stop blades, and other station actuators.

Automated Warehouse

In this example you have to transport, store and retrieve boxes from a rack. For that you use the loading and exit conveyors, and the stacker crane. For the PLC programming I used CODESYS with its simulated PLC software CODESYS Control Win V3. This software-simulated PLC acts as an OPC-UA server that communicates with Factory IO and an Ignition Gateway as clients.

First I defined the global variables and a symbol configuration object to define the I/Os and expose them via OPC-UA. Then I created two FBs to control the entry and exit conveyors, using simple logic.

I also used an FC to control the button lights. The main program defines the general behavior of the program, featuring a running state that self-latches when the Start button is pressed and can be interrupted with the Stop NC button.

The cycle program is implemented as a state machine, with each state representing a step in the process of storing or retrieving a box. In some cases, timers are necessary because the PLC's scan cycle is much faster than the physical response time of the actuators. For example, right after a motion command is issued, the state machine may evaluate the transition condition before the movement sensor has had time to activate — misinterpreting the sensor's inactive state as the motion having already finished, when in fact it hasn't started yet. A timer ensures enough time has passed for the movement to genuinely begin (or complete) before the state machine reacts to the sensor.

Finally, I created an HMI in Ignition to visualize the status of the rack, which positions are occupied, which are free, and the state of the process. This gateway connects to the simulated PLC via OPC-UA.

Buffer Station

The objective of this example is to buffer and separate up to five boxes, using a series of conveyors and sensors. For this example I used CODESYS and OPC-UA, using the simulated PLC as an OPC-UA server to communicate with Factory IO acting as a client. The PLC program is written in Ladder logic. Additionally I created a simple HMI to visualize the status of the system and control the operation when the manual mode is selected.

Firstly we create the global variables and a symbol configuration object to define the I/Os and expose them via OPC-UA. In this case we have 8 digital inputs and a REAL input for the potentiometer used for the conveyors velocity. We also define 7 outputs for the analog conveyors, displays, button lights and the stop blade.

I used the PLC_PRG POU to organize the program modes, and the general logic of the emergency, start, reset and stop buttons. In the HMI I created there are the same controls as in the panel in Factory IO, and also the manual controls of the outputs. The idea is that the operator can control the process manually from the HMI, or let the PLC control the process automatically using the "physical" control panel. The mode can only be changed via the rotary switch on the physical panel, avoiding control source conflicts between the HMI and the simulation.

The manual mode consist only in the direct control of the outputs and the conveyor velocity. Also i can duplicate the start, stop and reset buttons in the HMI because they are momentary, and cant conflict with the physical buttons in the panel.

The automatic mode does batches of three boxes. The operator can start, reset or stop the process in the physical panel or the HMI, but can't adjust the conveyor velocity or control the outputs directly from the HMI.

Elevator (Basic)

In this example you have to transport items through three different levels using two elevators. For the simulation I programmed a PLCSIM V20 virtual PLC using TIA Portal. First I defined the Inputs and Outputs as global variables, looking at the Factory IO driver configuration. I also created a separated table for the global variables.

In the OB1 I call the functions for the light control and the function needed for the factoryIO connection. I also call the FBs for the manual and automatic modes, and the emergency stop logic. The implemented logic for the lights and the exit conveyor are very simple.

Using a series of FBs I control the emergency state, manual, and auto modes. The auto mode calls the FBs that control the right and left elevators and the entry conveyor.

The logic for the right and left elevators is implemented as state machines. The functioning principle is that the entry conveyor is always feeding the left elevator. When the left elevator is moving a pallet, the entry conveyor waits. When each of the conveyors has already a pallet inside, the left elevator doesn't try to put another pallet. The priority order of the left elevator is the floor 0, then floor 1 and finally floor 2. In that order tries to fill the conveyors with one in each. In the other hand, the right elevator follows a FIFO queue. When the pallets are ready in the conveyors, the plc saves the query in a queue and the right elevator takes the pallets in that order.

Imagen 1
1 / 5

PLC físico

The FIFO queue is implemented using SCL language. I created a function that receives the number of the floor when the push input is activated. Then with the pop input you can delete the last value. Also you can always see the next value, the number of elements in the queue and if the queue is empty or full with two boolean outputs. The entry conveyor follows a state machine logic

Filling Tank (Timers)

The objective of this example is to fill and empty a tank using timers. For that we have 2 valves, one for filling and another for emptying. We also have 2 buttons and a display in a control panel. For this example I used CODESYS and Modbus TCP to communicate the simulated PLC with Factory IO. The PLC program is written in Ladder logic.

We must define the mentioned I/O as global variables. In this case we have 2 digital inputs for the fill and discharge buttons, 2 digital outputs for the valves, 2 digital outputs for the button lights, and an integer output for the display. I also use an auxiliary variable for the Int to Word conversion, since the display only accepts Word values.

Then we create a Ladder logic program that turns on the filling valve for 9 seconds and discharges for 9 seconds. The button lights act as a latching variable, and the display shows the remaining time for each operation. Finally, we map the I/O variables to the corresponding addresses in the Modbus TCP server and run the simulation in Factory IO.

From A to B

The objective of this example is to transport a box until it reaches a sensor, using a conveyor belt and a retroreflective sensor. For this example I used CODESYS and Modbus TCP to communicate the simulated PLC with Factory IO. The PLC program is written in Ladder logic. First, we must define the necessary I/O as global variables. In this case we have a digital output for the conveyor belt and a digital input for the sensor.

Then we create a simple Ladder logic program that turns on the conveyor belt when the sensor is not activated, and turns it off when it is, keeping in mind that the sensor is NC. Finally, we map the I/O variables to the corresponding addresses in the Modbus TCP server and run the simulation in Factory IO.

Level Control

The objective of this example is to control the liquid level of a tank using a Proportional-Integral-Derivative (PID) controller. I used CODESYS as a SoftPLC and Modbus TCP to communicate with Factory IO. The program combines Ladder Diagram (LD) for the control logic (Start/Stop/Reset and interlocking) with Structured Text (ST) for scaling and PID configuration.

A latching circuit handles the Start/Stop logic: pressing Start energizes the "Marcha" coil, which keeps itself active through its own contact until Stop is pressed. This "Marcha" bit enables the rest of the process, including the PID block and the fill valve.

Two ST routines handle the scaling: the setpoint coming from a potentiometer and the process value coming from the level sensor are both rescaled from the raw analog range (0–1000) to the 0–300 mm range of the tank. Once the system is running, the PID output is converted with TO_WORD and written to the fill valve through a MOVE instruction.

Communication between CODESYS and Factory IO is done through Modbus TCP, mapping Holding Registers for the level sensor and setpoint, Input Registers for the valve commands and PID values, and discrete Coils/Inputs for the Start/Stop/Reset buttons and their indicator lights.

Pick And Place XYZ

The objective in this example is to place boxes onto pallets using a three-axis Cartesian manipulator (X, Y, Z). Unlike the other examples, here I used a real Siemens S7-1200 PLC (CPU 1215C DC/DC/DC) with an additional SM1221 digital input module, all programmed in TIA Portal, communicating with Factory IO over Profinet instead of a simulated soft-PLC. The control logic combines Ladder Diagram for the sequencing and Structured Text (SCL) for the position comparison logic.

As with the other examples, I first defined the necessary I/O as global variables. The inputs include the pallet and box presence sensors (Box_at_place, Part_at_place), the vacuum gripper sensor (Detected), the rotation limit sensor (C_limit), the Start/Reset/Stop pushbuttons, the emergency stop, the Auto selector, and the three analog inputs that feed back the robot's real X, Y and Z position. The outputs cover the pallet, box and exit conveyors, the gripper rotation actuator (C+), the vacuum gripper (Grab), an exit traffic light, the pushbutton lights, the three analog setpoints sent to the robot axes, and a counter output for the finished-pallet display.

Imagen 1
1 / 5

PLC físico

Since the robot doesn't have discrete "position reached" sensors, I wrote an SCL function (mover_robot_SCL) that compares the real-time X/Y/Z feedback against a target position within a small tolerance, and sets three boolean flags (pos_X/Y/Z_alcanzada) once each axis is within range. All the target coordinates are organized as a custom "posicion_robot" data type, stored in a dedicated DB with named positions: home, the approach and pick poses above the box, and the approach and place poses for each of the three pallet slots. This keeps the state machine logic clean, since each state just calls the same function with a different position.

The main sequence is implemented as a state machine (E0 to E22) using Set/Reset coils, split into three near-identical sub-cycles — one per box on the pallet. Each sub-cycle moves to the approach position above the box, descends and grips it, retracts, rotates the gripper 90°, moves to the approach and place positions for that pallet slot, releases the box, and retracts again before starting the next sub-cycle. TON timers are used after each approach move, since the analog feedback settles slightly after the setpoint is written, so the state machine needs a short delay before trusting the "position reached" comparison. The C_limit sensor is checked between cycles to know when the gripper rotation needs to reset before starting a new turn.

The OB1 controls the overall program flow, checking the emergency stop and Auto selector, and calling the different functions and FBs. It controls also the emergency state and the running mode.

The rest of the program is split into small, single-purpose blocks: Control_cinta_entrada handles the pallet conveyor, using edge-detected memory bits and an SR block so the conveyor only restarts once the previous pallet has left and a new one is confirmed in position; Control_cinta_cajas and Control_exit_conveyor manage the box-feeding and exit conveyors; contador_terminados counts finished pallets with a CTU counter triggered on the rising edge of the pallet sensor (which is normally closed); and luces_botones drives the Start/Reset/Stop pushbutton lights. On a complete restart (OB100), the conveyor outputs are reset and the robot is commanded back to its home position.

Imagen 1
1 / 5

PLC físico

Palletizer

The objective in this example is to palletize boxes in stacked layers using a palletizer machine. As with the Pick And Place XYZ example, I used a real Siemens S7-1200 PLC (CPU 1215C DC/DC/DC) with an additional SM1221 digital input module, programmed in TIA Portal and communicating with Factory IO over Profinet.

As always, I started by defining the I/Os of the palletizing system. Firstly I planned the IO mapping using an excel sheet, and afterwards defining the variables in different plc variables tables in TIA Portal.

Imagen 1
1 / 4

PLC físico

The program is organized into one Organization Block and five Function Blocks, plus the connection function shared with the other examples. OB1 (Main) calls the Factory IO connection function every scan, and uses two P_TRIG blocks to detect a change on the Manual/Auto selector switch, setting a "modo_cambiado" flag whenever the mode is switched. A Start/Stop seal-in circuit sets the "marcha" (running) bit, but this circuit is interlocked with "modo_cambiado" so that changing the selector mid-cycle forces the system to stop rather than continuing in an undefined state. When the system is running in Auto, OB1 calls FB2 (modo_automatico), and "marcha" also drives a warning light.

FB2 (modo_automatico) calls the four process blocks every scan — control_roller_1, control_roller_2, control_ascensor and control_apilamiento — each with its own instance data block. These blocks run independently and stay synchronized through the physical sensors and a few shared memory bits.

control_roller_1 is a state machine (E0 to E5) that manages the entry conveyor: it waits for the palletizer to be free, edge-detects a new pallet arriving at the entry sensor, feeds it in and starts loading it into the palletizer, waits until the Pallet_loaded sensor confirms it's in position, and then holds until the "pale_terminado" flag is set by the elevator block before returning to E0 to accept the next pallet.

control_roller_2 uses a single TP (pulse) timer triggered on the falling edge of the exit sensor, keeping the exit conveyor running for a fixed 10 seconds so the finished pallet has enough time to clear the station after passing the sensor.

control_ascensor controls the lifting platform with a state machine (E0 to E6). Once a pallet is loaded it raises the platform to the first stacking level, using the Elevator_moving sensor together with TON timers to confirm the movement has started and finished. It then waits for the "primer_nivel_OK" flag from the stacking logic before raising to the second level, waits for "segundo_nivel_OK", and finally lowers the platform, sets "pale_terminado", and returns control to control_roller_1 so the pallet can be evacuated and a new one loaded.

control_apilamiento handles the stacking sequence with a state machine from E0 to E9. It feeds boxes in from the entry belt, uses two CTU up-counters to track how many boxes have been placed per row and column (with the target counts written via MOVE instructions), pushes each box against the plate, alternates the turntable 90° between boxes using the Pusher_limit feedback, closes the clamp to compact them, and opens/closes the plate using the Plate_limit sensor together with several TON timers to let each movement settle. Once a full layer has been placed it sets "primer_nivel_OK" or "segundo_nivel_OK", which control_ascensor uses to move the platform to the next level.

Queue of items (Counters)

In this example, the goal is to manage a queue of items using 2 conveyors and a retroreflective sensor. It is one of the simplest examples, but it is a good starting point to understand how to use counters in a PLC program. I used CODESYS and Modbus TCP to communicate with Factory IO. The PLC program is written in Ladder logic.

The logic here is very simple, using counters and having the outputs self latch. The counters output resets the outputs. The retroreflective sensor that detect the boxes are normally closed.

From A to B (Set and Reset)

The objective in this example is to transport a box from sensor A to sensor B. It is a very easy example to learn how to use the SR and RS blocks. I used Codesys and the simulated PLC as a ModBus TCP server to communicate with Factory IO.

Sorting by Weight

In this scene the objective is to sort cardboard boxes by weight using a conveyor scale. I used Codesys to program the simulated PLC CODESYS Control Win Systray x64. To communicate with the simulation in Factory IO the virtual PLC acts as an OPC-UA server, exposing the variables that i choose from the symbol configuration object.

The main program implements the start/stop control system with an interlocked emergency-stop and self-latching run state, which then enables the main control logic (FB_control) and simultaneously tracks how many boxes exit via the three different conveyor directions. Then I also programmed a separated FB for the emergency stop button that turns off all the outputs, and a FC block for the activation of the buttons lights.

The system uses a single state machine (E0 to E9) to handle the full cycle of a box: from entering the scale, taking the weight measurement, deciding the destination, and finally being routed to the right, front, or left conveyor. A short timer (TON) is used to let the weight reading stabilize before it's captured with a MOVE instruction into Weight_OUT. That value is then compared against three different weight ranges using comparator blocks, which determine which of the three branches (E4, E5 or E6) the box will follow.