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.
How To 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:
Investing in PLC Programming Training Kits
Here are some fairly affordable and useful PLC training kits, readily available on Amazon, that you may want to consider investing in:
Allen Bradley Micro820 Programmable CCW PLC Trainer
- Allen Bradley (AB) PLC interface is also one of the most popular PLC brands used in various industries,
- Offers 20-point controllers, pretty versatile
- Embedded communications via non-isolated serial ports (for RS-232 and RS-485 ports) and also features Ethernet ports
- Provides embedded support for up to four 10k thermistor temperature inputs
- Supports program download through USB with an optional 3.5-in. Remote LCD
- Supports up to two Micro800™ Plug-in Modules
- Supports microSD™ card for program transfer, datalog, and recipe management
- Includes a student workbook, PowerPoint presentations, Instructor Guidebook, and instructions for Connected Components Software download
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.
SIEMENS S7 1200 PLC Trainer
- Very affordable, one of the cheapest ways to learn PLC programming with Siemens module.
- Siemens PLC is currently one of the most use PLC brands in various industries, and by learning PLC programming on this training kit, you will have an advantage when you work with other Siemens PLCs.
- Featuring SIMATIC programming software. This is a fairly popular programming software in the PLC world, and you will have a huge advantage later in your PLC programming career.
- Can connect to PROFIBUS, PROFINET, MODBUS, or a CANopen networking interface. Pretty versatile and scalable.
- SIMATIC basic panel (KTP) included in the package. These panels come in different sizes and can be programmed with WinCC programming software (included in the package).
Steps in Learning PLC Programming
In general, here are the common steps in learning PLC programming and developing operational programming:
- Install the PLC training kit module and the PLC programming software (as we’ve reviewed above.
- Choose between the 5 programming languages, but commonly we’ll start with Ladder Diagram (LD) language
- Start by understanding the input and output devices
- Check for the proper rungs and properly map these I/O tags (I/O mapping or addressing). Define which I/O tags would be normally open [NO] or normally closed [NC].
- Define other functions like timer and counter according to the project’s needs.
- Using logic gate, develop statements and sequences of the program
- Learn important PLC programming rules and implement it
- Connect the hardware and run the program
Below, we will discuss these steps and how you should approach them.
The Basics of PLC Programming
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:
- When there’s a guest, provide service
- When there’s no guest, do not provide service
So, the program will choose between taking path 1 or path 2, but not both.
Repetition or Iteration
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 Types and Data Structures
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|
|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|
|BCD||C#0 to C#999||L C#998|
|Decimal number unsigned||B#(0,0) to B#(255,255)||L B#(10,20)|
|DWORD (Double word)||32||Binary number||2#0 to 2#1111_1111_1111_1111_|
|Hexadecimal number||W#16#0000_0000 to W#16#FFFF_FFFF||L DW#16#00A2_1234|
|Decimal number unsigned||B#(0,0,0,0) to B#(255,255,255,255)||L B#(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
|S5TIME (SIMATIC time)||16||S7 time in steps of 10ms (default)||S5T#0H_0M_0S_10MS to|
|TIME (IEC time)||32||IEC time in steps of 1 ms, integer signed||T#24D_20H_31M_23S_648MS|
|DATE (IEC date)||16||IEC date in steps of 1 day||D#1990-1-1 to|
|TIME _OF_DAY (Time)||32||Time in steps of 1 ms||TOD#0:0:0.0 to|
|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:
- Bits: can either have 1 or 0 value with 1 usually represents ‘On’ and 0 usually represents ‘Off’. Bits are the most basic data type and are the building block for all other types of data.
- Integers: whole numbers without decimal points. Words, Characters (Char), Double Integer (DINT), and Double Word (DWORD) are technically Integers. Unsigned are always positive numbers, and signed can be positive or negative.
- Floating numbers: numbers with decimal points, also called REAL numbers. It can be positive or negative.
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’.
Understanding PLC Addresses and PLC Tags
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:
- If it uses data names, it is a “Tag-based” software
- If it uses addresses to refer to data, it is an “Address-based” software
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:
- What is a Programmable Logic Controller?
- PLC Programming and Ladder Logic Explained
- PLC Basics: The Ultimate Guide to PLC Programming
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:
- Input modules are represented by the ‘I” or ‘X’, for example in Siemens and AB PLC, the input is represented by ‘I’, while a Mistubishi PLC uses ‘X’
- Output modules are presented by ‘Q’ or ‘Y’. Siemens uses ‘Q’, while Mitsubishi uses ‘Y’, for example.
For example, in a Siemens PLC, the format of I/O mapping is as below:
File types Byte Number.Bit Number
- Input address: I0.0, I0.1, I0.2, I0.3,……. I0.7.
- Output Address: Q0.0, Q0.1, Q0.2, Q0.3,……. Q0.7.
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.
Logic Gates With PLC Programming (via Ladder Diagram)
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:
- NOT Gate
- AND Gate
- OR Gate
- NAND Gate
- NOR Gate
- EX-OR Gate
- EX-NOR Gate
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)|
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)|
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)|
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)|
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)|
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)|
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)|
Important Rules In PLC Programming
Signals, decisions, actions
All PLC control circuits feature three core parts: signals, decisions, and actions:
- Signal: starts or stops electrical current flow to the circuit. When the program provides ‘on’ statement, the current will be passed to the circuit, allowing it to operate
- Decision: using logic gates from multiple devices to determine what is going to be done by the device
- Action: based on the decision, an action is performed
Inputs can be used in series and parallel to form a connection
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.
Inputs can be used more than one time in a single program
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.
It is bad practice to use any output more than one time in a single program, except when performing set/rest and latch/unlatch functions
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.
Output addresses can be used as input address
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.
Input address cannot be used as output address
While the same input can be used multiple times and as multiple inputs, we cannot, in any way, use input addresses as output.
Output or load (working coil) connections
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.