PLCs for Beginners

Book description

Unleash the power of PLCs by understanding and applying essential programming concepts such as structured text, programming logic, and technologies like ChatGPT

Key Features

  • Unleash the power of structured text by understanding its syntax, features, and applications
  • Harness the power of programming logic and design by taking a design-first approach to PLC programming
  • Leverage advanced concepts and technologies such as cybersecurity and generative AI with PLC
  • Purchase of the print or Kindle book includes a free PDF eBook

Book Description

As smart factories and advanced technology become more prevalent, the demand for PLC programmers with expertise beyond ladder logic is growing. This book introduces a new approach to PLC programming, preparing you for future challenges by exploring automation programming through computer science and text-based programming.

The book begins by exploring the basic components of PLCs and how they integrate with other modules, giving you a clear understanding of system functionality. As you progress, you'll delve into PLC program execution, learning about flow and essential components for effective programming. Next, you'll understand program design with pseudocode and flowcharts, vital for planning programs. You'll then explore Boolean logic intricacies, harnessing logical functions and truth tables for precise control statements. Later, you'll delve into structured text, gaining a comprehensive grasp of syntax and features crucial for efficient programming. The journey continues with a focus on advanced topics like cybersecurity in PLC systems and leveraging generative AI (GenAI), such as ChatGPT, to enhance productivity.

By the end of this book, you’ll be able to design real-world projects using pseudocode and flowcharts, and implement those designs in structured text.

What you will learn

  • Explore and understand how to implement PLC programs in structured text
  • Experiment with common functions in structured text
  • Control the flow of a PLC program with loop and conditional statements
  • Discover how to design a PLC program with pseudocode and flowcharts
  • Implement common sorting algorithms such as bubble sort and insertion sort, and understand concepts such as Big O
  • Understand the basics of cybersecurity to protect PLC-based systems
  • Leverage ChatGPT for PLC programming
  • Understand the basics of troubleshooting hardware and fixing common problems

Who this book is for

This book is for automation engineering students and individuals seeking entry-level knowledge of PLC programming with structured text and other modern computer science concepts to excel in the advanced automation landscape. No prior knowledge of PLC programming is required.

