Fesher Engineering Jobs, PLC programming, SCADA sYSTEM, Uncategorized

Ladder Logic Programming Basics

One of the best visual programming languages is a PLC programming language. It’s called ladder logic or ladder diagram (LD) and you can learn it very fast.

The smart thing about ladder logic is that it looks very similar to electrical relay circuits. So if you already know a little bit about relay control and electrical circuits, you can learn ladder logic even faster.

In this ladder logic tutorial you will learn everything you need to know about the ladder diagram PLC programming language. You will be able to start making real PLC programs with ladder logic in almost any PLC programming software. After reading this tutorial I strongly recommend that you continue with one of the PLC programming courses.

Let’s get started!

Ladder Logic PLC Programming Tutorial

What is Ladder Logic?

Ladder logic is a PLC programming language. It is really called ladder diagram or just LD, but most people refer to it as ladder logic. That is also what I will call it in this tutorial. There’s a very simple reason for its name. Ladder logic is made out of rungs making what looks like a ladder. It is possible to scale a PLC analog input for example, but ladder logic is mainly for bit logic operations.

The people or the organization that sets the standards for ladder logic is PLCOpen. Ladder logic is not only a programming language for PLC’s. It is one of the standardized PLC programming languages. This simply means that ladder logic is described in a standard. That standard is called IEC 61131-3. But for now, the only thing you need to know, is that there is a standard describing this programming language.


Introduction to Ladder Logic

To get you started with ladder logic there are a few things you should know about the programming language. You should know why ladder logic was invented, because then it will be much easier for you to understand it. Especially if you have prior experience with electrical circuits and relays or some boolean logic.


Invented for Technicians

Ladder logic is a graphical programming language which means that instead of text, the programming is done by combining different graphic elements. These graphic elements are called symbols.

One of the smart things about the ladder logic symbols is that they are made to look like electrical symbols. Ladder logic was originally created for technicians, electricians and people with an electrical background. People who are used to look at electrical diagrams and schematics.

Take a look at the symbols and see if you think they look familiar.

Just as in electrical diagrams ladder logic have symbols for contacts and relays (which are called coils in ladder logic). The symbols may look a little different from the ones you find in electrical schematics, but they have almost the same functions.


How to Read Ladder Logic

Another difference between ladder logic diagrams and electrical schematics is the way they are drawn. Where electrical schematics is often drawn horizontal, ladder logic diagrams are drawn vertically.

The best explanations for drawing ladder logic vertical instead of horizontal I can give you are these:

1. Easier to read

First of all it makes ladder logic easier to read because it is natural for the eye to go from the left to right and then down to the next line. Just like when you are reading. Of course this applies only to people living in countries where the reading is done from left to right.

2. Drawn on computer

When you draw ladder logic on a computer you will make one line at a time. As you draw more and more lines (in ladder logic called rungs) they will stack on top of each other, making up what looks like a ladder. The best way to look at a large ladder diagram with many lines is to scroll vertically along the screen.

3. Order of execution

The last reason for drawing ladder logic horizontal is to set the order of execution. Order of execution is how the PLC will run your ladder logic. To be more precise in what order your ladder logic instructions will be executed by the PLC. A PLC will always start at the top of your ladder logic and then execute its way down.

Relay Ladder Logic

As I said before ladder diagrams can look a lot like electrical schematics going vertical. Most people learn to draw ladder logic diagrams this way – by building them as electrical schematics. But there are some differences. This is why I will advice you to learn it in a different way.

I will explain this way in this ladder logic tutorial.

The problem here is that electrical control systems and the PLC works in different ways. Here are the biggest differences:

  • The PLC takes one ladder logic line (rung) and executes that and then goes to the next line
  • In electrical systems multiple lines (current pathways) can be executed (activated) at the same time

With these crucial differences in mind, let’s get into it. It’s time to learn some ladder logic.

Ladder Logic Basics

The first thing you will see when you create a new piece of ladder logic are two vertical lines. It is in between these two lines your ladder logic goes. When you draw ladder logic, you will draw vertical connections between these two lines. Each of those are called a rung. Just like on a physical ladder.

Ladder Logic with Horizontal Lines called Rungs


In these rungs you can put any of the ladder logic symbols to create the logic you want. As you can see above, I have put numbers on each rung. This is to understand how the PLC will execute the ladder logic. You may be familiar with the PLC scan time or scan cycle. Roughly said, the PLC will first scan all it’s inputs, then execute the program to set outputs.

But how does the PLC execute our ladder logic?

