PLC or Programmable Logic Controller can be found in various automated manufacturing processes and has been the standard of the automation industry for years.
In general, whenever there’s a need to control devices, you may need a PLC: from robotic machines to pneumatic machines to even traffic lights, the PLCs might find their home. Simply put, the PLC is a very important and iconic component in various industries with pretty versatile functionalities and responsibilities.
With that being said, learning PLC programming is a very valuable asset for any programmers and software developers, and here, we will discuss all the ins and outs about how to get started and learn PLC programming.
Here at PLCGurus.NET, we are aimed at providing FREE resources for you to learn everything about PLC programming, and you might also want to subscribe to our YouTube Channel for more of our tutorials and information.
With that being said, one of the key obstacles in learning PLC programming is that you’d need to own—or at least gain access to—a PLC hardware. Also, you might need to invest in additional software. There are certainly various resources that can help you learn PLC programming (see our article: 5 Essential Tools Every PLC Programmer Needs).
However, you won’t learn effectively unless you try programming an actual PLC and put all these theories into practice. That said, there are some affordable and accessible training kits available in the market today, and here are our recommendations:
Here are some fairly affordable and useful PLC training kits, readily available on Amazon, that you may want to consider investing in:
Key Features:
Our Verdict:A great investment if you want to learn Allen-Bradley PLC platform (which by far has the greatest market share in North America). A great training kit that will enable you to learn various aspects of PLC programming, including, PLC configurations, communication, I/O mapping, addressing, and even physical installation and wiring.
It’s a pretty complete package, and should help you understand, install, and troubleshoot AB PLC control systems. This modest invest can provide an huge boost to your PLC programming career.
Key Features:
In general, here are the common steps in learning PLC programming and developing operational programming:
Below, we will discuss these steps and how you should approach them.
A “program” is a set of instructions that the computer executes. Programming construct, on the other hand, handles the order these instructions would be executed and also used to control the flow in which these instructions are (or are not) executed.
In programming languages, there are several recognized basic programming constructs, which can be classified into three categories: Sequence, Selection, and Repetition (or sometimes called Iterations. They are sometimes referred to as “tiers” or “floors” so Sequences are called “First Floor/Tier” and Repetition is “Third Floor/Tier”.
Sometimes routine invocation is added as the Fourth Floor/Tier, but for the sake of this guide, we’ll focus on the first three constructs:
In the first tier of the construct, a sequence essentially tells a CPU which statement is to be executed next. In programming languages, a statement or programming statement is an expression that translates into an instruction.
By default, a sequence is a statement that follows the current statement (or the first statement of the program, depending on when it’s written). So, the sequence construct determines the order in which instructions occur and are executed/processed.
The sequence is the most basic construct in a programming language.
Selection determines which path a program takes, or the program flow. As the name suggests, the selection statement provides the ability to select between alternative path options for instruction execution.
A program can take many possible paths depending on various factors, and a selection statement instructs the program on which path to take.
Let’s use an illustration to further describe the selection construct: let’s assume there’s a restaurant. If at least one guest is present in the restaurant, then an employee should serve the guest. Otherwise, no service is necessary.
With this example, there are two possible paths:
So, the program will choose between taking path 1 or path 2, but not both.
A repetition construct, or sometimes called iteration, is a repeated execution of the code (or a section of the code) when a program is running. We can further divide these repetitions into two types: count-controlled repetition and condition-controlled repetition.
Let’s use the same example to illustrate repetition: since we’ve defined the condition of when service should be provided (when there’s a guest), we can repeat the same process for a full month.
As we can see, we can move between the constructs to form a basic programming concept: in the first floor/tier, we have a basic flow, statement after statement. Then, we use this statement to perform or not perform service based on whether a guest is present.
On the last (third) tier, we repeat this process for 30 days (a month).
Data is classified into various different types of data that an object or variable can contain (or hold) in a program. In all programming languages, data types are very important: before we develop any program or software, data types must be assigned and applied properly to ensure an error-free program with the right outcomes.
Below, we will discuss the data types in PLC programming, along with their structures:
Data Type | Size | Format Options | Range and Number Notation (lowest to highest values) | Statement List (STL) Example |
BOOL (Bit) | 1 | Boolean text | TRUE/FALSE | TRUE |
BYTE (Byte) | 8 | Hexadecimal number | B#16#0 to B#16#FF | L B#16#10 L byte#16#10 |
WORD (Word) | 16 | Binary number | 2#0 to 2#1111_1111_1111_1111 | L 2#0001_0000_0000_0000 |
Hexadecimal number | W#16#0 to W#16#FFFF | L W#16#1000 L word#16#1000 | ||
BCD | C#0 to C#999 | L C#998 | ||
Decimal number unsigned | B#(0,0) to B#(255,255) | L B#(10,20) L byte#(10,20) | ||
DWORD (Double word) | 32 | Binary number | 2#0 to 2#1111_1111_1111_1111_ 1111_1111_1111_1111 | L 2#1000_0001_0001_1000_ 1011_1011_0111_1111 |
Hexadecimal number | W#16#0000_0000 to W#16#FFFF_FFFF | L DW#16#00A2_1234 L dword#16#00A2_1234 | ||
Decimal number unsigned | B#(0,0,0,0) to B#(255,255,255,255) | L B#(1, 14, 100, 120) L byte#(1,14,100,120) | ||
INT (Integer) | 16 | Decimal number signed | -32768 to 32767 | L 101 |
DINT (Double integer) | 32 | Decimal number signed | L#-2147483648 to L#2147483647 | L L#101 |
REAL (Floating-point number) | 32 | IEEE Floating-point number | Upper limit +/-3.402823e+38 Lower limit +/-1.175495e-38 | L 1.234567e+13 |
S5TIME (SIMATIC time) | 16 | S7 time in steps of 10ms (default) | S5T#0H_0M_0S_10MS to S5T#2H_46M_30S_0MS and S5T#0H_0M_0S_0MS | L S5T#0H_1M_0S_0MS L S5TIME#0H_1H_1M_0S_0MS |
TIME (IEC time) | 32 | IEC time in steps of 1 ms, integer signed | T#24D_20H_31M_23S_648MS to T#24D_20H_31M_23S_647MS | L T#0D_1H_1M_0S_0MS L TIME#0D_1H_1M_0S_0MS |
DATE (IEC date) | 16 | IEC date in steps of 1 day | D#1990-1-1 to D#2168-12-31 | L D#1996-3-15 L DATE#1996-3-15 |
TIME _OF_DAY (Time) | 32 | Time in steps of 1 ms | TOD#0:0:0.0 to TOD#23:59:59.999 | L TOD#1:10:3.3 L TIME_OF_DAY#1:10:3.3 |
CHAR (Character) | 8 | ASCII characters | A’, ‘B’ etc. | L ‘E’ |
Understanding data types in PLC programming is very important, if not essential. Different PLC data types come in different sizes and hold different kinds of data:
As discussed above, all data types are made of bits, 1’s, and 0’s. If a data length is, for example, 8 bit, then it is written as xxxxxxxx, where any of the X’s can be either a 0 or a 1.
So, for example, it can be 11001100, 11111111, 00000000, or any other possible combinations. The data types (as discussed above) will determine what these bits mean for the PLC module.
For example, if the data type is an unsigned integer, the least valuable bit is the rightmost and would double in value as you move left. A ‘1’ in the rightmost bit is worth 1, then moving to the left a ‘1’ is worth 2,4,8,16,42,and finally 128.
So, a 00000000 in an unsigned integer is 0 while a 11111111 is 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255.
Some PLC programming software also prefers hexadecimal format (HEX), which will group sets of 4 bits together instead of writing all bits.
However, each of these ‘groups’ will contain 16 (0-15) possible values, which causes a problem since we only have 10 possible numbers (0-9). So, we also use A, B, C, D, E, and F to get all these 16 values (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F).
For example, 9 in HEX represents 1001, and 1111 would be ‘F’.
The PLC memory contains registers that are stacked side-by-side. Each of these locations has an Address so the PLC module can properly find data and instructions contained in the registers.
In older PLC programming languages and software, you’d need to ‘call’ these addresses when referring to the contained data. For example, if a data is contained in the 1004th register, you’d need to call “x1004”.
However, newer software allows us to directly name a piece of data (i.e. “restaurantGuest”, and when we call this data, the PLC module can keep track of where the register containing this data is located. We call this process “tagging”.
So, based on this, we can differentiate different PLC software into two types:
Lately, there are also modules and software that are basically Address-based, but also allow us to ‘name’ the addresses with nicknames or other similar approaches.
Tag-based software, however, is the superior choice especially with bigger programs where remembering what’s contained in the thousands of registers can be very difficult.
One of the first tasks in any PLC programming is to properly map or address the program’s inputs and outputs. The programmer must contain all the primary I/O tags within the program, so they can manipulate these input and output tags as needed.
For example, during a hardware failure, we’d need to manipulate the respective input/output to allow repairs, and we’d also need to do this during a system upgrade or expansion.
The process of mapping or addressing input and output tags is called IO mapping (or IO addressing/IO buffering).
In PLC programming, the simplest way to map input and output tags is to create a specific routine which should contain the I/O, and we can set them through OTE (OuTput Energize) instructions.
We’ve done several comprehensive guides that cover beginner to advanced topics of PLCs and PLC Programming in greater detail. You can view some of them here at:
The basic principle is that each input module with its input tags must be mapped to internal PLC tags, as well with each output tag coming out from the PLC. This will vary depending on your PLC module, however:
For example, in a Siemens PLC, the format of I/O mapping is as below:
File types Byte Number.Bit Number
So:
Using these basic principles, you should be able to properly map input and output tags in any PLC brands.
Another important step is to choose normally open [NO] or normally close [NC] state of the I/O contact depending on the project’s needs.
First, there are 5 PLC programming languages as defined by the IEC 61131-3 standard: ladder diagram (LD), function block diagram (FBD), structured text (ST), instruction list (IL) and sequential function chart (SFC).
The ladder diagram is the most basic of them all, and so we will discuss it here. If you want to learn further about the other languages, you might want to check our dedicated guide on PLC programming languages here.
In PLC programming with ladder diagram, there are seven different types of logic gates:
Below, we will explain each of them according to common PLC implementation:
Also called buffer or inverter, it takes one input and will produce an inversed output. When the input is 1 then the output is 0 and vice versa. In the case of a PLC ladder, when a button (to provide input) is pressed, then the output is on.
Input (I1) | Output (Q1) |
0 | 1 |
1 | 0 |
An AND gate involves two inputs, and when both inputs are high, then the output will be high, if only one input is high, then the output will be low.
Input (I1) | Input (I2) | Output (Q1) |
0 | 0 | 0 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 1 |
If both inputs are low, the output will be low. For any other states, the output will be high.
Input (I1) | Input (I2) | Output (Q1) |
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 1 |
NAND, or not AND gate is technically an AND gate followed by a NOT gate The output will be ‘0’ when bot inputs are ‘1’, for all the other cases, the output will be ‘1’.
Input (I1) | Input (I2) | Output (Q1) |
0 | 0 | 1 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
NOR gate, or not OR, in an OR gate followed by NOT gate.
When both inputs are 0, then the output will be 1. On the other hand, when both inputs are 1, then the output will be 0.
Input (I1) | Input (I2) | Output (Q1) |
0 | 0 | 1 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 0 |
If both inputs are either 1 or 0, then the output will be 0. For any other state, the output is 1.
Input (I1) | Input (I2) | Output (Q1) |
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
When both inputs are 1 or 0, then the output will be 1. When the inputs are different, then the output is 0.
Input (I1) | Input (I2) | Output (Q1) |
0 | 0 | 1 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 1 |
All PLC control circuits feature three core parts: signals, decisions, and actions:
The number of inputs and outputs in a PLC system can link in both series or parallel connection. Typically in a ladder diagram, we use AND gate with series connections and OR gate for parallel connections. This is important since sometimes we’ll need two or more input systems to regulate a working coil. Refer back to the logic gate section above for possible input combinations.
A single input can be used repeatedly in the same program to control different outputs according to the project’s needs. With this feature, we can trigger several outputs simultaneously with a single input.
When we perform a set/rest function the same output address is utilized for obvious reasons and based on the rule above, we can either connect it to the same or different inputs. A latch/unlatch option is technically similar to a set/reset function but typically uses two inputs, one of them is normally opened (NO) and the other input is normally closed (NC). Latch/unlatch is typically used in the cycling process.
An important rule is that an output can be used as an input address, which is useful in a cycling process (for example, when a process is repeated continuously). We can, for example, use a latch/unlatch function based on an output coil so it performs as the input coil.
While the same input can be used multiple times and as multiple inputs, we cannot, in any way, use input addresses as output.
Load devices (i.e. working coil, lights, etc. ) must be powered by their full rated voltage to operate properly, and multiple loads must be placed in parallel. Placing multiple loads in parallel is to ensure all of them to receive full voltage.
That’s it! We’ve shared the basic things you’d need to learn to start learning about PLC programming. However, our advice is to invest in a training kit (as we’ve recommended above) and start building a small project to practice.
Practicing will help you to learn and implement all of these basics, while at the same time you can get real practical experience and knowledge.
Every electrician, mechanic, and even DIY enthusiast needs a good tap and die set in…
A distributed control system, or DCS, is essentially a control system where the control elements…
A precision screwdriver, is a screwdriver that is designed with more emphasis on precision and…
What does SCADA stand for? SCADA stands for Supervisory Control And Data Acquisition. What Is…
Electrical enclosures have different NEMA ratings and specifications. The primary objective of NEMA enclosure ratings…
Before the invention of the steam boiler, humans relied on coal fires and the burning…
This website uses cookies.