5 Common PLC Programming Mistakes and How to Avoid Them

Learn five common PLC programming mistakes and how to avoid them.
PLC Programming mistakes - thumbnail
Listen to this article

PLC programming is one of the most popular skills among automation engineers. With this skill, automation engineers can communicate with PLCs and tell them how to interact with sensors and actuators on the factory floor. So, to be able to communicate with a PLC, you first need to know the language of PLCs and how to speak to them properly.

In this blog post, we’ll talk about five common PLC programming mistakes. We’ll also discuss how you can avoid these mistakes. This will help you feel more confident the next time you program or troubleshoot a PLC.

If you’re new to PLC programming and don’t know where to start, check out this blog post on How to Start Learning PLC Programming.

Now, let’s dive into the first common mistake that every PLC programmer might make.

Mistake 1: Programming without defining goals

Before you start writing any code, it's important to clearly understand the project goals and requirements. Many PLC programmers start programming without a clear picture of what the project is supposed to do. This often causes mistakes and wasted time. They may also miss key requirements, which could lead to expensive changes or downtime later.

How to avoid it

Before you start PLC programming, it’s important to know the exact purpose of the project. You can also refer to the Functional Design Specification (FDS), which outlines the expected behavior of the process. This gives you a clear overview of what your code should accomplish and helps you break the project into smaller, manageable tasks, making programming much easier.

Mistake 2: Poor naming and no comments

One of the common mistakes PLC programmers make is not considering good names for variables and functions and not using any comments. When this happens, it becomes harder to understand the PLC program, especially when you or someone else on your team wants to troubleshoot or update the code in the future. Without proper names and comments, it will be difficult for you or other team members to understand the logic behind your code.

How to avoid it

  • Use good names: Define clear, meaningful names for variables and functions.
  • Use comments: Add clear and easy-to-understand comments for variables and the complex parts of the code to explain exactly what they do in your program. This helps everyone understand what each part of the code does.

For example, take a look at the PLC program below. As you can see, we’ve added in to show that a variable is a hardware input, ou to indicate a hardware output, and var to signify it’s a local variable.

Documentation in plc programming

Also, you can see that we’ve added easy-to-understand commands to the variables and rungs of our PLC program.

By the way, the PLC program above is written in CODESYS. We’ve explained how this PLC program works in the Ladder Logic Best Practices blog post. If you want to learn more about programming in CODESYS, you can check out our course CODESYS 1: Introduction to PLC Programming.

Using good names and comments is essential if you want your PLC program to be easily understood and allow others to troubleshoot and update it without any issues.

Some people don’t add good names and comments on purpose. They do this to make sure they’re the only ones in the plant who know how the PLC program works. But what they don’t realize is that this will hurt their career in the long run. For example, if they leave the plant one day and someone else needs to troubleshoot or update the PLC program, it will be a challenge. And guess what? Everyone will know who wrote that messy PLC program. Don’t be that person.

Mistake 3: Overcomplicating logic

PLC programs can get messy when the logic is overcomplicated. Some PLC programmers try to make their code perfect by adding unnecessary conditions or features to their programs. Others write the entire program in one block. When this happens, you’ll end up with repetitive code in different parts of the program.

This slows down the system, makes the code harder to troubleshoot, and increases the chances of PLC programming errors.

How to avoid it

  • Write simple and clear logic: Breaking down tasks into smaller parts helps you program step-by-step and avoids complex programs.
  • Use modular code: To improve readability, you can use Functions and Function Blocks. This makes your code reusable and avoids repetition in your programming.
    For example, let’s say you are working on a PLC program for an industrial process, and as part of the code, you need to convert a temperature value in degrees Celsius to a value in degrees Fahrenheit several times. To do this, as you can see in the PLC program below, you can program a function that handles this conversion. Then, you can easily use this function whenever you need to convert Celsius to Fahrenheit in different parts of your PLC program.
Two ConvertTemp function blocks converting Celsius inputs to Fahrenheit outputs

If you want to learn how to use Functions and Function Blocks in your PLC program, check out our course Learn How to Use FCs and FBs for Programming Siemens PLCs.

  • Review your code regularly: The last thing you can do to avoid having an overcomplicated PLC program is to regularly review your code and remove any redundant code or overly complex conditions.

Mistake 4: Ignoring proper testing and simulation

One of the costliest mistakes in PLC programming is skipping testing with simulation and relying only on physical testing. Testing is crucial to ensure that your code works as expected under all conditions. After programming is done—or even at every step of programming—it’s better to test your logic in a simulated environment using simulators.

How to avoid it

Most PLC programming software comes with its own simulation environment that you can use to test your PLC programs. For example, if you’re programming a Siemens S7 PLC using TIA Portal, you can use PLCSIM as a simple but effective simulator to test your code.

You can also use more general-purpose 3D simulators like Factory I/O to test your program in a virtual environment.

3D simulators - Factory I/O

If you want to learn more about how to use PLCSIM and Factory I/O, you can check out our PLC Programming Made Easy course series, where you learn how to program a Siemens S7 PLC using TIA Portal.

You can also learn how to use Factory I/O with an Allen-Bradley Micro800 PLC in our PLC Programming From Scratch course series.

Just a heads up, using 3D simulators like Factory I/O works best for smaller PLC programs with digital inputs and outputs. If you're working on a PLC program with hundreds or thousands of inputs and outputs, most of which are analog, you're better off using the built-in simulator of the PLC you're working with.

The table below makes it easy for you to quickly identify popular PLC brands, their software, and corresponding simulators.

Table listing PLC brands, software (e.g., TIA Portal, Studio 5000), and simulators for automation programming

Testing the PLC program helps you avoid future failures in an industrial setting.

Mistake 5: Neglecting continuous learning

Some PLC programmers stick to their old knowledge and don’t upgrade themselves. However, the PLC programming field is always evolving. PLC brands and programming software frequently introduce updates and new features. If you stop learning, you might struggle to work with modern systems. Employers also value programmers who stay up-to-date with industry trends. Neglecting to learn could limit your opportunities for exciting projects.

How to avoid it

There are plenty of online courses, videos, and tutorials to help you stay up-to-date. At RealPars, we frequently publish new courses in PLC programming, which you can find by visiting realpars.com/courses and filtering by the skill path of PLC Programming.

To supplement your learning, you can also read technical blogs, join forums, and follow PLC-related social media channels to stay informed about the latest PLC programming technologies. If you’re a RealPars Member, you have access to the RealPars Community page, where you can ask questions and benefit from other PLC programmers’ experiences.

Conclusion

In this blog post, you learned about some of the most common PLC programming mistakes and how to avoid them. This will help you write better code and ultimately grow your career and earnings as an automation engineer or technician.

As a final note, if you're a plant manager and think your team could benefit from PLC programming training to reduce downtime, check out realpars.com/business and fill out the form. Our team will quickly get in touch to see how we can help your team develop their skills.

Join the Top 1% of Automation Engineers

Start Your 7-day Free Trial

Learn from Industry Experts

Start your learning journey today!
With a 7-day trial, then 25/month
Start Learning For Free