One rung at a time.

This might be one of the most important rules of ladder logic. The PLC only executes one rung at a time, then executes the next. In fact, the PLC only executes one symbol at a time.


Ladder Logic Programming with Instructions

Each symbol in ladder logic is an instruction. This can, in the beginning, be rather confusing. But don’t worry. I will explain this with simple examples. Let me start by giving you a simple example. In this first example you will be introduced to the two first ladder logic symbols.

So what are these instructions or symbols?

They are basically logic instructions, that makes you able to create a piece of logic. That piece of logic is your ladder logic or PLC program. If you take a closer look at the example below, you will see two instructions (symbols).

Two Instructions in One Ladder Logic Rung


Examine if Closed

The first instruction here is called examine if closed. The symbol for the instruction looks like this:

Examine if Closed Instruction

This is a conditional instruction. It means that you can use it to check if something is true. For example check if a bit is on.

As you can see there is a name above the instruction symbol – I0.0.

This is the address of the specific bit, this instruction will examine. In this case, a digital input. It could also just be an internal memory bit or even an output.

Examine if closed is also known as normally open. It works basically the same way as a normally open contact in en electrical circuit. Of course, the normally open contact has no memory bit as a condition. The condition is whether the contact is activated or not. So the condition could be a finger pressing a button.

The main point here is that, each instruction has to be assigned an address in the PLC.

Yes, inputs and outputs are also bits of memory in the PLC. In the example above, the examine if closed instruction has been given memory address I0.0 as a condition. This address belongs to the first input of the PLC.

Here’s how that works:

  • When the PLC scan cycle starts, the PLC will check the states of all its inputs.
  • It will then write in memory the boolean value for these states (0 or 1).
  • If an input is LOW the bit will be set to 0.
  • And if an input is HIGH the memory bit will be set to 1.

Output Coil

The instruction itself even has a place in the PLC memory. What the PLC will put there is the result of the instruction. To see what the PLC uses that result for, we have to look at the next instruction:

Ladder Logic Output Coil


An output coil is used to turn a bit on and off.

As you can see, the symbol is placed in the right side of the rung. This means, that all the instructions that come before (in the same rung) act as a condition for that instruction. In our example that will be the result of the examine if closed instruction.

Let’s check out what the results of that instruction could be, to see how it works:

  1. PLC scan | Inputs -> I0 byte
  2. Program runs | I0.0 -> XiC result

Ladder Logic Inputs and Outputs with PLC scan


In the animation above you can see that the PLC first scans all its inputs. The states of these inputs are then saved in a memory byte. A memory byte is just 8 bits next to each other. For now, you don’t have to think too much about it. But placing the bits next to each other is very smart. I’ll come back to that later.

When the PLC has the states of all inputs saved, the program will start to run. First instruction to be executed is the examine if closed (normally open). The result of this instruction will be the same as the state of the memory bit. It makes sense to call the instruction normally open. In a normal state (where the memory bit is 0) the contact will be open, and the result be 0. But if the memory bit is 1 the contact will close and yield the result 1.

At last, let’s look at the output rung:

  1. XiC result -> Output coil
  2. Output coil -> Output byte

Now, the output coil uses the result of the previous instruction as a condition.This is called RLO (result of logic operation). The RLO is stored in a special place in PLC memory. In Siemens S7 PLC’s that place is called the status word.

A word in PLC terms is 16 bits next to each other or 2 bytes.

The output coil works in a simple way. It simply sets the bit to the same value as its condition (RLO).

In the PLC all the digital outputs are also assigned to bits in memory. We’ll call that the output byte (Q0), so the bits Q0.0 – Q0.7. The result of the output coil will be put in memory bit Q0.0.

When the PLC has executed the whole program, it will set the outputs. The state of each output is set to the same state as the output bits.

This whole scan cycle is very important to keep in mind, when you’re programming in ladder logic. Otherwise, your program might act a bit strange. This will be illustrated in the next example. At the same time, you will also learn about 3 other ladder logic instructions.


Output Latch

In the previous example, you learned how to read the state of a digital input and set a digital output to the same state. Let’s say that digital input is a momentary pushbutton. It is called momentary because it has a spring inside. This means, that the pushbutton will only be active as long as you press it.

The ladder program above works just fine. But as you might have noticed, the output will only be active as long as the input is active. You will have to hold your finger on the button to keep the output activated. But let’s say that the output controls a fan for a ventilation system. It would not be very convenient for the operator to hold down the button all the time. We need a way to keep the output active, even though the operator releases the pushbutton.

