How to Scale Analog Values for PLC Programming

LeMaster Tech
183 followers
755 Video Views·May 24, 2026
In this tutorial, I break down what analog sensors and values are, and how to normalize and scale them in PLC code, and then we build an example scaling function together from scratch in Siemens TIA Portal.
We'll cover:
- What analog values are and how they differ from Boolean (digital) values
- How normalizing functions work
- How to scale a normalized value and what engineering units are
- Live build of a working scale and normalize function in TIA Portal
Whether you're new to PLC programming or have always wanted a clearer explanation of analog scaling, this simple and easy to follow video is for you!
Resources
PLC used in this tutorial: https://amzn.to/4cgkOPa
Support the channel: https://www.patreon.com/LeMasterTech
Hello, and welcome back to the channel.
And today we're going to take a look at, uh, PLC programming,
continuing our PLC programming tutorials.
And today's zeroing in on how to scale analog inputs.
Um, so we've done quite a lot of work so far on the channel with Booleans or
binary digital inputs and digital outputs, which are on off zero or one.
Today, we're going to take a look at the other kind of input, which
is analog inputs and outputs.
Um, and these are things like temperatures, pressures, flows, the
speed of a variable frequency drive, things that are not zero or one.
They have a range of control, a range of feedback input or control output.
Um, and to understand the scaling that we need to do in the PLC, you need
to understand briefly how these work.
So effectively, uh, every analog device is converting a physical real world
process, uh, into a raw electrical signal.
The most common ones are zero to 10 volts DC and four to 20
milliamps, uh, uh, analog input.
So the, the thing that I want to go, you know, put my credibility at stake
and say is more common is four to 20 milliamps, because you get this nice
benefit of zero milliamps also telling you that there's a problem with the device.
So four milliamps acts as your baseline of a zero reading where that's zero
pressure or flow or your low level or whatever, but, or four milliamps tells
you that, but zero milliamps tells you, Hey, I've lost communication with this
device and I've gotten some benefit.
Uh, you don't always have that necessarily.
If you have zero to 10 volts, unless you add in some sort
of like broken line connection.
Um, now it's important to note that every PLC manufacturer and every
analog input card can be a little bit different.
So you need to check the specs for what the raw input signal is for your card.
Some Allen Bradley cards will use zero to 32,000.
They'll basically max out what a double integer can hold a
double integer value, uh, uh, variable.
Um, but Siemens, the more common one is basically zero to 27,648, where
anything below zero will be seen as under a current in anything above
27,648 will be seen as over current.
Okay.
Um, so we'll use a zero to 27,648 because I have the Siemens PLC
programming, uh, software and a PLC hooked up.
Um, but the, the concepts we're about to cover are universal for any PLC.
So let's actually get into what scaling and analog input looks like.
And let's just make a new function called analog scaling.
Um, you could create this in any PLC platform.
Now the exact name of the next two blocks I'm going to show
do vary across PLC platforms.
So the two steps we want to do are basically take a raw electrical
input, which will be giving us a value of zero to 27,648.
And we want to normalize it to basically zero to 100% or 0.0 to 1.0.
Um, and then we want to scale it according to our engineering units.
Okay.
So this is what scaling an analog input means.
What that zero to 27,648 means to the actual real world is
meaningless unless we scale it.
Because a flow meter, a pressure sensor, and a temperature sensor,
and a level sensor could all be hooked up to the same analog input card.
They could all be four to 20 milliamps, but that tank might be
telling you zero to 10 feet of liquid.
That flow meter might be telling you zero to 50 GPM of flow.
Um, you know, that temperature could be 32 to 200 degrees Fahrenheit.
Um, or you might want that temperature sensor reading in Celsius.
That is where the scaling comes in.
So the first thing we want to do is we want to normalize that raw value.
Siemens has a block called norm underscore X.
You could do this in Allen Bradley with a compute or calculate block.
Um, you can do it in Siemens with a calculate block, but this is already
built for you where you basically say, what is my raw, um, electrical minimum?
It's going to be zero.
And my raw electrical maximum will be six 48.
And then, uh, we'll define this raw input as a, uh, input to
be passed into this function.
Okay.
So we're creating a function that will let us scale all of our analog inputs.
Um, so we'll make this reusable.
So we'll make it a, what's called a local in meaning it needs to get
passed into this function when we call it.
Um, and we'll make it a double integer.
That's the proper, um, proper format for this.
And this is going to output something that we'll use in this
scaling function called normalized.
So we'll just go ahead and define it.
We'll make it a real, um, because this is going to give us zero to one, but
we don't want an integer that will only ever read zero or one.
We want it that normalized zero to a hundred percent.
So we want it to be a real, um, okay.
Now we'll have this normalized bit that will, and actually
did I call it local temp?
Okay, good.
Um, so this will basically tell us zero to one as a function of scale, like
where in the four to 20 milliamps span our devices, um, but that's still not
useful because those aren't the units we're looking for, what we're looking
for is something that has been scaled to the appropriate, uh, output.
Okay.
So we'll take that normalized and we'll say we have zero to a hundred.
It can be really tempting to just take that value and math and
multiply it times your max span.
So if you were looking at a level sensor that was telling you zero to a hundred
percent full on a tank, you might get away with saying like, well, now I'll
just multiply it by a hundred and it'll tell me the percent full of the tank.
But that's tricky because four milliamps does not always equal zero.
Sometimes like with the temperature sensor and in the U S you know, we're
using Fahrenheit zero is not a temperature.
You're going to see from a temperature sensor very regularly.
If you're measuring the temperature of a liquid, a lot of these are scaled to
like 32 or, or, you know, there'll be 32 to 200, but you want this function to
work if you get another temperature sensor that goes 50 to 300.
So again, to make this reusable, what we want to do is we want to make some new
variables and call them a EU min and EU max.
You can call these something else that makes more sense to you.
EU means engineering units, right?
This means the, the basically like the the actual, what you want your
scaled output to display as and we'll make these reels as well, even though
they are most commonly going to be integers, that's okay, we'll keep them
all reels and that should not be local temp.
That should be another local in, okay.
We want when you're calling, can I move that?
Okay.
We want that to be a local in because we want this to be something
that you pass in per input.
Um, the whole thing about making an analog scaling function that's
reusable means you need to be able to change these parameters
per sensor that you hook up.
So we'll make engineering units, minimum and maximum, and then we'll make an
output that will be our scaled input.
Okay.
So I know I just said output.
That'll be our scaled input.
But if you think about what this function is doing, it's taking a raw electrical
signal from an analog input and it's turning it into a useful scaled
engineering units, whether that's GPM for flow or, you know, inches of H2O
for, for, for, um, for, for a level sensor or something like that.
So we'll make that a local out and we'll go ahead and define that.
Just this little normalize plus scale is all it's going to take to give us a
reusable function that will let us scale inputs.
So let's go take a look at what actually using this thing, uh, looks like, and
we'll show an example of it working.
So let's go ahead and define like raw temp one.
Okay.
We'll make a raw, uh, temperature sensor and to not worry about wiring or physical
hookup, we'll make it a memory tag for now, but obviously this would be the tag
you hook up to your global analog input channel.
We'll go ahead and define it.
And we'll say the engineering units, uh, minimum for this will be 32 and 200,
right?
So it's measuring the temperature of water.
There's no reason to think it's going to measure below 32 super important
point about EU min and EU max.
This is not something you as the programmer should be picking what makes
sense to you.
This should be from the manual of the device that you hooked up.
So depending on the specs of your temperature sensor, your flow meter,
it'll tell you min span and max span for four and 20 milliamps.
Um, so I am obviously picking values for the demonstration, but these are things
that should be coming from a manual.
Uh, now let's go ahead and define, uh, the scaled output.
Okay.
So this is going to be now a temperature sensor doesn't need the pound sign.
There we go.
This is going to show us a temperature sensor.
Let's go ahead and download it.
Um, this will show us a temperature sensor that is going to read a raw
electrical signal of zero to 27,648, but our function that we just wrote should
scale that down to a zero to 1% of span and then multiply it times 32 to 200 to
figure out where we are in that span.
Okay.
So we're sitting there at zero 32 is a good sign.
Let's go ahead and throw 13,000 in here and look at what about
middle span looks like.
And it gives us, Hey, okay.
You're getting this electrical reading on your card of 13,000 that
correlates to 110.99 degrees Fahrenheit.
Nobody in the UK panic.
Um, and then let's say, let's go get pretty close to max span.
Okay.
25,000.
All right.
It's 183 degrees.
So you can see this is kind of cool and kind of useful, but let's take a look
at where it gets really useful.
Let's say we have a raw level in here as well.
And the level is going to show us, um, from three inches of water
up to 240 inches of water.
Okay.
It's a, it's.
I don't know, ultrasonic level sensor, um, to pick your poison.
Uh, but basically let's just make up that we have some level sensor here.
Um, and we are going to have a scaled level one here and we'll make
that a global memory as well.
And like making all these global memories is not exactly
good programmers etiquette.
I'm just trying to go fast for the sake of the tutorial.
Uh, and then we'll throw one more in here.
We'll say we have a flow meter, raw flow one.
Um, and we'll define a little global flow meter tag here.
Uh, shouldn't have been a real that's okay.
It doesn't matter.
Um, and let's say that the flow meter is zero to a hundred GPM and we'll
make scaled flow one, uh, tag as well.
Okay.
Define tag, global memory.
There we go.
All right, let's go ahead and download this, play around with it and talk
through what we're seeing a little bit.
Alrighty.
So we'll leave scaled temp alone, uh, as is, but what's cool is we've
written that scaling function once.
And this raw level is currently showing zero and it's, you know, scaling
it to three and if I send this one to, you know, 10,000, a little less than
half span, it gives us, Hey, okay.
The level is 88 inches of water.
And I go to my flow and I say, this is a little over half span.
And it says, all right, you're getting 54 GPM.
So one very simple analog scaling function that takes a raw input,
normalizes it, and then scales it according to our engineering units is
able to take every four to 20 milliamp analog input in our entire system and
rapidly convert it to engineering units that we'd want to see, we'd want to put
these on an HMI, add them to a historian tool and view trends over time.
Um, so this is really a simple, basic crash course to analog scaling.
No need, I think, to overcomplicate it.
I'm sure in the future we'll need to do a tutorial on the actual wiring of
analog inputs and the setup loop checking process for analog inputs, how you
actually make sure they're working correctly.
Um, but for the scaling and the PLC, I think this is a great, uh,
tutorial and good place to stop.
So I'll go ahead and call it there on this lesson.
Uh, if you have any questions, be sure to let me know about in the comments below,
please consider leaving a like on the video, subscribing to the channel that
helps me out a ton and let me know in the comments as well, what you'd like
to see next on the channel.
Thanks so much for watching and see you next time.
Thanks.
Bye.