Table of contents

  1. PLCs for Beginners
  2. Contributors
  3. About the author
  4. About the reviewers
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Conventions used
    6. Get in touch
    7. Share Your Thoughts
    8. Download a free PDF copy of this book
  6. Part 1: Basics of Computer Science for PLC Programmers
  7. Chapter 1: Computer Science Versus Automation Programming
    1. Technical requirements
    2. What is computer science?
      1. Why study computer science?
    3. What is automation programming?
      1. What is a PLC?
    4. Exploring automation through computer science
      1. How does computer science help automation programmers?
    5. Why should automation programmers care?
      1. Cloud technologies
      2. The internet of things
      3. Machine learning
      4. What does this mean for automation engineering?
    6. PLCs versus microcontrollers
      1. What are microcontrollers?
      2. Surface-level differences
      3. PLC and microcontroller programming languages
      4. Use cases
    7. PLC versus computers
      1. What is a computer?
      2. PLC versus computers
    8. Summary
    9. Questions
  8. Chapter 2: PLC Components – Integrating PLCs with Other Modules
    1. Technical requirements
    2. PLC types
    3. Common PLC modules
      1. Power supply
      2. Chassis
      3. CPU modules
      4. I/O modules
      5. Safety modules
    4. Sinking versus sourcing
      1. NPN versus PNP
    5. Sensors
    6. Motors and motor controls
      1. What is a motor?
      2. Open and closed-loop control systems
      3. Stepper motors
      4. Servo motors
      5. Encoders
      6. Motor drives
    7. Communication protocols
      1. What is a communication protocol, and what is it used for?
    8. Wiring diagrams
    9. Final project
      1. Specs
      2. BOM
    10. Summary
    11. Questions
    12. Further reading
  9. Chapter 3: The Basics of Programming
    1. Technical requirements
    2. Understanding what a program is
      1. What is the purpose of a program?
      2. Why use software over hardware?
      3. How to view software and hardware in a system
      4. Software is not a cure-all solution
    3. Understanding programming languages
      1. Syntax
      2. Translators
      3. Machine instruction
      4. Language paradigms
    4. Keywords
      1. Dos and don’ts of learning keywords and syntax
    5. Program flow
      1. Program iteration
    6. Exploring the IEC 61131-3 standard
      1. IEC 61131-3 pitfalls
    7. Final project
      1. Strategy
    8. Summary
    9. Further reading
    10. Questions
  10. Chapter 4: Unleashing Computer Memory
    1. Technical requirements
    2. What is memory?
      1. Memory
      2. Storage
    3. How computer/PLC memory and storage work
      1. HDDs
      2. SSDs
    4. Volatile versus non-volatile memory
      1. Volatile memory
      2. Non-volatile memory
    5. Memory addresses
      1. How memory works
      2. Computer memory – an analogy
    6. Common storage devices
      1. USB drives
      2. External hard-drives
      3. SD cards
      4. Cloud storage
      5. Obsolete storage devices
      6. Floppy drives
    7. Summary
    8. Questions
    9. Further reading
  11. Chapter 5: Designing Programs – Unleashing Pseudocode and Flowcharts
    1. Technical requirements
    2. What are pseudocode programs and flowcharts?
      1. Pseudocode
      2. What does pseudocode look like?
      3. Flowcharting
      4. What do flowcharts look like?
    3. Why use pseudocode and flowcharts in PLC programming?
      1. Why use pseudocode?
      2. Why use flowcharting?
      3. When to use one over the other?
    4. Tools needed for flowcharts and pseudocode
      1. Pseudocode tools
      2. Flowchart tools
      3. Whiteboarding
    5. Design exercises
      1. The quadradic equation
      2. The beer program
    6. Final project – Robot startup system
      1. Design requirements
      2. Design logic
      3. Wait sequence
      4. Pseudocode
      5. Flowchart
    7. Summary
    8. Questions
  12. Chapter 6: Boolean Algebra
    1. Technical requirements
    2. What is Boolean algebra?
    3. Boolean operators
      1. The basic operators
      2. The OR operator
      3. The NOT operator
    4. Boolean expressions
      1. Exploring NOT
      2. The OR operator
      3. The AND operator
      4. Operator laws
      5. Idempotent law
    5. Solving Boolean equations
      1. Examples
    6. Getting to know truth tables
      1. Basic operators
    7. Final project: Creating custom truth tables from scratch
      1. Row 1
      2. Row 2
      3. Row 3
      4. Row 4
      5. Final truth table
    8. Summary
    9. Questions
    10. Further reading
  13. Part 2: Introduction to Structured Text Programming
  14. Chapter 7: Unlocking the Power of ST
    1. Technical requirements
    2. What is ST?
      1. Area of a circle program in ST
    3. Why is ST important?
    4. ST versus LL
      1. Example 1 – The area of a circle program – LL
      2. Example 2 – Toggling a light
    5. What is CODESYS?
    6. Installing CODESYS
      1. A CODESYS exploration
      2. Exploring the PLC_PRG file
    7. The final project – Hello World
      1. Step 1 – Creating a new project!
      2. Step 2 – Code implementation
      3. Step 3 – Running the program!
    8. Chapter challenge
    9. Summary
    10. Further reading
    11. Questions
  15. Chapter 8: Exploring Variables and Tags
    1. Technical requirements
    2. What are variables/tags?
      1. Applications of variables
    3. Variables/tags under the hood
      1. Why use variables?
    4. Data types
      1. What is a data type?
    5. The IEC 61131-3 data types
      1. Bits and bytes
      2. Common data types
    6. How to declare variables
      1. Variable section of a file
      2. Declaring a variable
      3. Initializing a variable
    7. Variable naming
      1. Rules to naming a variable
      2. Naming conventions
    8. Final project – declare the variables of a triangle
      1. Code implementation
      2. Challenge – declare the variable for a rectangle’s perimeter
    9. Summary
    10. Further reading
    11. Questions
  16. Chapter 9: Performing Calculations in Structured Text
    1. Technical requirements
    2. Math in ST
    3. Assigning numbers
    4. Basic calculations
      1. Solution variable
      2. The four basic functions
      3. Basic operation demonstration
    5. Complex mathematical functions
      1. Square root function
      2. Exponent function
      3. ABS function
    6. Trigonometric functions
      1. Arc functions
    7. Order of operations for math calculations
    8. Computing complex equations
      1. Distance between two points
    9. Final projects
      1. Final project 1 – programming the perimeter of a rectangle
      2. Final project 2 – Pythagorean theorem
    10. Summary
    11. Questions
    12. Further reading
  17. Chapter 10: Unleashing Built-In Function Blocks
    1. Technical requirements
    2. What are prebuilt function blocks?
      1. Functions, function blocks, and keywords
    3. Function blocks under the hood
      1. What is a function block?
    4. Rising and falling edges
    5. Common PLC function blocks
      1. Counter function blocks
      2. Timer function blocks
    6. Final project
      1. Variables
    7. Summary
    8. Questions
    9. Further reading
  18. Chapter 11: Unlocking the Power of Flow Control
    1. Technical requirements
    2. Exploring what flow control is
    3. Exploring why flow control is important
    4. Exploring logical expressions
    5. Exploring the IF statement
      1. IF statement syntax
      2. Checking if two values are the same!
      3. Exploring the not equals operator
    6. Designing control statements
      1. Overdraft program
    7. Exploring the CASE statement
      1. State machines and CASE statements
      2. Implementing the state machine
      3. Flowcharting and CASE statements
      4. Real-world applications for the CASE statement
    8. Final project
      1. Requirements
      2. Program design
      3. Code implementation
      4. Final challenge
    9. Summary
    10. Questions
  19. Chapter 12: Unlocking Advanced Control Statements
    1. Technical requirements
    2. Nested control statements
    3. ELSE statements
    4. ELSIF statements
      1. Challenge
    5. Logical operators
      1. Exploring the OR operator
      2. Exploring the XOR operator
      3. Exploring the NOT operator
    6. Final project
      1. Requirements
      2. Variables
      3. Color and shape sorter logic
      4. Testing conditions
    7. Summary
    8. Further reading
    9. Questions
  20. Chapter 13: Implementing Tight Loops
    1. Technical requirements
    2. Exploring the different types of loops
      1. Counter loop
      2. Precheck loops
      3. Post check loops
      4. Infinite loops
    3. Exploring loops in pseudocode and flowcharts
      1. Exploring loops with pseudocode
      2. Representing a loop in a flowchart
    4. Implementing a FOR loop
      1. Implementing the WHILE loop
      2. Exploring the REPEAT loop
      3. Exporting the EXIT keyword
    5. Understanding nested loops
      1. Challenge – creating a behavior report
    6. Final project
      1. Design
      2. Code implementation
      3. Testing the program
    7. Summary
    8. Questions
    9. Further reading
  21. Part 3: Algorithms, AI, Security, and More
  22. Chapter 14: Sorting with Loops
    1. Technical requirements
    2. How to use this chapter
    3. What is sorting?
    4. Exploring what arrays are and how to use them!
      1. What is an array?
      2. Array elements
      3. Initializing an array
      4. Retrieving the number of elements in an array
      5. Why are arrays important for sorting algorithms?
    5. Exploring sorting algorithms
      1. What is an algorithm?
      2. What is a sorting algorithm?
    6. Algorithm efficiency metrics
      1. Exploring the Big O notation
      2. Exploring the Big Ω notation
    7. Common sorting algorithms
      1. Exploring bubble sort
      2. Exploring insertion sort
      3. Challenge – Merge sort
    8. Final project – cement bag sorter
      1. Requirements
      2. Analysis
      3. Implementation
    9. Summary
    10. Questions
    11. Further reading
  23. Chapter 15: Secure PLC Programming – Stopping Cyberthreats
    1. Technical requirements
    2. What cybersecurity is and why it’s important
    3. The basics of cybersecurity
      1. Vulnerabilities, threats, and risk
      2. Threat actors
      3. Exploring AAA
      4. Air-gapped systems
    4. Common cyberattacks
      1. Exploring information gathering
      2. Exploring social engineering
      3. Exploring password hacking
      4. Malware
    5. Attack prevention methods
      1. Stopping social engineering
      2. Defending against password crackers
      3. Password length
      4. Malware defense
    6. Final project – a PLC-based activation system
      1. Design
    7. Certifications
    8. Summary
    9. Questions
    10. Further reading
  24. Chapter 16: Troubleshooting PLCs – Fixing Issues
    1. Technical requirements
    2. Common causes of PLC issues
      1. Broken software
      2. Exploring environmental issues
      3. Understanding non-environmental issues
    3. Common hardware issues
      1. Exploring power supply issues
      2. Common PLC problems
      3. Bad batteries
    4. Exploring troubleshooting techniques
      1. The PLC toolkit
      2. Diagnosing power supply issues
      3. Diagnosing temperature issues
      4. Diagnosing networks
      5. Troubleshooting software
      6. The basics of troubleshooting software
    5. Final project
      1. Troubleshooting
    6. Summary
    7. Questions
  25. Chapter 17: Leveraging Artificial Intelligence (AI)
    1. Technical requirements
    2. What is GenAI?
      1. What is AI?
    3. What GenAI can’t do
    4. Reasonable expectations with GenAI
      1. What not to expect with GenAI
      2. What to expect when using GenAI
    5. The basics of prompt engineering
      1. Creating a prompt
    6. Producing workable code with ChatGPT
    7. Final project
      1. Prompt and code
    8. Summary
    9. Questions
    10. Further reading
  26. Chapter 18: The Final Project – Programming a Simulated Robot
    1. Technical requirements
    2. Project scope
    3. Project requirements
    4. Flowchart for the system
    5. Designing the pseudocode
    6. Implementing the program
      1. Using ChatGPT to implement bubble sort
      2. Final project variables
      3. Main program logic
      4. Testing the program
    7. Summary
  27. Assessments
    1. Chapter 1
    2. Chapter 2
    3. Chapter 3
    4. Chapter 4
    5. Chapter 5
    6. Chapter 6
    7. Chapter 7
    8. Chapter 8
    9. Chapter 9
    10. Chapter 10
    11. Chapter 11
    12. Chapter 12
    13. Chapter 13
    14. Chapter 14
    15. Chapter 15
    16. Chapter 16
    17. Chapter 17
  28. Index
    1. Why subscribe?
  29. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts
    3. Download a free PDF copy of this book

Product information

  • Title: PLCs for Beginners
  • Author(s): M. T. White
  • Release date: May 2024
  • Publisher(s): Packt Publishing
  • ISBN: 9781803230931