In ladder logic there are two ways to do that:

Output latch in ladder logic


If you are familiar with electrical schematics, you may find this familiar. This is called a latch or a self-hold.

The name reveals how this works. The coil simply holds itself. Let’s take it step-by-step to see how that works:

When the PLC runs this ladder logic program the first time (with the button pressed), the output will be activated. This is just like the example before. The fun happens the second or third time the PLC runs the ladder logic. Since this is a momentary pushbutton, it will not be active for long. Depending on how long time the PLC takes to execute the program, the button might be deactivated again the second, third or fourth time.

Let’s jump forward to the first scan cycle where the button is no longer pressed.

The output is still active, since the pushbutton was pressed in the last scan cycle. This time the PLC will, again, read the inputs and save them in the memory byte. In memory bit I0.0 the PLC will now save a “0”. The first examine if closed instruction with I0.0 as condition will be evaluated to false or “0”.

But as you can see, there’s another examine if closed instruction parallel to the other. But this one has the output memory bit as condition. This will therefore be evaluated as true or “1”, since the output is still active. As long as the output memory bit is “1”, the output will be activated. It acts as a condition for itself.

The reason that the self-holding instruction is put in parallel to the other instruction is to make it an OR condition. I will come back to that later. Important to know here is that either I0.0 OR Q0.0 has to be true to activate the output.


Examine if Open

Well, congratulations!

You just learned how to make a functioning ladder PLC program. A pushbutton that activates an output. In our example this would be connected to a contactor giving supply to a fan. The output then holds itself.

But there is a practical problem with this program. How do we stop the fan?

We want, somehow to be able to turn off the output again. The simplest way to do that, would be to add a stop button. The button will be connected to the second input. Thereby giving it the memory address I0.1.

The question is now; which instruction should we use for the stop button?

And even more important; where should we place it in out ladder logic?

To answer the first question, let me introduce you to another ladder logic instruction: examine if open.

Here’s how the examine if open symbol looks like:

Examine if Open Instruction


This instruction works the exact opposite way of the examine if closed instruction. The result of this instruction will be the inverted condition. It simply means that, if the condition is “0” the result will be “1”. Vice versa of course, so with condition “1” the result will be “0”.

If you think about it, this is precisely how we want to stop button to work. To turn off the output coil we must somehow give it the condition “0”.

Now to the second question. Where to place it?

We have to place it after the self-holding instruction. Said in another way – serial connected. Otherwise the latch would still give a “1” condition to the output coil, when stop button is pressed.

Now, we end up with this ladder logic:

Output latch with XIO to break the latch


You can see that it inverts the condition to the output coil. This will break the latch. To activate the latch again, the start button has to be pressed.

In the example above i used the examine if open instruction for a stop button.

This is not good practice!

Because in order for the stop button to work when its pressed, we have to use a normally open contact on the button itself. You can read more about why you have to use normally closed contact for stop buttons in my article about it. In short, it is to make sure that the system stops when a wire to the button breaks.

After using this good practice our ladder logic will look like this:

Output latch with stop


Although we changed the instruction, the ladder will still work in the same way. It’s because we also changed the way the physical stop button works.

You now learned how to set an output and hold it until a stop button is pressed. But there are other ways to do this. Latching is not the only way.

For Further Information Call@ +91-9555405045/+91-9718474287

or Visit: http://www.innovicindia.com




PLC Program to Operate Drilling of Parts


Whenever a part is placed on the drilling table, pneumatic clamper clamps the part and drilling process is done. When drilling is done, clamper releases the part by releasing pressure. When another part is detected, the process is repeated. Implement this in PLC using Ladder Diagram programming language.




  • Set lower and upper limit of a motor to stop and start the drilling process. This is done for precise drilling and to obtain uniformity.
  • Pressure operated clamping device is used to hold the objects firmly. This is operated by 20psig air supply which is provided when an object is detected.
  • Limit detection object is placed on the motor to detect upper and lower limit by the switches.

PLC Program:

Here is PLC program to Operate Drilling of Parts, along with program explanation and run time test cases.

List of Inputs and Outputs

I:1/14 = Start                                                              (Input)

I:1/15 = Stop                                                               (Input)

O:2/15 = master coil                                                 (Output)

O:2/0 = Clamping Device                                         (Output)

O:2/1 = Drilling Motor                                             (Output)

O:2/2 = Motor Down                                                (Output)

O:2/3 = Motor Up                                                     (Output)

I:1/0 = Object detect switch                                   (Input)

