PLC Programming Course (P3): How to Simulate the PLC Program

PLC Programming Course (P3): How to Simulate the PLC Program

PLC Programming Course (P3): How to Simulate the PLC Program

In this article (Part 3), you’ll learn how to simulate the PLC program that has been written in the previous part.

Simulating the PLC program is the last step before we download our program to the actual PLCs in the plant and test it with the real devices and equipment. On the other hand, it helps the beginner PLC programmers and automation engineers to gain a solid understanding of the program elements function and applications.

So, in this article, you’ll learn how to simulate the PLC program using Siemens PLCSIM software.

Part 1, was about creating a new project and PLC Hardware Configuration. 

In Part 2, we wrote a Ladder Logic PLC Program for a Water Pumping System project.

How to Download the Program to PLC

Downloading to the PLC means that:

– We want to make the PLC understands that to which actual devices it is connected (Hardware and Network Configuration).

– Which commands and actions (Logic) it should take to control the process properly (PLC Program).

I’ve opened the TIA Portal and the water pumping system project and entered the Main OB environment.

I’ll start by running the PLCSIM using the “start simulation” icon here.

NOTE: PLCSIM is the Siemens PLC Simulator that helps us to test our PLC program using a virtual PLC.

How to Download the Program to PLC

After clicking the PLCSIM icon, the virtual PLC and the “Extended download to device” window opens.

I choose the CPU and click “Load”.

Siemens PLCSIM Software

After some time the “Load preview” window opens.

Loading the PLC Program in TIA Portal

In this window, we see an action as “consistent download”.

If you have used any Functions (FC), Function Blocks (FB) or Data blocks (DB) in our software, then with consistent download you could download them automatically without any issues.

I click “Load” to download both the software and hardware to the PLC.

What is Consistent Download in TIA Portal

In the next window (Load results), we see that the download has been completed without any errors; besides, it asks that if we want to RUN the PLC CPU after downloading or not.

Be Careful!

In the actual processes, sometimes, if the software is not functioning properly when the PLC gets into the RUN mode right after the download, it may have some unwanted results. Because the software might start commanding some devices and runs some mechanisms.


1- You should test and simulate the PLC program before downloading it to the actual PLC in the plant.

2- You must think carefully, take required actions, and safety precautions before running the PLC.

I choose the “Start module” option to Run the CPU and click “Finish”.


The “RUN/STOP” LED blinks and the CPU goes into the RUN mode. You could also click the “RUN” button on the CPU.

How to RUN a Siemens S7 1500

Anyways, there are some other methods for downloading the hardware and the software to the PLC.

We can use the “Download to device” icon.

TIA Portal Download to Device

Or we can use the “online” menu options.

By these methods, all the software and hardware information will be downloaded to the device.

TIA Portal Download to Device Menu

But a more common method for downloading the software or hardware to the PLC specifically when the process is running is that to simply choose the PLC and right-click on that.

In the “download to device” menu, there are four options. If you have made some changes to the software and you only want to apply those changes, you should choose “software (only changes)”.

In this way, you’ll let the CPU to stay in the RUN mode. This is especially useful when the process is running, and we don’t want to interrupt the process by stopping the CPU.

The other options will stop the CPU by the way.

So be extremely careful! When the process is running, stopping the PLC CPU abruptly may have some harmful effects on the devices, equipment, or the final product.

Methods of Downloading to PLC

Monitoring the PLC Program in Real-Time

If I click the “Monitoring” Button, you see that the black lines will convert to green and blue lines that show the live or real-time condition of the level switches and the electric motor.

– Where you see the green lines it means that the condition is True.

– Where there is a blue line, the condition is False; same as the “Tank High-Level” Switch that does not sense any water, and therefore this condition is False.

Monitoring the PLC Program in Realtime

Force the Input Values to Your Desired Condition (Creating the SIM Table)

To force the condition of the switches to our desired simulation condition, I have to create a table and I am going to do that via the “Switch to project view” on the PLCSIM window.

