PLC Programming Tutorial for Beginners_ Part 1

A step-by-step PLC programming guide.
PLC Programming Basics- thumbnail
Listen to this article

Hello again, in this article we will learn how to write a PLC program for the machine illustrated here by using an S7 300 PLC and STEP 7 software.

We have two pumps which are being used to transfer two separate liquids into the tank.

Inside the tank there are two level switches installed in the lower and upper parts of the tank respectively, the switches are digital which means that they can only ever be in one of two states: true or false.

There is also an electrically powered mixer inside the tank which starts working for a defined period of time, mixing the two liquids together after the tank has filled.

We also have a discharge valve in the bottom of the tank which controls the draining of the liquid from the tank.


Program Functionality

Ok now let’s see what the program should do.

The lower level switch has an open contact inside it. When the level of the liquid drops to the level of the switch's position the contact closes, sending a 24 Volt DC signal to the PLC input.

We want to write the program so that when the level of the liquid reaches this minimum, the pumps will be activated and begin filling the tank with the liquids.

The pumps continue filling the tank until the level reaches its maximum at the higher level switch. When this happens the open contacts in the switch will be closed and another 24 Volt signal will be sent to the PLC input telling us that the tank is full.

When this signal has been sent, first the pumps should shut down so that no more liquid enters the tank, and then the mixer should be turned on.

We want the mixer to operate for seven seconds, mixing the liquids that have been pumped into the tank.

After seven seconds the mixer should automatically shut down and the discharge valve should open.

With the valve open the liquid will be discharged from the tank and transferred to another location within the factory to be processed.

When the level of the liquid in the tank drops to the minimum set level of the lower switch, the switch contacts will close again thus starting a repeat of the cycle.


Ok so now we need to click on the SIMATIC Manager desktop icon in order to start writing the program. SIMATIC Manager is a program which manages subprograms of STEP 7.


To start our programming first we need to create a new project by clicking on the new icon on the toolbar to open the "new project" window.

In this window, we enter a name for our project in the name field. We'll call this project Mixer and enter it here.

The path to our saved project is shown in the storage location. However, we can use the browse button to navigate to a different location other than the default.

new project

OK after creating the project we click on its name to highlight it, then from the insert menu we select one of the stations dependent upon the control system that we intend to use.

As discussed previously we will be using an S7-300 PLC to control our machine, so we need to select the second option shown here which is station 300.


After selecting this option we see that a subgroup named SIMATIC 300 has been added to our project.

Hardware Configuration

Next, we click on the hardware icon which takes us to the hardware so that we can configure the modules we need for the PLC.


Our PLC is an S7-300 so we need to select the relevant modules from SIMATIC 300 subgroup.

First of all, we need a rack into which we will mount the modules.

To insert the rack, open the RACK-300 and double-click on the Rail to add it to the left window.

As you can see this rack has 11 slots.

RACK-300 in STEP 7

We need to install a power supply in the first slot to power our PLC modules and turn them on.

To do this we open the PS-300 folder and double-click on the two-ampere power supply to insert it into the first slot of the rack.

Note that all the listed PLC modules have an order number or part number which is displayed in the lower box when each module is clicked.

In real-world projects the order number of each module that we select should match exactly the module in the enclosure but as this is a demonstration project for training purposes we can ignore that requirement for now.

PS 300 in STEP 7

Ok in the second slot of the rack, we always insert the CPU module.

To select the desired module we open the CPU-300 folder, which opens to show us all types of 300 CPUs.

We want to select a 316 CPU, so we need to open the "CPU 316" folder and click on the relevant part number to insert it into the second slot in the rack.

CPU 300 in STEP 7

Now, in addition to these two modules, we need an input and an output module, both digital.

The input and output modules are both categories in the subgroup SM 300.

To insert a digital module we need to open the DI 300 folder and double-click on the 24 Volt module which has 16 inputs.

However, as you can see, after doing this we get a message that this module can only be inserted into slots 4 - 11.

 DI 300 in STEP 7 error

So we need to leave the third slot empty, select the fourth slot, and then double-click on the module again to insert it into the rack.

DI 300 in STEP 7

Now we can also insert the digital output module by opening the "DO 300". Double-click on this module to insert a 24 Volt, 16 output module.

DO 300 in STEP 7

OK, the addresses of the digital input module range from byte zero to byte number one, which means that the addresses we can use in this module for our program start at I 0.0 for the first input and continue through to I 1.7 for the last input. This gives us 16 digital inputs.

Similarly, as you can see the addresses of our digital output module range from byte number 4 through to byte number 5, so there are 16 addresses that we can use for this module starting at Q 4.0 and continuing through to Q 5.7.

 I/O range for DI 300 and DO 300 in STEP 7

Configuration Completion and Testing

OK so now the configuration is complete and we can download it to the PLC. We will use a simulator to test the program, so we need to click on the simulator on/off icon in the SIMATIC environment in order to run the simulator program.


Now we go to the insert menu and select input variable so that we can insert an input variable.

PLCSIM input variable

Similarly, we can select output variable but as the address of our output module starts from byte number 4 we need to change the 0 to a 4.

PLCSIM output variable

Before downloading the configuration first click on the save and compile icon to save it, then we click on the download icon.

This brings up a window where we need to select the CPU to which we want to download the configuration and then click OK.

Save and compile and download to PLCSIM

In the next window click on view and then select the appropriate MPI address, and after clicking OK the configuration will download to the CPU.

Select Node Address

Now, having completed the configuration we can check the project tree and see that a subgroup with the same name as the CPU has been added there.

Now we can write our program in a block named OB1.

We can find the OB1 by opening the "S7 Program" folder and looking in the block folder.

OB1 in STEP 7

Ok now we open the OB1 by double clicking on it; as it's the first time we have opened it the properties window opens.

We simply OK the window to get into the programming environment.

OB1 properties


So far we have learned how to make some basic settings and organize the environment so that we can start programming.

In the next article, we'll learn how to write a program using simple and practical instructions that will control our machine.

Join the Top 1% of Automation Engineers

Try for Free

Learn from
industry experts

Start your learning journey today!

with a free 7-day trial, then $25/month
Start Free Trial Now