I:1/1 = Lower Limit                                                 (Input)

I:1/2 = Upper Limit                                                 (Input)

Ladder Diagram to implement automation of drilling process:


Program Description:

  • RUNG001 is to operate Clamping device with address O:2/0, Motor Down Coil O:2/2 and Drilling Motor O:2/1.
  • These outputs are operated when an object is detected.
  • Clamping device and Motor Down coil is de-energized when Lower Limit of drilling motor is detected which is connected to I:1/1. And Drilling Motor O:2/1 is de-energized when Upper Limit I:1/2 is detected.
  • RUNG002 is to operate Motor Up coil with address O:2/3. When Lower limit is reached that means drilling is completed. Next operation is to take Drilling motor back to its main position and for that reverse coil Motor Up coil with address O:2/3 is energized.
  • When it is reached to its main position that is Upper Limit I:1/2, reversing Motor Up coil is de-energized.

Runtime Test Cases:

Inputs                    Outputs                                     Physical Elements

I:1/0 = 1          O:2/0 = O:2/1 = O:2/2 = 1   Activate Clamper, ON Motor, Energize Motor Down

I:1/1 = 1         O:2/0 = 0, O:2/2 = 0              Deactivate Clamper, De-Energize Motor Down

I:1/1 = 1         O:2/3 = 1                                Energize Motor Up Coil

I:1/2 = 1         O:2/3 = 0                                De-Energize Motor Up Coil, OFF Motor



PLC Program to Control Level of Parallel Tanks

This is a PLC Program to Control Level of Parallel Tanks.


Two tanks are connected in parallel with a stream line. Heat and Cool the same material and control level of both tanks. Implement this in PLC using Ladder Diagram programming language.




  • Heater is used to heat the material and cooling water supply is used to cool down material temperature.
  • Inlet valve feeds Material to both tanks.
  • One tank stores material for heating purpose and the other stores material for cooling purpose.
  • Level switches are used to detect Low level and High level in both the tanks.
  • Outlet valves are installed in the bottom of both the tanks to drain products for further process.
  • Mount temperature sensors to measure temperature of both the tanks.
  • Controlling of these tanks is independent of inlet flow assuming inlet flow to be constant.

PLC Program:

Here is PLC program to Control Level of Parallel Tanks, along with program explanation and run time test cases.

List of Inputs and Outputs

I:1/0 = Start PB (Input)

I:1/1 = Stop PB (Input)

I:1/2 = LLST1 Low level of Tank 1 (Input)

I:1/3 = LHST1 High Level of tank 2 (Input)

I:1/4 = LLST2 Low level of Tank 2 (Input)

I:1/5 = LHST2 High level of Tank 2 (Input)

B3:0/0= Latching bit (Bit)

O:2/0 = V2 To heating tank (Output)

O:2/1 = V4 outlet from heating tank (Output)

O:2/2 = V3 To cooling tank (Output)

O:2/3 = V5 outlet from cooling tank (Output)

N7:0 = Register to store temperature of heating tank (Register)

N7:1 = Register to store temperature of cooling tank (Register)


Program Description:

  • RUNG001 is to control V2 Valve. This is operated whenever Low level of Tank1 is detected or if Low level or high level both are not detected.
  • RUNG002 is to control V4 valve. This is operated whenever Temperature data of tank 1 is greater than or equal to 70o C.
  • Latching of V4 is not provided because it is independent of Inlet valves. Even if the tank is half empty but temperature is more than 70oC, outlet valve of the tanks open.
  • Similarly RUNG003 and RUNG004 work and V3 and V5 are operated.

Runtime Test Cases:

Input                                           Output                                   Physical Elements
I:1/2 = 1                                        O:2/0 = 1                                  Open V2 Valve
I:1/3 = 1                                        O:2/0 = 0                                  Close V2 Valve
N7:0 ≥ 70                                     O:2/1 = 1                                  Open V4 Valve
N7:0 < 70                                     O:2/1 = 0                                   Close V4 Valve
I:1/4 = 1                                        O:2/2 = 1                                   Open V3 Valve
I:1/5 = 1                                        O:2/2 = 0                                   Close V3 Valve
N7:1 ≤ 20                                     O:2/3 = 1                                   Open V5 Valve
N7:1 > 20                                     O:2/3 = 0                                    Close V5 Valve

If want to know more about PLC then feel free to contact us on:

Contact Person: Raj Nayak

Contact No. : +91-9555405045

Website: http://www.innovicindia.com



Continue reading “PLC Program to Control Level of Parallel Tanks”