There are four fundamental variable types in PLC programming: Boolean, Integer, Real, and String. This is a universal concept for all PLC programming but needs to be clarified due to the acronyms and various names used by manufacturers and PLC hardware.
Your controller programming manual will help you understand the terms of the variables in your hardware. It is essential to understand the different types of variables available to you, the programmer. We will explore each of the four variable types, breaking down what they are and how they are used in programming your controller. Let’s dive in!
Boolean (On / Off) PLC Variable
Boolean variables are the simplest type of variable. They are used when a variable needs to be in one of two states, often referred to as “true” or “false.” These states can also be referred to as “on” / “off” or “1” / “0”. Typically, a ladder logic program will include these Boolean variables called digital inputs, digital outputs, bits, bools, etc. You usually think of ladder logic programming when looking at Boolean variables.
We use discrete digital inputs and an output Boolean in this program example to create a start-stop circuit. Normally open and normally closed ladder logic contacts will take the Boolean variable as it is or inverse it. You can see that the stop bit is inversed in our example.
Boolean variables are also used as flags in programming to indicate whether or not a specific condition has occurred. For example, in a program to check if a variable is equal to a particular value, the variable’s flag may be set to “true” if the two values match or “false” if they don’t.
Integer (Number) PLC Variable
Integer variables are the second most common type of PLC variable. They represent numeric values and are usually stored as a 2-byte (16-bit) number. Usually called registers or words, these numbers can be 8, 16, or 32-bit. They can also be signed or unsigned, meaning that negative numbers are possible.
Our ladder logic example uses the increment and decrement instruction on a 16-bit integer called “Int.” Switch three will increment the register, and switch four will decrement the register.
Integers are typically used for all types of mathematical calculations, as well as for counting, timing, and other numerical measurements. They can also store negative numbers as well as huge numbers. If we call up the windows calculator on the computer, we can look at these integer values more closely.
Our standard calculator comes up as the default. Select the three lines (pancake) beside the standard name and select programmer.
This programming calculator will show us the bits (Binary) for the integer value we enter. The default is QWORD (64 Bit). Change this to double word (DWORD), which is 32-bit. Enter the value of 100,000 on the calculator. The hexadecimal, octal, and binary values will be displayed. Remember that these values are just representations of the integer number.
Real (Very Large or Small Number) PLC Variable
Real variables are a type of floating-point number and are typically used to represent numbers with fractional or decimal parts. They are usually stored as 4-byte (32-bit) numbers and can hold extensive ranges of numbers, both positive and negative. They are commonly used in programs that require high accuracies, such as programs that require calculations based on measurements of temperature, pressure, or other physical properties.
This example will convert degree C into degree F using the formula F = (9/5 X C) + 32.
20.2 C converts to 68.32 F.
String (Character) PLC Variable
The last type of variable is String variables, which store text or character data. They are typically stored as an array of bytes, allowing an unlimited number of characters. A byte is 8 bits which are 256 numbers. This will represent a character in the language. The most common use for String variables is in programs that need to interact with the user, such as programs that collect input from the user or provide output to the user. They can also be used for messages in PLCs that send emails.
In our example, if input 6 is on, then the ASCII string “Switch is on” is copied to the destination tag. If input 6 is off, the string “Switch is OFF” is copied.
Further information can be found in our post, What Everybody Ought to Know about PLC Numbering Systems. This will give more details about the variables used in PLC programming.
PLC programming uses various variable types to provide robust and detailed automation solutions. Understanding the different types of variables available, such as Boolean, Integer, Real, and String, is essential to use this technology effectively. By understanding the various capabilities of each variable, you, the programmer, can ensure that your programs are both robust and reliable.
Watch the video below to see the operation of the four fundamental PLC programming variables.
Free learning and training series for PLCs.
Click / Click PLUS (Koyo)
Omron CP1H Series
Horner XL4 Series
EasyPLC Software Suite – 3D training package
Purchase your copy of this learning package for less than USD 75 for a single computer install or less than USD 100 to allow different computers.
Receive 10% off the investment by typing in ACC in the comment section when you order. http://www.nirtec.com/index.php/purchase-price/
Learn PLC programming the easy way. Invest in yourself today.
C-More EA9 Series of HMI
(Webserver, FTP, Data Logging, Free Remote Apps, etc.)
Node-Red is a free IoT software hub that can communicate MQTT and many standard industrial protocols. This series will help you communicate to the PLC, create an HMI on any electronic device, log data to a database, and view the information on a spreadsheet for analysis.
Node-RED IoT enabling software
Watch on YouTube: Learn the 4 Basic Variable Types in PLC Programming
If you have any questions or need further information, don’t hesitate to contact me.
If you’re like most of my readers, you’re committed to learning about technology. Numbering systems used in PLCs are not challenging to learn and understand. We will walk through the numbering systems used in PLCs. This includes Bits, decimals, Hexadecimal, ASCII, and Floating points.
To get this free article, subscribe to my free email newsletter.
Use the information to inform other people how numbering systems work. Sign up now.
The ‘Robust Data Logging for Free’ eBook is also available for free download. The link is included when you subscribe to ACC Automation.