Learn the fundamentals of binary and Boolean operations in ladder logic using Siemens TIA Portal. This is Part 1 of my PLC programming tutorial series covering ladder diagram programming from the ground up. In this tutorial, I cover:
Momentary coils and how they operate Normally open (NO) and normally closed (NC) contacts Positive and negative edge detection (one-shots) Set/Reset and Latch/Unlatch instructions
Whether you're just getting started with PLCs or brushing up on the basics, this video breaks down the core building blocks you'll use in almost every ladder logic program.
Timestamps 00:00 Introduction and Background 01:57 Setup and Adding Input and Output Tags 05:13 Examine If Open (XIO) or Closed (XIC) Normally Open (NO), or Closed (NC) 09:45 The wiring in use for this tutorial 12:39 Using two digital inputs to control four digital 15:21 Set and Reset, Output Latch and Unlatching Commands 17:43 Positive Edge and Negative Edge One Shot Conditionals 21:55 Outro and Thank you!
What's up, Automation Nation? Welcome
back to Low Master Tech. In today's
video, we are kicking off a new beginner
to intermediate ladder diagram PLC
programming series. Today being part one
means we're going to be covering
operations that involve true false
boolean conditions. And just because
we're dealing with true false conditions
does not mean that you can't do a lot of
cool stuff here or that it's not
incredibly important. For this tutorial
series, I'm using a Seaman's S71200 PLC,
which I can leave a link to in the
description of this video. This is a
very common piece of hardware found in
industry, but it is a little bit pricey
for the hobbyist who's just dipping
their toes in this field. Additionally,
you can get Seaman's TIA portal for free
downloads, but you get a 21-day trial
license after which time you need to
pay. There are free software such as the
Arduino PLC IDE, the Code Assist
platform, Beckoff TwinCat, or the Open
PLC IDE where you can follow along with
many of the concepts we're doing in
these videos for completely free. I'm
using Semens because Seammens is the
most common worldwide PLC platform and
so I think for maximum utility of this
series this is a good platform to teach
on. Most of learning how to program in
this language will apply to Rockwell
Allen Bradley Beckoff Seammens Omron
Kens Mitsubishi Panasonic. It doesn't
matter what PLC platform you're
developing on. Every platform is just
different flavors of fundamentally the
same language. Just before we start the
tutorial, industrial automation and
controls tutorials aren't that common or
that good on the internet. And I believe
it's because the hardware tends to run
expensive. The software tends to run
expensive. And if you're going to show
things like hands-on wiring and
integration of real sensors into a
system, that hardware gets expensive as
well. Committed to bringing the highest
quality level automation and controls
tutorials to YouTube. But if you want to
help me do more of it and do it faster,
please leave a like on the video,
subscribe to the channel, drop a comment
letting me know that you find this
useful and what you want to see next.
And if you really love what we're doing
here on the channel, you can check out
my Patreon in the description below.
Now, let's get into the tutorial. So, I
have a PLC that I am already online
with. Uh, this video is not a series on
how to get online with a PLC or how to
create a new Seaman's PLC project. We're
going to focus on ladder diagram,
understanding it, and writing logic. So,
I'll try to drop tidbits about PLC
programming setup while I go, but we're
going to mainly focus on ladder diagram.
So I'm going to make my main routine
which is just going to by default get
called when uh the program starts up but
all the actual logic is going to happen
in a function that we're going to call
ladder tutorials
binary. Okay. So I make a new function
and that's where I'm going to drop all
of the code that we write. Um, but one
tidbit about PLC's in general is you
typically have to call your routines
from a main routine or they won't get
triggered. So this is basically in any
form of programming, you have your if
name equals main kind of condition
checking if you're in the main routine
and then you call all the sub functions
that you want to scan. So we're going to
write all of our code here in ladder
tutorials binary, but we added it to the
main just to get out in front of that.
Now, to talk about the physical setup
that we're going to use here, I'm going
to create two tags for input hand
switches and then four outputs for
lights. So, I'm going to say hand switch
one and hand switch 2 are going to be
address input 0.0
and 0.1.
and they might be mad because I've
previously used this PLC, but once I
download that'll it'll just work. Um,
and one thing depending on the platform
you're on, again, how you define your
inputs and outputs does vary, but in
general, they're all pretty similar in
the sense that you need to find where
your hardware input and output tags,
which on Allen Bradley, you'll have I's
and O's. on Seammen's most of the
European and international standard O's
look a lot like zeros while they also do
in the US. Um so they've decided to use
Q's instead of O's. So for outputs you
have Q0.0
referring to the first relay output on
the front of my PLC. And we'll check out
my hardware in just a minute. Uh so that
everything we're doing in this tutorial
makes sense when you see the outcome.
But I do think if you're just following
along to understand the latter logic,
you're still going to take a lot away
from this series. So, I'm just going to
go through there quickly. And I use the
first four outputs on my PLC to be four
output lights. And I use the two hand
switches to be two inputs. And I'm going
to download this to the PLC. And again,
I think we could actually fill like a
whole tutorial episode on what compiling
is, what downloading is, what uploading
is, how to go online, how to go offline.
I want to focus on the ladder in this
one and the actual PLC programming which
we still haven't started doing. So just
drop a comment if you have questions and
if you think a specific concept would be
useful uh for a future video. Now like I
said we're going to do binary operations
in this video which means we're going to
look at all the true or false things and
not really all of them. The most common
and most important ones that you need in
PLC programming. So we're going to start
with a normally open contact. Okay. And
again per PLC platform they may call
this something different but the origin
of ladder is basically they used a lot
of the uh visual tools that show up in
electrical schematics and relay logic.
So on a relay where a thin strip of
metal switches back and forth between
one contact and another based on an
electrically isolated signal on the
other side of a coil. on that relay you
have a common wire switching between
normally open and normally closed. And
so in ladder you basically have normally
open and normally closed contacts. The
same visual except it's a software
block. Now if you come from a
programming background or it's easier
for you to think of it this way. This is
basically an if statement. You're
checking if a condition equals 1. So we
could say if hand switch one is true
then ladder is kind of naturally then.
So just the nature of this PLC branch
existing is us saying hey energy if you
want to think of it this way electricity
comes in on the left side of your screen
checks if hand switch one is equal to
one. And if we put this coil over here
and say output light one active, then
this rung of code reads as if hand
switch one then turn on out light output
light one. But it also implicitly has a
second condition in here which is if not
hand switch one then turn off output
light one. That's something special
about these momentary coils here. Um e
every PLC platform has this distinction
between a momentary only energized when
the left side is true versus set and
reset or in Rockwell it's called latch
and unlatch OTU and OTL. In Seammens
it's set to turn it to one and then
reset to turn it to zero. That's more
like a light switch. This energize only
while true is more like a momentary push
button where you have to be holding that
button in the whole time for a light to
be on. So, we should be able to test
this and I should be able to show you
physically what this means. But this is
a valid ladder logic rung right here.
We're checking if an input from the real
world, which is a hand switch, is turned
on, then we're going to turn on a light.
So, let's go ahead and download that.
And let's see if I can get the box on
screen in a way that doesn't look
stupid. So, like I kind of alluded to
while punching in the tickets, I have
this old control box from a different uh
thing I did a while ago that has two
hand switches. And actually, that's
cool. Um, so the second switch does
nothing. I have four lights up top. I
don't even remember which wire I put
into which one. But when I turn hand
switch one on, you can see the LED on
this light turns on. And if I turn it
off, it turns off. Now I should have had
something here which is the glasses in
the monitoring. Every major PLC platform
has a version of this. They have live
monitoring which is you can see the
energy coming in here and it's lit up
green. And then you can see with the
dashed line where energy code energy
processing power has not processed
because the hand switch is not turned
on. But if I turn the hand switch on,
you can see the energy gets to the
output light. Now energy as I'm using it
is basically code saying it's true. So
you should do thing that is not
fundamentally the same as 24 volts
or 120 volts or any other amount of
power. That's because inputs and outputs
vary wildly in industry based on the
need, based on what you're hooking up to
them. And so you it's very important in
automation and controls that you know
your hardware and you know your use
case. For that reason, despite the fact
we've only written one very basic line
of ladder logic, I want to take a pause
and explain the wiring of my system.
Okay. On a piece of drail, I have a
24volt power supply which is taking wall
outlet in and it's transforming 120
volts into 24 volts DC. From there, my
PLC is powered with 24 volts DC, and I
run zero volts DC down to the line on
the relay outputs. I'll talk about that
in just a second, but it's easier to
talk about the hand switch first. So, in
my control box, both of my hand switches
just are think of them as a strip of
metal that's either not making contact
with the terminal or making contact with
the terminal depending on the state of
the switch. And so I have two inputs
coming back to my PLC that are either
connected to 24 volts or connected to
nothing based on the state of the hand
switch. So that's how I read a one or a
zero from those two hand switches. The
thing that might be less intuitive is
I'm actually connecting the outputs when
I turn them on or turn them off to 0
volts DC to get the lights to turn on or
turn off because I have the positive
wire of all of my lights directly
connected to 24 volts DC. But when the
outputs are not active, I've created an
open wire condition because these are
relay outputs. So I was talking a little
bit earlier about the idea of a relay
which is some electro mechanical piece
of equipment that makes contact or
breaks contact between two terminals.
For a light to turn on both the positive
terminal and the negative terminal have
to be connected to create an
electrically continuous loop. So just by
having a relay output not active. That
means this red wire for example will not
make contact with 0 volts DC. it won't
be able to complete the loop and the
light won't turn on. But then when it is
active, this red wire basically pulls in
and makes contact with 0 volts DC. Power
can flow through that light and the
light turns on. Which is why an output
being energized in our PLC program is
not the exact same thing as us turning
voltage on. If that makes sense. It's
important to understand in automation
and controls, you're writing code that
controls the real world. One does not
always equal 24 volts. 0 does not always
equal 0 volts. I apologize for the segue
into the real world. But uh frankly, if
you learn about ladder logic programming
and you don't learn about the sensors
and inputs and outputs that you're
controlling, you have half of a skill.
Okay. So now armed kind of with this
basic input and basic output condition,
let's do a very quick example of how to
use both of these hand switches uh to
control all four of the lights in kind
of an interesting state. So let's say
when both hand switches are off that we
want the first light to turn on. And
then we'll say when we're going to
basically do the logic gates that you do
in uh college if you have a
microcontroller class. And then we're
going to say when hand switch one is on
and hand switch two is off. That'll be
the condition that'll turn output light
two on. And then we're going to say when
two is on and one is off, that'll be
what turns three on. And then, hey, if
they're both on, let's go ahead and turn
four on.
Okay. And so this is kind of fun because
two inputs that have binary conditions
actually have a total of four potential
output states here. So if I grab the box
again, I don't know why I keep putting
it behind me. If I grab the box again
and I download this code to the PLC. All
right. So, right now with both hand
switches off, the I can't do bottom,
left, or right right now. So, right now
with both hand switches off, this light
is on. If I turn one on, I get the
second light. If I turn the other one
on, I get the third light. And then,
what condition haven't I had yet? This
one? Yep, I get the fourth light. Okay,
so there you can see our code in action.
You can see that there's four total
possible combinations of these hand
switches being on or off and we have
them controlling the four different
lights based on that. So this is really
an excellent first dive into binary
ladder logic programming. If you
understand these momentary outputs, I do
want to reiterate the thing that is
happening with these momentary
conditions is you're saying as long as
the conditions to the left of this coil
are true, then this coil is going to be
energized. But the second these
conditions are not true, that coil falls
to deenergized. So you basically have an
if else statement in the same line of
code. You have if hand switch one and
two are off then turn on light one. But
you also have the statement of if hand
switch one or hand switch two is on then
turn off output light one. That's the
nature of these coils. So our next
practical example is what if I don't
want that to be the case? What if I want
something that triggers something to
turn on but I don't want the second that
condition goes away to turn off. So,
what if I said I want when hand switch
one turns on, right? This condition that
we've talked about, I want that to turn
on output light one, but I want it to
stay on even if I turn hand switch one
back off.
That is when we want to use this set bit
that we talked about before. So, in this
case, if I just go ahead and download
this real quick. In this case, and don't
mind that a light is still on from our
previous example. If I turn the hand
switch on, output light one turns on.
And even now, if I turn hand switch one
back off, output light one stays on. And
that's because I set it on, but until
something resets it off, it's going to
stay energized. Kind of like that blue
light is energized because nothing
turned it off after I deleted the code.
The partner condition to that,
obviously, like we've said, is a reset
block. And what's cool is I can have it
tied to a completely different input. So
I can say, hey, hand switch two is going
to be what turns off output light one.
So now that you can see these two
conditions, you can see hand switch one
letting me turn on the light and hand
switch one can turn back off and the
light stays on, but hand switch two will
turn off the light. And what's
interesting is if they're both on here,
you actually see an interesting dynamic
of PLC programming, which is PLC's read
top to bottom and left to right just
like you're reading a book. So even
though both hand switches are on, it's
getting set and then on the very next
rung, it's getting reset. So by the P so
by the time the PLC finishes a cycle of
processing, it just sees that the tag is
off because in the same rung, it gets
turned on and then turned off in the
same network. So for example, if the top
line had the R and then the bottom line
had the S, that light would have been
turning on with both hand switches on.
So that's just a useful PLC programming
nugget to know about. So, we're making
really tremendous progress in a very
small amount of time. And hopefully
you're learning a lot and finding this
very useful. Let's combine these set and
reset conditions with one more super
useful binary function, which is one
shots. So, this block if and this
counterpart block if not are looking at
a binary condition continuously. So,
they continue evaluating and they
continue processing over and over and
over again. So, every time this hand
switch is off, I'm trying to set the
light to turn on. And every time this
hand switch is on, I'm trying to tell
that hand switch to turn back off. But
what if I want when an when a switch
gets turned on, I want to try to turn on
the light once
and then move on with my day. Well,
that's when you want something called a
oneshot. In Allen Bradley and Rockwell,
you type in ONS and a special character
called a oneshot pops up. In Seammens,
in many European and Asian vendors, they
have rising edge and falling edge
momentary triggers. So this is P for
positive edge trigger. But if I look at
the positive edge trigger of the hand
switch, I now have to give it a second
tag, which is the memory. So, an
interesting thing about the PLC is it
can only track statuses over time if it
has somewhere to put that status over
time. So, every scan of the PLC, it's
live evaluating the input for whether
it's true or false, but it needs a new
tag to basically put the state of the
hand switch in memory.
So, we're going to say hand switch one
memory. And I'm going to go ahead and
define a tag. And this is a seaman's
function, but all PLC's sort of have
inputs, outputs, and then they can do
program tags or local tags or global
memory tags, which are taking a
permanent memory address. So, similar to
the I's for inputs and Q's for outputs,
you can use M's for memory tags that are
internal logic tags. For small systems,
things that you're writing on like an
RSLogix 500 system or a Seaman's S12 uh
S71200,
it's totally fine to use memory tags. If
you're doing really large systems with
complicated functions, you usually want
to be looking at using databases for
more of your memory.
But anyways, this tag HS1 mem is going
to be the bit that tracks the last state
of the hand switch. So we know if it was
a rising edge trigger or not. Now if I
say on positive edge for hand switch one
and for falling edge negative edge for
hand switch 2 and I give HS2me
its own tag. I have caps lock on
and I give that its own tag as well.
Global memory define.
Now, what we'll see when I get my box
out and let's use output light two just
so I can get that blue light to turn off
finally. So, now what you can see is
when I turn on switch one, it turns on
and when I turn on switch two, it stays
on because we're waiting for the
negative edge of switch two. So, if I
turn switch two back off, the light
turns back off. But now, what's cool is
even though light two is off, and you
can see that the the switch up top still
says true. If I trigger it again with
switch two off, the light still turns on
because I'm only evaluating that line
once. It's a onehot that happens when
that condition is met. So, you can think
of this in a process where someone hits
a start button. You might check to see
if the system is healthy to start up a
bunch of pumps and things like that, but
you usually wouldn't want to like
trigger a start condition when that
button is pressed momentarily that is
locked into place so that if two hours
later the process clears and is ready to
start running, stuff starts running. So
you might only want to evaluate
something once when a condition is true
and then stop evaluating it until that
condition happens again. So, every time
I turn on a hand switch, I turn the
light on. But then every time this
switch turns off, it turns off. This is
also how you get around some of those
race conditions where you could have two
things that turn something on or two
things that turn something off.
And so, if you use positive and negative
rising edge bits, you have a way of
handling that. Okay, so that was a
action-packed uh introduction to binary
ladder logic, ladder diagram
programming. Um, if you have any
thoughts on the tutorial format, ways
that it could be more useful, things you
want to see more of or less of, things
you feel like I covered too quickly or
didn't cover deep enough, or just
additional topics you want clarification
on, let me know about in the comments
below. I will adapt this series to the
interest of the crowd as it goes on. I
have really been enjoying all of the
enthusiasm behind automation and
controls I have found on the channel
lately. So, um it's super cool to have
all these automation enthusiasts here.
This is going to do it for today's
video. Thank you so much for watching
and see you next time. Thanks. Bye.