Basic PLC Programming – How to Program a PLC using Ladder Logic (for Beginners)
Basic PLC Programming – How to Program a PLC using Ladder Logic (for Beginners)
This guide assumes that, because you know about the existence of
Programmable Logic Controllers, you already know the most basic electrical
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 1 of 38
:
principles that govern the actual PLC operations. The knowledge of Input
Devices helps to imagine a multitude of solutions to a common problem, as
well as knowing the different Output Devices that are controlled by the PLC
to solve the problem in the first place.
For instance, you want a control system for your water tank. You want the
tank to fill up until it is full and then automatically refill one the water level is
near empty just to maintain the pressure. What do you do?
Because you have clearly identified what outcomes you want along with the
conditions, you now have to think the appropriate types of sensors and
output devices that you must use.
In this case, because there are water levels involved, you must use level
sensors: One for the Full level and one for the Near Empty level. Lastly, you
would want to control an input valve to regulate the flow of water into your
tank.
I found this helpful video that actually shows a control problem to solve:
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 2 of 38
:
PLC Programming
Programming Tutorial for Beginners_
Beginners_ Part 1
RealPars
Watch on
The next step is actually designing a program for your controller to execute
the steps required to perform your automated control system.
But first, you have to know some logical fundamentals that will allow your
system to create decisions on its own.
Fundamentals of Logic
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 3 of 38
:
PLC Programming was based on Relay Logic, and Relay Logic was based on
—well, the fundamentals of logic. Logic circuits are digital, so they produce
outputs that are discrete in nature. This means that it’s either “True or
False”, “High or Low”, “Yes or No”, “0 or 1”. Nothing in between. This
simplifies input-output relationships as compared to the analog side of
things.
The result may also vary by the tiniest amount and it is already considered a
different output. Therefore, it is much simpler to use the Binary concept in
Number Systems to represent the outputs.
What is Binary?
Binary is part of the M-ary system of representation when M is the total
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 4 of 38
:
number of results. Confused? For a single digit, BI (two)-nary means two
possible outputs. Quarter(four)nary means four possible outputs. The
Decimal number system—which we are familiar with, has 10 (prefix Deci-)
representations: 0, 1, 2, 3, up to 9.
Because you are an intelligent human being, you may have guessed that
more digits can represent more values. In decimal, you use 10 if you have
exceeded counting through all representations (0 to 9) once. You use 20 if
you have exceeded twice, and so on.
Binary numbers are quite the same. 0, 1, 10, 11, 100, 101, 110, 111, 1000—you
see the pattern? One digit is added to the mix every time you have “used up”
all the possible representations.
Using the proper sequence and arrangement of the Relays, the early
programmers were able to set conditions for switching their output devices.
The way they did this is by using the binary logical operations: NOT, AND,
OR, XOR, NAND, NOR, and XNOR.
Whether you have relays or logic gates, these are the fundamental logical
operations that you must know.
Note: For the examples that I will discuss below, the assumption is an output
of 1 “Turns the circuit ON” and an output of 0 is a “Circuit OFF condition”.
NOT
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 5 of 38
:
The NOT operation performs negation of input. If you have “0” as an input,
performing the NOT operation will output a “1”. Let’s look at how this is
performed using Relays.
Hence, the Normally Closed relays served as the primitive versions of NOT
gates.
This is the only logical operation that requires only 1 INPUT. The logical
operators that I will discuss next require 2 inputs. Basically, they now
COMPARE the inputs that you provide.
AND
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 6 of 38
:
PLC Programming AND table
The AND gate outputs a “1” whenever BOTH inputs are “1”.
In everyday language, the AND operation requires that input 1 AND input 2 is
ON.
How did they do it for Relays? By placing normally open relays in series.
Connecting the normally open relays in series would not allow current to
pass through unless BOTH relays are energized. Simple as that.
The AND operation is commonly used in drilling machines where, for safety
reasons, the operator must use two hands to turn on the drill. This
decreases the possibility that the operator has his hand placed on the
drilling platform while the drilling operation starts.
OR
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 7 of 38
:
The OR operation outputs a “1” whenever ONE of the inputs is a “1”.
Basically, both Input 1 and Input 2 can control the switching of the circuit. In
comparison with the AND operation, you can only turn on a circuit by turning
BOTH switches ON.
In the AND operation, the relays were placed in series. In the OR operation,
relays are connected in PARALLEL to each other.
XOR
XOR stands for “Exclusive OR”. This means that the input must be different
from each other, hence the term exclusive.
Using XOR, only one input at a time can control the circuit switching.
NAND
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 8 of 38
:
PLC Programming NAND table
The gate will turn OFF when BOTH inputs are ON. Hence, you can expect
the truth table to be an inverted version of the AND truth table in terms of
the output.
NOR
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 9 of 38
:
PLC Programming NOR table
XNOR
When you want to turn on a circuit when the states of both inputs are the
same, XNOR is used.
This means that when both inputs are OFF or both inputs are ON, the XNOR
operation turns the circuit ON.
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 10 of 38
:
Boolean Algebra
Usually, the inverted versions of logical operations are not used in practical
circuits as you can easily change inputs into a Normally Closed one instead
of a Normally Open one (more on that later). But, it is still helpful to have a
basic understanding of them.
What this means for us is a shorter program that performs the same
operation, and that is highly desirable.
There are different laws that consist Boolean Algebra, and most of them are
similar to the mathematical laws that we have studied in elementary school.
The three basic rules are:
Commutative Law
This law states that two inputs are added (OR) or multiplied (AND), the order
is not important. This means that the result is the same for A+B and B+A.
For A*B, the result is the same for B*A. Both are similar to Mathematical
rules.
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 11 of 38
:
Associative Law
Again, this law is just similar to the associative law in Mathematics. Either
adding or multiplying three variables together in a grouped fashion does not
affect the result.
(A+B)+C=A+(B+C)
(A*B)*C=A*(B*C)
Same goes for the AND. When the result of A AND B is applied with C using
the AND operation, the logical output is the same as that of A coupled with
the result of B AND C.
Distributive Law
A*(B+C)=(A*B)+(A*C)
A + (B * C ) = ( A + B ) * ( A + C )
So, when you see an equation that resembles the one on the right, it is
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 12 of 38
:
actually more practical to use the equivalent equation on the left because
that ultimately results in the same output using a shorter program.
As stated earlier, the AND gate is simply a “multiplication” and the OR gate is
simply “addition”.
We can further simplify this using the NAND gate, because we have learned
earlier that the NAND gate is the equivalent of ‘NOT AND’.
(A NAND B) OR C
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 13 of 38
:
Now, if you wanted to take this logic gate representation back into a boolean
equation, you would have to turn EVERY operation into a representation
using just three operations:
NOT
OR
AND
Further Reading:
Logic Gates by Electronics Tutorials
Boolean Algebra by Electronics Tutorials
Short Guide on Boolean Algebra
The IEC has published the IEC 61131 standard for PLCs which should be
followed by all users worldwide, and it has a section specifically for PLC
programming languages, the IEC 61131-3.
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 14 of 38
:
to the PLC. The IEC 61131-3 standard defined the five
standard languages that are used in PLC programming.
Structured text
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 15 of 38
:
Example:
The example above directly shows the relationship between the variables for
the input and the output.
For example, in the structured text above, all variables within the
parentheses will be executed first. In that case, the most inner set of
parentheses should be evaluated, and that contains “NOT PushC”.
The program negates PushC first, and then evaluating the logical value of
PushB AND *the result* before evaluating it with PushA using the OR
operation.
Further Reading:
Instruction List
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 16 of 38
:
example.
Since different manufacturers use different mnemonics, I will only give the
IEC61131-3 as an example.
LD A
AND B
ST Q
Further Reading:
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 17 of 38
:
A Brief Instruction List Programming Tutorial
Functional Blocks
Basically, when the Pump and Pressure inputs give a HIGH reading, the end
output will be 1. OR it could be that only the Test input gave a HIGH reading.
Further Reading:
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 18 of 38
:
Functional Block Programming by Wisdom Jobs
Sequential Function charts, on the other hand, are just that–charts that
represent each function in a PLC control system in a sequential fashion.
Further Reading:
The most commonly used PLC programming language is the Ladder Logic
Diagram.
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 19 of 38
:
The reason for its popularity is that Relay Logic Diagrams were closely
resembled by the Ladder Logic Diagrams.
When the PLC was invented, designers found a way to use the existing
knowledge of the Relay Control System designers for programming the PLC.
Another reason is that the PLC programmers usually prefer to define the
actions in terms of contacts, which again was the most commonly used
control system before the PLC.
Since this is the most commonly used PLC programming language, this is
the one that you will learn in this mini-course.
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 20 of 38
:
Ladder Logic Programming
PLC Programming has never been easier for the original Relay Control
System designers, thanks to Ladder Logic.
Ladder Logic was derived from the Relay Logic Diagrams and hence uses
almost the same context.
The only difference is that because the PLC was very flexible in terms of the
Input and Output Devices, the symbols for the electrical devices are now
exempted from the actual program.
For Ladder Logic Programming, Inputs are Inputs, and Outputs are Outputs.
No need to memorize all the standard symbols for each separate device.
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 21 of 38
:
PLC Programming: Ladder Logic Diagram (Photo from PLCacademy)
The ladder logic diagram consists of two fundamental parts, which you can
see as the vertical and the horizontal lines. They are called, respectively,
the rails and the rungs.
Now, you may have noticed in the ladder logic diagram example above, there
are multiple inputs in the same rung. EXCEPT, they are not in series but
rather connected in a parallel fashion.
Back to the example, the two vertical rails represent the 24 Vdc source and
the other one the 0 Vdc terminal. They are power rails. What this means is
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 22 of 38
:
that for an output element (more on that later) to become powered up, you
have to connect the two rails together by finding a way to connect them via
your inputs.
To scan the program for continuity of rungs, the PLC uses a top to bottom,
left to right sequence, thus checking continuity between the two rails for
each scan.
Simply put, the devices on a rung must provide continuity from the left rail to
the right rail.
Notations
In PLC Programming there are some fundamental notations that you must
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 23 of 38
:
remember to create programs, and they are very simple. In fact, you have
already seen them in the example above but this time, you are going to learn
what those actually mean.
Two vertical bars represent an input device. It could be any input device
connected to a PLC hence the symbol does not change for ALL PLC devices
as it is the standard set by the IEC 61131.
There are two types of input device notations: one is the Normally Open
(NO) inputs, and one is the Normally Closed (NC) inputs. They are classified
that way because the Relay Logic has used the same principle in the Relay
Logic Diagrams. In fact, this was inspired by electromechanical relays
because they, too, can also be normally open or normally closed.
Normally open inputs are the ones that have the two vertical lines separated
by a space in between. In PLC ladder logic programs, they are usually
termed as “Make” inputs.
Normally open inputs, like normally open relays, do not by default create a
connection between the two rails when connected. When activated, only
then it will create the connection.
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 24 of 38
:
These inputs could be any input device or sensor that is used to
conditionally activate an output device.
Normally closed inputs are the ones that have the two vertical lines with a
forward slash that connects the two opposite ends.
In PLC ladder logic programs, they are usually termed as “Break” inputs and
are an equivalent of the NOT operation.
Normally closed inputs are most commonly used for STOP buttons or
emergency shut down devices.
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 25 of 38
:
PLC Programming: Output Device
Shown above is the notation for an output device in a PLC ladder logic
diagram. Again, this could be ANY output device that can be controlled by
the PLC: Motor starters, Lamps, Buzzers, Solenoid Valves.
These relays now only rely on the memory component of the PLC so instead
of actually using relays to create a connection point, the memory of the PLC
now only stores the states of the supposed relays.
Internal Relays
Internal relays are elements that hold data to serve as relays for the system.
This is what makes the PLC more cost-effective than the conventional relay
systems that were used before.
These internal relays rely in bits on the memory of the PLC but can be
treated the same way as an external relay (as what I’ve been saying since
earlier).
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 26 of 38
:
For example, using an internal relay in conjunction with a push button allows
you to turn on a solenoid valve in one rung and a motor in another rung using
the same push button.
Furthermore, conditions for logical operations such as AND, OR, or NOT may
be made using that same internal relay in a different rung.
Battery-Backed Relays
When the PLC is suddenly turned off, whether due to a power outage or
some connection breaks, the states of the internal relays become erased
automatically.
Because of this, when you start the PLC after that scenario, the states of the
internal relay will go back to the initial stage of the program rather than the
LAST state that it had before the power outage happened.
This is where battery backed relays come into play. They retain their state of
activation even when the power supply of the PLC is entirely off. Hence, they
are also called retentive coils.
Internal relays only retain their state if the input devices that are placed to
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 27 of 38
:
activate them are also retaining their activation states.
For set and reset relays, however, you can actually retain their state
indefinitely and then remove the state using another condition from an input
device.
Internal relays also make the PLC highly flexible because of the different
applications that extend the PLC’s capabilities.
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 28 of 38
:
PLC Programming: Multiple Input Conditions
In designing control systems, there are times when you would want more
than one condition to turn something ON or OFF.
In this situation, using the input device notation over and over again would
be impractical and messy as a ladder logic program. The rung would have
too many things on it!
Thus, the program above shows that there are two conditions that are
represented by an internal relay EACH.
Latching Programs
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 29 of 38
:
PLC Programming: Latching Programs
Input devices are usually momentary in nature, hence, for that scenario to
happen, Latching programs are required to be set up in the PLC
programming software.
One-Shot Operation
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 30 of 38
:
So far, we have talked about retaining the states of relays and actually doing
it even without power supplied to the PLC.
Now, this type of operation is used when you want just an output pulse that
does not retain its state all throughout the program. This function is termed
as one-shot.
One shot operation is momentary, hence pushing the trigger button will only
cause an impulse to the output device.
Master-Slave Operation
Master inputs are used when you want the whole program to be dependent
on a Master Control condition.
For instance, if you want the system to run ONLY when authorized personnel
has already examined the machine, a Master ON button must be switched
ON first.
It does not matter if the Slave START buttons were pushed over and over
again, because the system will not start without the Master ON button being
in an energized state.
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 31 of 38
:
Equivalent Ladder Diagrams for Logical Functions
AND
The AND condition is basically just two inputs in series with each other.
Because the inputs are in series, the two inputs must BOTH have continuity
in order for the output to turn on.
OR
PLC Programming OR
NOR
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 32 of 38
:
PLC Programming NOR
NAND
Similar to the NOR condition, the NAND condition is just a negated version
of the AND condition. Normally Open inputs are inverted.
XOR
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 33 of 38
:
The XOR condition has a different story than the rest of the logical
conditions. If you look at the Boolean equation for the XOR condition:
Therefore, to XOR the two variables A and B, you would have to perform
NOT, AND, and OR conditions to your ladder logic programs. This way, only
ONE input variable is allowed to control the output AT A TIME.
XNOR
For this one, notice that the ladder logic diagram has an internal relay
connected in a “break” manner in order to negate the result.
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 34 of 38
:
Before you start: PLC Safety Systems
In applying the PLC programming skills that you have learned throughout
this mini programming course, make sure that you familiarize yourself with
the different safety techniques that are most commonly used in control
systems!
Emergency stop buttons are essential in every control system because when
the output devices start malfunctioning, you can have control of the power
using the PLC by setting an emergency stop button.
Two-handed Start
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 35 of 38
:
The two handed start is a basic practice for machines that are hazardous to
operate due to the actuators’ short distance to the user. Usually, drilling
machines are controlled using this type of setup.
A sensor input is also used to ensure that an object that was expected to be
in the drilling platform is actually on the platform before the operator can
even start the drilling.
Proximity Detection
Lastly, proximity sensing is used as a safety measure when there are huge
machines that may impose risks because of some produced tiny projectiles
or even being caught by the machine itself.
This is used to ensure that the controlled machines would not cause any
harm when accidentally approached (if that is even a thing).
Conclusion
In doing PLC programming, there are plenty more combinations of programs
that you may be able to design using the knowledge that you have acquired
in this post. Your imagination is the limit!
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 36 of 38
:
Check out one of my other posts if you want more!
Search …
We created this website with the goal of helping YOU learn about the
basics of the Programmable Logic Controller.
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 37 of 38
:
Featured Posts
https://basicplc.com/plc-programming/ 21/04/2025, 8 25 AM
Page 38 of 38
: