In this full tutorial, we'll wire and control a stepper motor with a PLC from start to finish. We start with an overview of the hardware on the bench, then go step by step through wiring the stepper to the driver and the driver to the PLC. From there we set up a motion axis in the controller and write the ladder logic to jog the motor forwards and backwards using two pushbuttons and a Move Relative instruction. Whether you're a controls engineer adding motion to your skill set, a panel builder wiring your first stepper, or a student learning PLC-based motion control, this video walks through the complete process — hardware, wiring, axis configuration, and code. We'll cover:
Hardware overview: the stepper motor, driver, and PLC used in this build Wiring the stepper motor to the driver Wiring the driver to the PLC outputs Setting up the motion axis in the controller Writing ladder logic with two pushbuttons and a Move Relative block Jogging the stepper forwards and backwards
TIMESTAMPS: 00:00 - Intro and Background 00:47 - Hardware Equipment Overview 03:06 - Step by Step PLC to Stepper Wiring Overview 06:42 - Set up a motion axis to control a stepper in the PLC 11:00 - Write Basic code to control stepper motor movement in the PLC 18:31 - Final Demonstration and Outro
Don't Forget to Leave a Like on the Video & Subscribe to the channel! Considering becoming a super supporter of the channel at my patreon! https://www.patreon.com/LeMasterTech
AI Generated·May contain errors
What's up Automation Nation and welcome back to the channel. In today's video,
we're going to be taking a complete look at how to control stepper motors for precise motion
control using a PLC for industrial controls and automation. This will be a comprehensive tutorial
where we take a look at the main wiring, physical components required, as well as the PLC programming
setup, and some basic code to actually generate movement. Because that's quite a lot of content
to cover in one video, I'll break this down into chapters and you can see the timestamps below. If
you have any questions about what you saw today, feel free to ask them in the comments below and
I'll get back to you as soon as I can. I'll try to leave all the hardware shown in this tutorial
linked below as well. And without any further ado, let's dive in. Enjoy. Now, let's start this
tutorial by talking about the three main electrical components in use. The first and most obvious one
is the stepper motor itself. In America, you'll typically find stepper motors sized by NEMA,
the National Electrical Manufacturers Association, and basically all the NEMA ranking is telling you
is actually the size of the face. So NEMA 17 is 1.7 inches, 23 is 2.3, and they're actually not
telling you anything about the torque or overall power, just sizing. So this is a tutorial on how
to control steppers from a PLC, not how to size your motors. So for now, we'll just say work with
someone who knows about motor sizing to size the right size stepper motor. Next is the stepper
motor controller or driver. Because even though the PLC is the thing actually calculating when we
want the motor to turn and how much, a stepper motor driver or controller is the thing that
actually keeps track of the cycles of the multiple legs of your motor and tells it which one needs
to pulse next. It acts as the super important electrical bridge between your stepper and your
controller. And the last major component in the mix is obviously the PLC. Some PLCs or programmable
logic controllers do not have I.O. on board the controller or they don't have a transistor output
which you can use for stepper control. So you may need to buy an I.O. card that's specifically for
stepper motor control. The specific term for this is pulse train output and you just need to work
when you're specifying components to make sure that you have transistor digital outputs capable
of high speed pulsing known as pulse train output. Other than that, you just basically need wires to
connect these three components together and a power in feed for the source to the controller.
Most steppers come with a four wire connector to go into the legs of their motor, but if not,
they're super cheap and easy to find. So we won't get into that part. Now, in an industrial setting,
steppers only really do useful motion when they're coupled to something like a linear axis like this
ball screw I have here or a rotary table where it can rotate to index. But because this is a
tutorial on how to control steppers from a PLC, I'm not going to spec out components in this video
and we'll focus on stepper through controller to PLC. Okay, so let's go through and take a look at
the specific wiring for each of those three major components we just talked about. First and probably
easiest is the motor itself. For an open loop stepper, we only have four wires corresponding
to the A and B coils inside the motor and the plus and minus legs. You can quickly identify
which wires make up a coil by touching them together and if you feel the magnetic resistance
increase just trying to turn the motor with your free hand, those make up a leg. So we need to
land these on A plus and minus and B plus and minus directly. An encoder which would add feedback
to this motor is a significant amount of extra wiring back to a high speed input on a PLC and
out of the scope of today's video. Next up is the stepper controller and even though these have a
lot of dip switches and terminals, there isn't actually that much to them here. We already
covered the four stepper legs and there are two additional wires to connect for a dedicated power
supplying ground. We need these terminals because steppers often consume more amperage than a PLC
can output. Like a 48 VDC stepper motor can be controlled by a low amperage 24 VDC pulse signal
from a PLC. So these terminals are easy, just make sure to use an appropriate amount of power for
your motor. Now the dip switches I'm going to go over real fast because they aren't exactly wiring
but they are important to get right. One set of dip switches will typically be to set for what
you expect your max amp draw to be and just make sure to follow either the manufacturer specs you
can get online or often the dip switch matrix printed right on the side of the controller
and make sure to double check your on versus off orientation. For the other set of dip switches
you're setting up how many steps per revolution your motor should spin at. Many standard motors
have 200 or 400 steps per revolution but thanks to some electrical magic you can do something
called micro stepping to often do fractional steps for smaller motion increments. So you can
play around with these a bit but you need to make sure that your PLC gets set up the same way you
assign these dip switches. So the easiest place to start is generally just make the same number of
pulses per revolution as your stepper has increments. Now lastly the PLC wiring to your stepper
controller and despite the six terminals these are not very complicated either. Enable, Direction,
and Pulse all have a positive and a negative terminal and you can wire all three of these
negative terminals to zero volts DC which can reduce the total wires needed to bring to this
card from the PLC and you can even jumper it to the ground terminal of your power supply. The enable
and direction positive pins should work with any standard DC output electromechanical or transistor
based because they don't need to be high speed output. So the last wire is the pulse pin and this
is the pulse train output from the PLC. It needs to be on a transistor output capable of high speed
pulsing so make sure you specifically seek out a PLC or IO card that can calculate high speed
pulsing signal. So in total and in summary we have three digital outputs from the PLC to the stepper
motor controller card and one of those has to be pulse train output for the pulse signal and then
we land zero vdc or ground on the three negative terminals for enable pulse direction and the
ground terminal of our power rails a dedicated power supply on the plus v terminal and then the
four legs of our motor land on a plus a minus b plus and b minus back to the stepper motor and
that's it for the wiring the rest of it now comes down to how we set up our PLC and write our logic.
All right for the computer-based portion of this demonstration we're going to make a brand new
project called stepper motor setup we're going to make it in tia portal again as with most of the
controls tutorials on this channel i'm doing mine in siemens because it's the platform i already have
a paid license for and i have a PLC on hand for but the main steps covered in this tutorial will
be pretty much platform agnostic and so with just our PLC added let's go ahead straight to PLC tags
and let's add all of the IO that we're going to need the inputs and outputs that are already hooked
up to our PLC okay so i have hooked up to it the two hand switches and the two push buttons that
are on the front of my cabinet so we'll say input switch uh zero because it's at input zero that's
probably the best way to do it and then we'll say input switch one uh and then we will say we have
push button one and push button two and if you don't like my tag naming too bad now we have three
digital outputs we have stepper pulse we have stepper direction and we have stepper enable
okay that's just from the wiring that's the three uh outputs that we need to control so those are
going to be on q channels which would be outputs not eyes for inputs all right and so these are
our four inputs and our three outputs that we're going to do all of our control based on now the
next thing we need to do to actually add the stepper to our PLC program is to go to technology
objects and add a new object but skipping ahead here a little bit this pulse signal which is
hooked up to output zero via high speed output so we actually go to device configuration in Siemens
and again different platforms have different ways to enable this functionality but we go to the
properties of the PLC and we go to pulse generators for PTO and you can see it gives us options for
PTO 1 2 3 and 4 to enable these four channels as pulse generators so what we'll actually do
is we'll land our high speed pulse signal on channel 2 so we'll go ahead and enable this
pulse generator and leave everything else as a default for now it'll be on channel output 2
so we'll go back to our default tag table and we started labeling this at 2 let's actually go 2
3 and 4 okay so now we should have a pulse output that we made on channel 2 now when we go to
technology objects add new object we'll grab a positioning axis it's the only one in motion
control it'll by default it'll call itself axis one that's fine you can name it something else
if you want something else and then in general parameters it's asking us for a position unit
we'll say millimeters and we want to be pulse train output if you had a motor or a servo that
was expecting like a 0 to 10 volt dc analog connection you could set it up here and then
profi drive would be a drive that's uh actually using profinet to communicate but we'll go down
to the drive parameter and this is where it's looking for pulse generator so you have to have
set one of those channels up to do pulsing and here we'll grab pulse 2 and then we'll say the
pulse a direction b that's us saying there will be two different channels one will be the pulse
the other will be the direction there we go now you can put your enable output signal here but
one interesting thing is a lot of stepper motor controllers actually operate inverse of how the
siemens technology object wants to work so this might take a little guess and check if you put
your enable output here then when you enable the plc the output will turn on the problem is with
my stepper motor controller it's inverse of that so when we write the logic you'll see why i'm not
putting my enable output here and i'm just going to leave this blank for now and use the enable
signal slightly differently but if you get all green here that means that your drive parameters
are acceptable and you can go write some code to actually control it so let's make inside the main
let's go ahead and plan on just adding a function for basic motor control so we'll add a new block
it'll be a function we'll make it in ladder to keep it nice and easy and we'll name it motor
control motor control there we go okay and while i'm here on main so i don't forget i'll drop it
in there to make sure it's now being scanned feel free to check out my introduction to plc
programming if you're lost on that part we're going to add the basic functionality we can to
get this stepper moving and that'll be enough to tell us that we've done the basic setup correctly
so we're going to open the tab on the right called instructions and then we're going to go
down to motion control under technology and we'll start with the mc power button it'll prompt us to
the power instruction not button it'll prompt us to make a database for it that's fine
in axis we'll go ahead and point it at the axis that we just made and for enable let's go ahead
and point it at one of our inputs now we have the two input switches i've got some tape on the front
of my uh panel i labeled the second switch as enable so we'll just use that input just because
i already have the tape on it and that's actually all we need to do to make this power data block
uh tied to an enable input like i said earlier i actually have this digital output my enable
signal my stepper enable output actually behaves opposite of how the power db wants to behave
so i'm going to tie the mc power database status i'm going to tie it to an xio or normally open
contact so actually when power enabled is true my enable output will go away and when it's false
my enable output will turn on this is actually just something you need to check the specs on
your stepper motor controller because there are some where enable behaves active high and there
some where enable behaves active low for locking next block we'll add we'll do the motor control
reset and this is because anytime you're trying to set up a new motor and you have any kind of
issue like you trigger a parameter at the wrong time or you have an invalid velocity in there
it'll throw an error and you need some way to reset it now this one you don't actually need
to do anything special if you don't want to you can just make a memory bit so i'll make a global
memory bit and it'll just be a tag that i toggle from the plc if i wind up with an error and i need
to get this thing to reset that's because i don't plan on having a lot of errors and i'm doing this
for a tutorial but you might want a reset push button or something tied to your actual reset
command this will clear out any errors generated on that axis now let's go ahead and throw down
the actual exciting block the move relative block there's move absolute there's move relative and
there's move velocity and there's move jog there's a whole bunch of ways from any plc platform to
create movement some of them are based on homing so that you know where zero is and then all of
your movements are based on your physical position in space there's moves move relative which is
wherever you are move 10 millimeters that way 10 millimeters that way whatever there's move jog
where you just move in very slow small increments and you can find all the descriptions for these
different blocks from your oem but we're going to do a move relative so that we can demonstrate
this in a timely manner and again the axis will just get tied to the axis the velocity important
point here is this is based on whatever your units are so when we set up this axis and i said that it
was going to be in terms of millimeters if you did it in terms of pulses then the velocity would be
pulses per second so you might want a few thousand pulses per second but if i do millimeters and i
tell it that my drive is 400 pulses per millimeter and actually one thing i forgot when we were doing
the setup there's 400 pulses per motor revolution for this motor but i'm on a ball screw that's
four millimeters so actually those default values would have worked but it's important to make this
match your physical setup of the stepper motor configuration so i have 400 pulses per motor
revolution but i'm on a four millimeter pitch ball screw but if i had the general set to pulses
when i'm looking when i'm looking at my velocity here i would be putting in velocity in pulses per
second but because i'm looking at a value of millimeters i'll say the velocity is 15 millimeters
per second and i could go a little faster than this but i don't need to and distance will make
another global variable and we'll just call it step distance and we'll use our two push buttons
to move us forwards and backwards here in a second so let's define this new tag and we'll call it
global memory we'll make it a real is fine and we'll just define it as distance and then execute
is actually when we want the stepper to go again because i want to use my two push buttons to jog
forwards and jog backwards i'll make a new internal bit here and we'll just call it stepper go right
we'll make a new bit uh and call it go global memory tag will be fine we'll define it okay so
now we need to write a little code to listen to those two push buttons and uh move forwards or
backwards based on them so let's just come down here and let's say what did we have push button
one and push button two we'll say that we're because these are push buttons we're just going
to put in momentary uh rising edge triggers so we're only going to move these motors every time
there's a new push which means we have to make some new tags and my push button one is tied to
my tape that says reverse so we'll make a bit call it reverse memory it'll be global memory that's
fine it's just these one shot instructions and forward memory these one shot instructions need
a boolean to track where what the last value of their tag was so that they can tell if a tag
changed or not over time now let's add two instructions to each of these rungs the first
one will be a move where we're going to move a value into uh the stepper distance tag okay
so we're going to say we want to move 10 millimeters uh forwards on forward and 10
millimeters back on reverse and because we have bi-directional movement enabled on this axis
we can just say we want the distance to be negative 10 when reverse is pressed and the
distance to be forwards 10 when forward is pressed and then for both of these we're going to go ahead
and add a set instruction to that stepper go not enable go uh so that was the uh bit that we said
was actually going to be the execute move relative command here on our move relative block and so the
only thing we have to do now before we can actually test this out and see it work is make sure that
we're resetting step go when our move relative block finishes okay so we'll just come under here
under move relative and we'll just say when mc move relative db is done right then we'll just say
we want to reset stepper go okay so what should happen now is we push reverse and it goes back 10
millimeters we push forwards and it goes forwards 10 millimeters and uh every time it's finished it
resets itself and we can push the buttons again so we can just keep getting 10 millimeter movements
with our two push buttons we should be able to download to the plc and it finds my plc and let's
go ahead and download and see if we can get this motion working okay so now with everything wired
up with the motion axis set up in our plc we can put it all together with our setup okay so we have
hand switch one hand switch two push button one push button two hooked up to our inputs enable
direction and pulse hooked up to our three dc outputs so we should just be able to turn the
enable switch on so our driver is ready to go and so with it enabled we'll tell it reverse
it goes back forward it goes 10 millimeters add time and you can pretty easily see just how
accurate and repeatable this is i could have this run 50 times 100 times with little to no
calibration and within fractions of a millimeter this is going to return home every time okay so
that is going to do it for today's video i hope you found it useful and informative this is a
foundational aspect of industrial motion control for factories and it controls an automation let
me know if you have any questions in the comments below let me know what you'd like to see next on
the channel as well don't forget to leave a like on the video and subscribe to the channel
it helps me out a ton and we'll see you next time thanks bye