MEE440 - INDUSTRIAL AUTOMATION
INTRODUCTION TO PLC
DR. NAİL AKÇURA
nail.akcura@ikc.edu.tr
Auxiliary Sources (recommended to be inspected before the weekly course)
PLC Basics | Programmable Logic Controller
https://www.youtube.com/watch?v=PbAGl_mv5XI
What is Ladder Logic?
https://www.youtube.com/watch?v=qaI48NCUvkA
How to Convert a Basic Wiring Diagram to a PLC Program
https://www.youtube.com/watch?v=snu8JNM-J1A
PLC Timer Programming for Beginners
https://www.youtube.com/watch?v=BHbOXDt5O3o
PLC Counter Programming for Beginners
https://www.youtube.com/watch?v=euFbTdFvAiI
Delta PLC WPL.Soft Mühürleme ve SET/RESET uygulaması.
https://www.youtube.com/watch?v=rYnlMAuIfMY
PLCs
PLC vs Classical Automation System
Classical industrial automation system
1. Auxiliary devices (such as time relays, hour meters, counters, auxiliary
relays, etc.) that constitute the basic electrical components of the
automation and are mounted in an electrical enclosure.
2. Design of the overall automation electrical circuit that has to achieve
the desired operation of the controlled process.
3. Wiring that is needed inside the electrical enclosure for connecting
the auxiliary devices between them and also with the I/O devices • First 3 cases are embedded in the
existing in the enclosure. operation and programming of PLC
4. Wiring that is needed for connecting the electrical enclosure with the • The last case still remains in classical
I/O devices as a whole, existing far from the enclosure. Input devices automation system
may be photoelectric switches, proximity switches, selector switches,
etc., while output devices may be motors, electrovalve coils, other
actuators, indication lights, etc.
Popular PLC brands
1. ABB
2. Allen-Bradley
3. Siemens
4. Honeywell
5. Mitsubishi
6. Yokogawa
7. Toshiba
8. General Electric
9. Omron
10.Schneider Automation
11.Reliance
12.Hitachi
13.Modicon/Gould
14.AutomationDirect/PLC Direct/Koyo
15.Cutler Hammer
Control types
Programmable
Electrical
Controllers
Hardware Software
control control
Hard-wired Alterable Alterable Free
Program Program Program Program
•Cabling •Switch •ROM •RAM
•Locking relay •PROM •EEPROM
•EPROM
Internal structure of a PLC
A basic PLC module
Operating Modes for S7-200 (can be changed with PLC
brand, consult your PLC brand manual)
STOP Mode:
• Stops execution of the program.
RUN Mode:
• Setting the mode switch to RUN mode starts the
execution of the program
Also, other modes with other versions or brands, these
modes can be included:
ONLINE Mode, MONITOR Mode, TEST Mode (hardware,
self-loopback, internal self-loopback, etc), etc
Program scanning Start
Reset output memory
X0 X1 Xn
......
Input Scan inputs and register signal
states in operation registers
Processor Status
Register PLC-program
•Input 1st step
•Output :
•Auxiliaty relay Nth step
•Data memory
Relay output states to
Output physical output relays
......
Y0 Y1 Yn
Input/Output connections PLC
X4 T1 Y0
X0
Y0
Y1
Output
X1 Y0
relay
Y2
X2
Y0 X4 K30
Y3
X3 T1
Timer Y4
X4 relay
Y5
X5
~
Digital Input Output
(Virtual Coil) Switch
S/S COM
Input step Internal Sequence Output step
External switch state (OPEN/CLOSED) Sequence is run OPEN/CLOSED state is External load is run
by input switch relayed to output relays
Software structure
POU: The term Program Organizational Unit (POU) is used for all programming objects (programs, function
blocks, functions, etc.) which are used to create a controller application.
• A POU is a program, a function block, or a function.
TASK: Tells your application to run a set of POUs or gather IO data.
• It is the smallest executable program unit.
• Reduces CPU Unit cycle time.
Instance: Responsible for binding a Task and a Program.
Function Block: The blocks executing specified or programmed functions.
Task >> Main (PRG) >> Sub (PRG) >> Area_1 (FB) >> Function (FB)
Software structure
instance
• Programs can be called by tasks.
• Function blocks can be called by programs or by other function blocks.
• Functions can be invoked by any POU type
Software structure
• It only runs one task at a time.
• The priority decides which one to run the
task first.
• The task is completed even if the other
tasks interrupts.
Software structure
IEC 61131-3
• IEC 61131-3 is the third part (of 10) of the open international standard IEC
61131 for programmable logic controllers. It was first published in December 1993 by the IEC; the
current (third) edition was published in February 2013. (IEC: International Electrotechnical
Commission)
• Part 3 of IEC 61131 deals with basic software architecture and programming languages of the
control program within PLC.
• It defines programming languages, data types, variables, configuration, program organization unit,
resources, tasks, object oriented programming (OOP).
Variable data types (main)
Variable type Description
BOOL Digital Data (True / False)
BYTE Numerical Data / Bitwise Data (0 - 255)
INT Numerical Data (-32768 - 32767)
UINT Numerical Data (0 - 65535)
SINT Numerical Data (-128 - 127)
USINT Numerical Data (0 - 255)
DINT Numerical Data (-2147483648 - 2147483647)
WORD Numerical Data / Bitwise Data (0 - 65535)
DWORD Numerical Data / Bitwise Data (0 - 4294967295)
REAL Numerical Data (-3.402823e+38 - 3.402823e+38)
ARRAY Array of Any Data type (Declared as "ARRAY [0..10] OF DataType)
Variable data types (optional, especially with 64bit PLCs and
Runtimes and in used in advanced programming)
Variable type Description
LWORD Numerical Data / Bitwise Data (0 - 18446744073709551615)
UDINT Numerical Data (0 - 4294967295)
LINT Numerical Data ( -9,223,372,036,854,775,808 -
9,223,372,036,854,775,807)
ULINT Numerical Data (0 - 18446744073709551615)
VARIANT Object (Anything)
NULL Object (Nothing)
Variable attributes
Variable type Description
CONSTANT Variable that is hard coded and cannot be changed at runtime
RETAIN Variable that remembers its last value between loss of power supply to the PLC.
Most PLCs have a limit on the maximum amount of data that can be retained.
Older PLCs may retain everything by default or have special ranges of registers
that are retained, so make sure you check.
PERSISTENT A variable that retains it's last value even after a re-initialisation of the PLC or
the PLC is warm started. The only way to reload the default data is to cold start
the PLC or perform a full download. Note: Persistent variables can be dangerous
if used incorrectly, especially if indirect addressing / pointers are being used.
Cold Start: Cold start refers to starting the CPU from power off, current configuration is discarded, and program
processing begins again with the initial values.
Warm Start: Warm start refers to restarting the CPU without turning the power off, Program processing starts
once again where Retentive data is retained.
Interface
An interface is the declaration of variables a PRG, FB or FC is expecting to use. There are a few keywords
that can be used to declare interfaces:
Name Description
VAR_INPUT Data passed into the POU
VAR_OUTPUT Data passed out of the POU
VAR_IN_OUT Data that is passed in and out of the POU to the same variable (If you know a
bit about computer programming, think of this as passing by reference)
VAR Data that is local to the POU, Some PLCs allow access to the data by explicit
reference only (For example, "POU.VARIABLE")
VAR_STATIC The same as VAR, but does not allow access to the data from outside the block
VAR_TEMP Temporary data, the values stored in TEMPs is lost when the block is exited
END_VAR A required termination declaration after declaring your variables
Interface
Example:
IEC 61131-3 PLC variables
I = Input
But also with other PLC brands not following
Q = Output
this, you can see other representations,
M = Auxiliary memory bit (logic coil)
especially:
T = Timer
C = Counter X = Input
FB = POU function block Y = Output
FC = POU function DB = Timer
IB = Input byte …
IW = Input word†
QB = Output byte
QW = Output word†
MB = Auxiliary memory byte
MW = Auxiliary memory word†
Label = Alphanumeric label‡
Addressing Input/Output (depends on PLC brand and its software)
Inputs Outputs
X00-X01-......-X07 Y00-X01-......-Y07
In OpenPLC Editor
X10-X11-......-X17 Y10-Y11-......-Y17
Addressing example
................................. ................................. • %IX0.3
X70-X71-.......-X77 Y70-Y71-.......-Y77 • %QX1.2
X100-X101-......-X377 Y100-Y101-......-Y377
!!! Following IEC 61131-3 does
Also: mean that it shall follow
Inputs Outputs addressing inputs and outputs
I0.0-I0.1-…I0.7 Q0.0-Q0.1-…Q0.7 as I0.0, Q0.7, etc.
I:0/0-I:0/1-…I:0/7 Q:0/0-Q:0/1-…Q:0/7
%I0.0-%I0.1-…%I0.7 %Q0.0-%Q0.1-…%Q0.7
%IX0.0-%IX0.1-…%IX0.7 %QX0.0-%QX0.1-…%QX0.7 X stands for bit
… … % is addressing prefix
Auxiliary Relay / Memory (M)
• NO and NC contactors can be used inside the program as desired.
• It can be started as ON/OFF states.
• Addressed in decimal numbering (M1-M25-etc).
3 types of M:
• Keeps its instant state when electricity goes off.
• Does not store its instant state when electricity goes off.
• Special M (comes with PLC design, its function cannot be
changed, can be used in program for multiple times, may differ with
PLC brands)
Auxiliary Relay / Memory (M)
Example (Mitsubishi PLC):
Aux. Relay \ PLC Model FX1S FX1N FX2N *
General Auxiliary Relay 384 (M0-383) 384 (M0-383) 500 (M0-499)
Latched/Retentive M 128(M384-511) 1152(M384-1535) 2572(M500-3071)
Total 512 1536 3072
Auxiliary Relay
Special M (from Mitsubishi):
Auxiliary Relay
Special M (from Siemens S7-200):
Programming
Ladder diagram symbols
PROGRAMMING LANGUAGES
• Ladder diagram (LD), graphical
• Function block diagram (FBD), graphical
• Structured text (ST), textual
• Instruction list (IL), textual *
• Sequential function chart (SFC), has elements to organize programs
for sequential and parallel control processing, graphical.
Ladder diagram
Ladder diagram
Signal section: Starts or stops current flow to the circuit.
Allows circuit to operate.
Decision section: Uses logic from multiple devices to
determine what work is to be done. Decision is used to
control a load device.
Action section: Work to be performed based upon
decision. (I.e. turn a load device on or off.)
A row number is allocated for each horizontal rung. The
number of the line is situated on each horizontal ring’s left
side. Displayed three row numbers
• On the correct side of a coil are numerical
cross references
• They identify the line number that their
contacts are located on.
Ladder diagram
1. Inputs can be used in Series as well as Parallel to 2. Outputs (or coil) can be used only in Parallel
form a connection
*
Ladder diagram
3. One Input can be used in multiple times in one 4. One Output cannot be used multiple times in one
program program, except in Set/Reset and Latch/ Unlatch
functions
*
Ladder diagram
5. Input Address cannot be used as an Output 6. Outputs Address can be used as Inputs Address
Address
*
Ladder diagram
7. Outputs can not ve connected directly. If needed, a 8. A contact cannot be connected in vertical way. It
random NC contact can be used. should be connected horizontally using an
equivalent circuit
Logic in programming and Its command list in Siemens PLCs
Siemens uses STL (Statement List) text based
Command line programming language which is not among the IEC
61311-3 programming languages list.
However, it is equivalent to ST language.
Logic in programming and Its command list in Siemens PLCs
Instant contacts/coils
• In normal working process, inputs are read
and its states are held in input registers.
Then, program execution/scanning starts.
• With instant contacts, inputs are not
registered in input register. It directly reads
its status and connects to the rest of the
circuit.
• Likewise, outputs/coils status are changed
inside the program and the results are
written to output registers.
• With instant coils, output status is directly
applied to the load when its status changes
inside the program.
Timers
• Comparing to relay-logic timers (conventional type), the working principle is the same.
• PLC programs enable to reach and use some of other properties of timers as well (e.g., instant
value of accumulator, timer input signal, etc.).
• Also, some brands can provide another type which is very similar to conventional type.
Allen-Bradley Allen-Bradley
o ENO: Active when EN is active
o Q: Conventional timer output
o ET: Instant accumulator value
o PT: Timer preset value (Shows similarities to the
object-oriented programming)
Timers
Siemens S7-1200 Siemens S7-200
Older Siemens PLCs
included varieties of timers
with different resolutions
Timer is set to 1 second
Timers
Retentive timers: (also called «Accumulating Timer»)
• Different from conventional timers, if the timer input is cut off before the preset time, the
accumulator does not reset its value. If input comes again, the accumulator counts from the
value which was left.
• Only resets from its reset relay/pin.
Counters
• Counts up/down with each input signal step
Siemens S7-200
• Conventional counters outputs HIGH when value
reaches zero to preset value/preset value to zero
• Resets its value with reset input
• Up Counter
• Down Counter
• Up/Down Counter
Siemens S7-200
Counters
Do-more Designer
Up Counter:
• Starts from zero
• Each pulse increases CT0 value
• .DONE output activates when preset value is reached
Down Counter:
• Starts from preset value
• Each pulse decreases CT2 value
• .DONE output activates when it reaches zero
Up/Down Counter:
• Starts from zero
• Each pulse increases/decreases CT1 value
• .DONE output activates any preset condition is reached
Set-Reset
• A ready-to-use structure for latching circuit
Siemens S7-1200
• SET set the bit value to HIGH
• RESET set the bit value to LOW
• If SET and RESET is activated at the same time,
the dominant one overrides.
Siemens S7-200
• SET and RESET is activated by only a pulse
• If SET is activated once, the only way to make
the output bit LOW, a RESET input is needed
• So that, if a SET coil is used for a bit, also a
RESET coil has to be used in the program
Leading Edge and Trailing Edge Contact
• Leading edge (also «positive edge») contactor closes for only one cycle when the
related variable value changes from LOW to HIGH.
• The next cycle it opens again whatever the value the related variable has
• Likewise, tailing edge contact (also «negative edge») contactor closes for only
one cycle when the value changes from HIGH to LOW
Siemens S7-200 Do-More Designer
• Also, there is another type which does not
require a variable but directly applied to the
related rung.
Examples
An automated temperature control system and its related
control schematic is given below.
Components: START button, STOP button, 3x
thermostat (only consider 3 thermostat), 3x heater
https://instrumentationtools.com/plc-program-
temperature-control-using-thermostat/
For more:
https://instrumentationtools.com/ladder-
logic-programming-examples/
List of Inputs and Outputs
I:1/14= Start (Input)
Examples I:1/15= Stop (Input)
O:2/0= Master Coil (Output)
I:1/0 = Proximity to detect big parts (Input)
• Small parts do not need to be detected as it has a straight conveyor
O:2/1= Gate solenoid coil (Output)
path.
T4:0 = Timer to operate gate (Timer)
• Big parts are to be diverted to the adjacent conveyor which is
connected with the main conveyor as shown in diagram above.
• Detection of big particles has to be done in order to divert the path of
such particles.
• To detect big parts, Proximity Limit switch is used.
• Conveyor has a fixed speed, hence timer is to be set to energize
Gate Solenoid which diverts big parts to the adjacent conveyor.
https://www.sanfoundry.com/plc-program-
separate-big-small-parts/
For more:
https://www.sanfoundry.com/100-plc-programming-examples/
List of inputs or Outputs
I:1/0 = Level High Switch-Tank 1, LHS1 (Input)
Examples I:1/1
I:1/3
= Level Low Switch-Tank 1, LLS1
= Level Low Switch-Tank 2, LLS2
(Input)
(Input)
O:2/0 = Inlet Valve (Output)
• Mount two level switches in the first tank and two switches in the
O:2/1 = Tank Connecting Valve (Output)
second tanks. Both switches of tanks detect High and Low level of
O:2/2 = Outlet Valve (Output)
the tanks.
I:1/14 = Start (Input)
• Install inlet valve to control inlet process flow and outlet valve to
I:1/15 = Stop (Input)
control outlet process flow.
B3:0/0 = Master Coil Bit (Bit)
• Install one more connecting valve to control draining of process
material from Process 1 Tank to Process 2 Tank.
• Provide interlocking to prevent from malfunctioning or overflowing.
https://www.sanfoundry.com/plc-program-control-level-two-tanks/
List of Inputs and Outputs
I:1/0 = Start (Input)
Examples I:1/1 = Stop (Input)
I:1/5 = Proximity (Part detection)(Input)
C5:0 = Counter Up (Counter)
• Mount Proximity Switch to detect the parts.
O:6 = Display address (Output)
• Use output of proximity to counter as an input to increment data.
TOD = Hexadecimal to BCD conversion instruction(Compute)
• Convert this number into appropriate numerical and show number of parts
B3:0/0 = Latching Bit (Bit)
collected.
• Most widely Inductive and Capacitive Proximity switches are used to detect
parts.
• Inductive Proximity are used to detect metal objects while to detect other
objects, Capacitive Proximity Switch is most widely used.
• Capacitive Proximity detection capability ranges from 1 to 25mm distance.
• Mount this sensor according to the size of parts present on the conveyor and
width of conveyor so that this sensor can detect parts easily.
• CUP is used to increment the number of parts collected.
https://www.sanfoundry.com/plc-program-counting-parts-conveyor/
Examples
The given sorting machine sorts material types (wood, plastic
and metal) using photoelectric, inductive and color sensors.
• Detect the incoming objects with the help of a photoelectric
sensor, proximity, and color sensor.
• Use a belt conveyor to move the objects from one place to
another place that will be operated with the help of an
electric motor.
• Take sensors such as inductive proximity sensor, capacitive
proximity sensor, and a photoelectric sensor.
• Determine whether the object is wooden, metallic, or plastic.
• Make a program to sort these objects according to their
material.
• Use pneumatic cylinders and a mechatronics system to
push to objects in their respective collectors/buckets.
https://www.enggarena.net/automated-sorting-system-using-plc/
Examples
Cylinder Position Sensor
https://www.enggarena.net/automated-sorting-system-using-plc/