How to Create a SIM Table in TIA Portal

In the opening window, I create a new project and name it as “Water Pumping System”.

Creating a New SIM Table in TIA Portal V15

After some processing, our project has been created.

What I need is on the “project tree” and under the “SIM tables” folder. I expand it and open the SIM table 1 by double-clicking on it.

I click on the “Load project tags” icon, and it automatically loads all the project tags.

We need the “Bits” column to modify the level switches inputs to true or false.

I float this table as I want to use it for the rest of the simulation so that you can see both the Ladder Logic and the SIM table at the same time.

How to Load Project Tags in TIA Portal

Time to Simulate the PLC Program!

Let’s start with this condition;

The Pool is full of water and therefore the “Pool Low-Level Switch” is active and sending a 24-volt or a TRUE signal to the PLC. Therefore, I activate its corresponding Bit in the SIM Table (Check the changes in the programming window).

The tank is empty and both the “Tank Low-Level Switch” and “Tank High-Level Switch” are inactive and therefore the pump is working to increase the level of the water within the tank.

Simulate the PLC Program Using a SIM Table

Very soon the “Tank Low-Level Switch” becomes active as it senses the water. To simulate its condition I activate the its Bit in the SIM Table.

Modifying the Values in SIM Table TIA Portal

As a side note, you see that the Flip Flop keeps the “Set” command and the pump is still running despite the “Set” connection is inactive and this is how Flip-Flop works.

How does a Flip Flop Works

As soon as the level of the water reaches the High-Level Switch and activates that, the “Reset” input of the Flip-Flop becomes activated and therefore the pump stops working.

Forcing the Values in SIM Table

Now the water level will settle down due to the consumption through the outlet and again the “Tank High-Level Switch” becomes inactive after some time.

How to Force the Input Values in PLC Simulation

When the water reaches below the Low-Level Switch of the tank, this Switch also becomes inactive and therefore the pump begins working and the water level starts to rise again.

TIA Portal PLC Simulation

This scenario will be continued unless the water level in the Pool decreases and the “Low-Level Switch” of the Pool becomes inactive as a result.

In this situation, the pump stops working instantly, even if the “Set” input of the Flip-Flop is active.


This is due to the priority of the “Reset” input in the SR Flip-Flop as we have talked about it in Part 2.

Here is why we chose the SR Flip-Flop instead of RS Flip Flop.

Ladder Logic PLC Program Flip Flop

OK, that was all the possible conditions with this simple process. We hope you have learned something new from this article.

Thanks for reading another article. Please spread the word by sharing this article:

If you’ve missed the previous parts here are the links to them:

Part 1: How to Configure the PLC Hardware

Part 2: Ladder Logic PLC Programming of a Water Pumping System

Our YouTube Channel

Contact Us

Have a question or suggestion?

[email protected]

Youtube channel

PLC Programming Course (P1): PLC Hardware Configuration

PLC Programming Course (P1): PLC Hardware Configuration

PLC Programming Course (P1):

PLC Hardware Configuration

In Part 1 of this Siemens PLC Programming Course you’ll create a new project and configure the Hardware Configuration in TIA Portal.


PLC programming starts by getting familiar and comfortable with the programming environment. So first things first! In this very first article of this course, we’ll create a new project and then configure the required hardware of the PLC in the Siemens brand new software, TIA Portal or Totally integrated Automation Portal V15.1.

In Part 2 we’ll continue with PLC programming of our process and in Part 3 we’ll end up with our PLC software simulation.

Of course, this free training course will be continued with other examples of real-world processes and we believe that you’ll learn many useful practical tips and tricks in them.

Creating a New Project in TIA Portal

Totally integrated Automation Portal or TIA Portal is the Siemens brand new software that you can program your S7-1200 and S7-1500 series PLCs using that.

A project in TIA Portal contains all the hardware, network, programming, and monitoring system information.

TIA Portal V15.1

By double-clicking on the TIA Portal icon we can open up the software; after a few seconds, we see this window. From the Start menu, we obviously should choose the “Create new project”.

I name the new project as “Water Pumping System” and specify a location to save that. Then, I click “Create”. Creating a new project was pretty easy, right?

How to Create a Project in TIA Portal

Now, other submenus of the “Start” menu are enabled and you see them on the left and right hand side of the window.

Hardware Configuration in PLC Programming

As the next step that is configuring the PLC hardware, we can select either

– the “Configure a device” sub-menu or

– the “Write PLC program” sub-menu

As they both do pretty much the same thing. They both let us select the hardware and configure them before we start writing the PLC program.

I prefer choosing the “Configure a device” submenu and then click on “Add new device” to add my PLC CPU.

PLC Hardware Configuration in TIA Portal

In the “Add new device” window, in addition to Controllers (or PLCs), you see also HMI and PC Systems that we will talk about them in future articles.

Add New Device to Your Project in TIA Portal

Now, let’s select our PLC CPU. I’m going to choose an S7-1500 series PLC CPU, so I expand its folder and I think a 1513-1PN CPU is enough for our process.

When you click on each CPU, you see a technical description of that and its specific article number.

Adding a PLC to TIA Portal Project

Important NOTE:

Remember that if you are going to program an actual PLC in a plant, the process to configure the hardware requires some information beforehand.

For example, you should exactly match the Order Number or Article Number of the hardware in TIA Portal with the exact order number of your existing actual hardware. Otherwise, you will face some unwanted errors and you may not connect to your PLC.

PLC Hardware and Software Compatibility

Among the CPUs under the 1513-1 PN folder, I choose the this one (6ES7 513-1AL02-0AB0) and click “Add” to continue.

Siemens 1513-1PN PLC CPU

In the opening window, we have three tabs;

– Device view

– Network view

– Topology view

What we deal with in this article is the “Device view” tab.

As you see, the software automatically has added the appropriate Rail for the PLC and mounted the PLC on that. Something that does not happen in the older versions of Step7 software like version 5.6 or older.

TIA Portal Hardware Configuration Window

On the right-hand side of this window, there is the Hardware catalog pane in which we can find any hardware modules we need and add them to our configuration.

SIMATIC MANAGER Hardware Catalog Pane

In the next part of this example, we’ll write the PLC Program of a Water Pumping Process.

So, according to the process we need only a Digital Input (DI) and a Digital Output (DO) card as we have three discrete inputs and just one discrete output.

Estimating the Required PLC Cards

In the Hardware Catalog pane, under the DI folder, as you see there are 16 and 32-input channel cards that we can choose among them.

32 Channels Digital Input Cards

I choose a 16-channel Digital Input module (6ES7 521-1BH10-0AA0)

When I click over each module, in this case, the Digital input card, it shows us on which slots I can add this module by illustrating some blue rectangles around them.

How to Add a Digital Input Card to the Rack in TIA Portal V15

And if I expand the slots, you see that I can add it anywhere after the CPU.

I drag and drop it into the slot number 2, right after the CPU.

To Which Slot Should I Add a DI Card

As another example, if I select a Power supply module (PS module), there is another option to place that, and it is right before the CPU, in slot zero, which is a more common practice.

Adding a Power Supply Module to Slot Zero

I also need a Digital Output card and I can find it under the DQ folder. I choose a 16-channel DO or DQ card (6ES7 522-1BH10-0AA0) and add it to slot number 3 by dragging and dropping it.

Adding a Digital Output Card to the PLC Rail

I save the project and then compile it. For compiling the hardware, we should first select the rail and then the compile icon will be activated.

Save and Compile the PLC Hardware Configuration in TIA Portal

I think now we are done with PLC hardware configuration and ready to program our PLC in the next part.

Thanks for reading another article. Please spread the word by sharing this article:

Following are the links to the next parts of this PLC programming example:

Part 2: Ladder Logic PLC Programming of a Water Pumping System

Part 3: How to Simulate the PLC Program

Our YouTube Channel

Contact Us

Have a question or suggestion?

[email protected]

Youtube channel