Stepper Motors with Arduino - Controlling Bipolar & Unipolar stepper motors

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today in the workshop we're going to work with stepper motors will learn how stepper motors work and what the difference is between a bipolar and a unipolar stepper we'll also see how we can use a uln to 0 0 3 and L 298 and H bridge and an a 4988 module to control our stepper motors it's a lot to cover but don't worry I'll take you through it one step at a time welcome to the workshop [Music] hey welcome to the workshop today we're going to be making some things move by using stepper motors now we've used motors and some of our other projects before we did a whole video on using brush DC motors along with an h-bridge controller and we've also used servo motors in some of our projects including the me arm robotic arm which made use of four servos but until now we have not done anything with stepper motors now stepper motors are very valuable devices that can be used in a number of different applications they're very good when you need a high torque motor when you need a motor that can position something very precisely a stepper is what you need and also if you need a motor that can move very very slowly without having to resort to a number of gears or pulleys a stepper is an ideal choice so let's take a look at how a stepper motor works now a stepper motor as the name would imply is a motor that moves in discrete steps after each step the motor holds itself in position internally a stepper motor consists of a magnetized geared shaft that is surrounded by electromagnets controlling the current in the electromagnets allows us to step the motor there are three different types of stepper motor design the variable reluctance stepper motor the permanent magnet stepper motor and the hybrid stepper motor these differences are primarily in the way that the magnetic field is created in the geared shaft now steppers are controlled by applying current to coils which in turn creates electromagnetism there are two different coil wiring arrangements that you need to be aware of the bipolar stepper motor consists of two sets of coils and usually has four wires two wires per coil the unipolar stepper motor also consists of two coils but each coil has a center tap unipolar stepper z' can have six connections but they often have five as the two Center taps are tied together now internally the coils in a stepper motor are actually split into several different sections steppers are available in a variety of different sizes and capabilities now stepper motors are used for a myriad of different applications 3d printers and CNC machines make extensive use of stepper motors because they need the precisely position either a printhead or a cutting head DVD and blu-ray drives make use of steppers so that they can position the laser precisely above the disk the older dot-matrix printers made use of steppers also to move their print heads the cameras I'm using here all have stepper motors in them to drive the zoom lens as steppers are used extensively in robotics you can even build an analog clock with a stepper motor by using a stepper that does 60 steps per rotation now as I showed you in the last animation there are two different types of coil windings that you'll encounter when you're using stepper motors the bipolar and the unipolar and so I want to show you how these different coil windings work because that's very important to know when you're working with stepper motors there are a number of differences between bipolar and unipolar stepper motors the bipolar stepper uses a four wire connection whereas a unipolar stepper uses a five or six wire connection now in order to reverse direction you need to be able to reverse the polarity of the voltage on a bipolar stepper however on a unipolar stepper you do not need to reverse polarity in order to reverse direction a bipolar stepper generally has higher torque because it makes full use of the coil windings within it the unipolar stepper only makes use of half of the windings and therefore has a lower torque because it uses the full coil windings however a bipolar stepper has a slower maximum speed as the coils have more inductance a unipolar stepper can spin faster but neither a bipolar or unipolar stepper is noted for spinning at a very fast speed now because of that voltage reversal the bipolar stepper needs a more advanced controller circuit than a unipolar stepper on a unipolar stepper you can simply control it with four transistors now let's take a look at some stepper operation we'll start with a bipolar stepper if we apply current to the top coil will notice that the rotor is attracted to that coil and locks itself into position if we then take the current off of that coil and apply it to the other coil the rotor is attracted to that coil this is an example of a full step clockwise now in this example you'll notice we've used the other coil and we've reversed the polarity of the current as we do this the bag that is attracted to that and when we apply current to the other coil is attracted to that one this is a full step counterclockwise now in this example we'll start off let the first one apply current to the first coil which attracts the magnet to it we will then apply current to the other coil but we won't remove it from the first coil and you'll notice that the motor position is halfway between the two coils if we then take the current off of the top coil and leave it on the second coil the motor moves and attracts it to that coil now this is an example of doing a half step clockwise and actually we can do quarter steps eight steps and sixteen steps by just varying the amount of current we apply to the two different coils now let's take a look at a unipolar stepper motor in a unipolar motor we constantly apply the positive voltage to the center tap and it is where we attach the negative voltage that determines the direction the motor is going to run it so if we take a negative voltage and apply it to the top coil the rotor will be attracted to that coil if we then take the voltage off of the top coil and apply the negative voltage to the bottom coil then the rotor will be attracted to that and this is a full step clockwise if we want to reverse the direction we simply apply two negative connection to the other end of the coil and this will cause the motor to move counterclockwise now that we've seen how stepper motors work I wanted to talk about how you would select a stepper motor for your project when you go to purchase stepper motors you'll notice that there are a mountain of specifications that are included with them and I could probably do a whole video on just understanding these specifications I won't do that but in order to try to cut the size of the mountain down I've got some of the key specifications here that you will need to know when you're picking out a stepper motor the step angle is a very important specification this indicates just how much the shaft advances for each step it's also sometimes rated as steps per revolution and the two figures are equivalent if for example I have a motor that has a step angle of 1.8 degrees per step that is the same thing as 200 steps per revolution you can calculate one from the other by just taking 360 and dividing it by the step angle to give you steps per revolution or dividing it by the steps per revolution to give you the step angle the voltage rating of the motor is obviously a very important consideration the current is also very important how much current will this motor require in order to achieve its specifications you'll need to know this when you're picking out a power supply for your stepper motor the coil resistance can be an important spec because this tells you how much current you can possibly put through the stepper motor at a given voltage inductance is an importance best vacation as well higher inductance means the stepper motor won't be able to spin as fast holding torque is a very important spec because it tells you how strong the motor is the holding torque is the amount of torque that the motor can exert when it is energized the detent torque on the other hand is the amount of torque the motor has when it is not energized the shaft style of the stepper motor can be important when your mating it up with gears and pulleys there are a number of different pfaff styles the round shaft and the D shaft are very common and those are usually used to mount pulleys a geared shaft refers to a stepper motor that already has gears integrated onto the shaft an elite screw shaft is very commonly used when you're building actuators one application of lead screw shaft stepper motors is the stepper motor used inside a CD or DVD drive now one other specification you'll need to know when picking out a stepper motor is the size of the stepper motor but one thing you need to know is that to steppers that are exactly the same size and dimensions aren't necessarily the same motor that can vary quite a bit in terms of the voltage one of them can be unipolar one of them can be bipolar a good example is a very common motor called the NEMA 17 or any ma 17 you'll find this design used in a lot of 3d printers now you can't just walk into your local electronics store and ask for a NEMA 17 and expect to get the correct motor they may indeed have a motor that's called a NEMA 17 but it might not be the motor that you need in order to illustrate this I've got a couple of examples over here these two motors that I have on my workbench are both called NEMA Seventeen's and as you can see they have the same size faceplate however they're very different motors this is a five wire unipolar motor and it runs on seven and a half volts whereas this is a four wire bipolar motor that runs on 12 volts you'll also notice that the shaft lengths of these are both different if these are both called NEMA 17 an actual fact NEMA or nem a is an abbreviation for the National Electrical Manufacturers Association and back in 1984 they set out a number of standards for motor sizes and motor specifications the number 17 here refers to the plate size of the front plate size and what you do is you divide that number by ten to get the approximate size of the plate so oedema seventeen as a face plate that's approximately 1.7 inches whereas a NEMA 23 is a face plate of approximately 2.3 inches the actual NEMA number can be extended even further to indicate things like voltage etc and if you're interested on the website in the associated article I've got links to charts that'll give you all the different NEMA specifications alright we've looked at a lot of stepper motor theory now it's time to put some of that theory into practice for the first couple of experiments I'm going to be using a very common stepper motor and Driver combination this is a two eight byj forty eight stepper motor and the driver is based on a UL n two zero zero three Darlington transistor array I've got the motor and the driver over here on the workbench to show you as you can see they're quite tiny these are available normally for under five dollars for both the driver and the motor and the reason they're so inexpensive is because this motor has been used in countless applications over the last couple of decades it's used in air conditioned or controlled ducts it's used in vending machines and lots of other apps so as a result they're manufactured by the millions and they're very very cheap you can get these on eBay or Amazon or probably at your local electronics store as well now the to eight BY j48 stepper is a stepper that runs on five volts and it's a unipolar stepper so it has five wires with the center top of each coil connected together it internally steps at thirty two steps per revolution but there's gearing already incorporated into the motor that reduces that by a factor of 64 so you actually get 2048 steps per revolution so let's take a look first of all at how we're going to hook this up to our Arduino and then at the sketch that we're going to be using to drive our stepper motor for our first experiment we'll need an arduino uno the UL n 2 0 0 3 motor controller board and a 2 8 byj 48 stepper motor will also need a separate 5 volt power supply under no circumstances should you attempt the power the stepper motor with the 5 volts from the arduino now first we'll connect the power supply up to the UL n 2 0 0 3 driver note the polarity next we will connect the ground from that power supply to the arduino is ground this is very important so that we establish the same voltage reference between the two after that we'll hook the motor cable from the stepper motor up to the driver board and now for our connections of the arduino pin 8 of the arduino we'll go to the in-1 pin on the UL n 2 0 0 3 pin 9 2 I and 2 pin tent in3 and pin 11 2 I an for now for this demonstration we're going to be making use of the arduino stepper library this is included in your arduino ide so there will be no extra library to add so we'll begin by including the stepper library next we're going to define three constants the two 8b y j48 stepper motor internally steps at 32 steps per revolution so we'll give that a constant steps per Rev and we'll set that the 32 however the motor has gear reduction and the gear reduction will reduce those steps by a factor of 64 so we'll give another float called gear read and we'll set it to 64 now I should note that some of these motors actually don't have that same gear reduction and so if your motor has a different gear reduction just change this number accordingly next we want to get the steps per geared output revolution in other words the final steps that the motor shaft will do and this distally by multiplying the previous to Constance in this case that will equal a value of 2048 steps will define one variable an integer called steps required and that's simply the number of steps that we require in order to turn next we're going to create an instance of the stepper class now one thing to note is that we've used pins 8 9 10 and 11 on the Arduino for our stepper motor and those are connected accordingly to the in-1 int I + 3 + I + 4 of the UL n 2003 motor driver however the sequencing on the stepper motor requires us to go 1 then 3 then 2 then 4 so when we set up the stepper motor class we're going to need to maintain that step sequence so we're going to do the steps per Rev which is 32 and we're going to give it the 4 pins that we are going to in the order of the sequence and so they're going to be 8 10 9 and 11 if you get this wrong your motor will not step correctly so make sure to pay attention to this now there's nothing in this setup because we don't need to set up the pins as outputs the step 4 library will do that for us so we'll go into the loop and in our loop I've just got three demonstrations of how to run the motor you can add additional ones if you wish so we'll take our separator object and we'll set it speed on the first example we're going to set it extremely slow as slow as it can go so we'll give it a speed of 1 we're going to give it 4 steps and we're going to go and step it through those 4 steps and this delay so what that will do is it will move the motor very very slightly and we can use the LEDs on the UL n 2003 driver board to observe the step sequence after that we're going to turn one half of a turn and we're going to do it relatively slowly so the number of steps required are the steps per output Rev which in my case is 2048 divided by 2 we're going to set the speed of the stepper motor to 100 which is a bit faster than before but is still rather slow and then we're going to step it by those number of steps required and then we'll delay a second after that we're going to rotate counterclockwise very quickly so we're going to set the number of steps to a negative value because we're going counterclockwise and again the steps per output Rev divided by 2 so remember the negative over here will make this turn counterclockwise in this case I'm setting the speed relatively fast to 700 which is near the top range for this motor you can experiment to see what the top range for your motor is and again we'll step it by the number of steps required which in this case will be negative 1024 and then we'll delay 2 seconds and then after that the loop just repeats over and over again so now that we've seen the sketch let's take a look at it in action so here's how I've hooked up our demonstration I've mounted the motor on a board you'll notice there's a second motor over here this is going to be for the next demonstration that we do but we'll ignore this one right now I've placed a little clip on the motor so that you can observe the shaft rotation a little easier now here's my uln 2 0 0 3 driver board and my arduino uno and here's my connection to my external 5 volt power supply so about the 5 volts connected up right now all I have to do is actually power up the Arduino Uno and we're ready to go because I've actually uploaded the sketch to it already so let's do that right now now as you recall the sketch starts by very slowly going through the motor sequence which you can observe on the LEDs on the driver board now we're going to go one half turn clockwise at a relatively slow speed once we've done our half turn we'll return counterclockwise at a quick speed and we'll start off all over again so we'll step it through four separate steps and then begin our clockwise rotation so as you can see the sketch works very well for our next experiment will leave the wiring that we had for the first experiment but we're going to add an additional uln to 0:03 driver board and another two eight byj 48 stepper motor once again we'll use the separate five volt power supply to supply power to the uln two zero zero three driver board will then connect the stepper motor to the driver board and now for our connections to the Arduino pin four of the Arduino will connect to in-1 on our new uln two zero zero three driver board pin five will go to in2 pin six to IM 3 and pin seven will go to i and four for this demonstration we're going to make use of another library called accel stepper now this is not included in your Arduino IDE so you will need to install it so go up to sketch and go to include library and go to manage libraries once the library manager is loaded search for excel Stepford you will likely find that this is not yet installed so click the more info button and then click the install button to install the library once the library has been installed you can close the library manager now let's get back to our sketch we'll start off by including that library so include excel stepper now we're going to define a couple of constants in this experiment we're going to drive one motor using full steps and the other one using half steps so we'll define a couple of constants for that next we need to define the pins that the two motors are using now motor one is using pins 8 9 10 and 11 this is the same connection we had with our previous experiment motor number two is going to be using pins four five six and seven now we're going to be setting up our stepper motors and remember the sequence for these motors is 1 3 2 4 as it was in our last experiment so the first step we're going to be driving at half steps and we'll set it up with motor pin 1 3 2 & 4 and the second stepper we are going to be doing at full steps and we're going to set it up with motor pins 5 7 6 & 8 now in the setup we need to define what a revolution for each motor is clockwise and counter clockwise so we're going to set a maximum speed of each to a thousand which is about as fast as these motors can go we'll set an acceleration factor for each of these as well because as the name will imply accel step can do acceleration and deceleration will set a regular speed of 200 and we're going to move it to position 2048 as you recall the 2 8 B Y j48 with its gearing will move 2048 steps per revolution we're going to do exactly the same thing for motor too except we'll do the move to to a negative 2048 because we wanted to move counterclockwise now we go into the loop now at the bottom of the loop you'll notice we have a stepper one run and a stepper to run the steppers aren't run until these statements are actually executed so they aren't run up in the setup routine as you might expect we have an if statement that checks both steppers to see if they've moved to the very maximum of their distance if they have the value distance to go we'll represent the number of steps left in the sequence if it is equal to zero then we're going to move it to the opposite end so we'll do a negative of its current position and move it back same thing for step or two and then as I said we will run step four one and run step or two now this is a bit different than using the step four library that we use previously but exactly more versatile so now that we've seen this let's take a look at it in action ok I've got our two stepper motors running right now a couple of things to observe first of all you'll notice that they're spinning in the opposite directions to one another secondly you should be able to notice that there's some acceleration and some deceleration involved over here it's not spinning at a constant speed now this is stepper motor number one and this is number two now number one is moving in half steps number two is moving in full steps and you can see a difference on the LEDs on the driver boards as they approach very slow speeds and this difference is due to the half steps versus the full steps and as you can see this works pretty well so now that we've worked with unipolar motors it's time to move on to bipolar motors now as you'll recall bipolar motors require you to be able to reverse the polarity of the current and the coils if you want to spin the motor in the opposite direction and an ideal device for doing this is an h-bridge controller now if you're not familiar with eight bridges I did a video on using eight bridges with DC motors and I'd advise you check that out to get more familiar with the operation of an H bridge but essentially an H bridge has for internal transistors that can be switched in order to reverse the polarity of the voltage that it applies to the motor and so that's ideal for a bipolar motor an ideal controller is the same controller that we used in that video the l2 98n because it has two H bridges in it which is perfectly suited for controlling one-step remoter that has two coils so in our next experiment we are going to use an l2 98n and a bipolar stepper motor and control that with the Arduino here's how we're going to hook up our experiment we'll need an Arduino Uno an l2 98n H bridge motor controller a bipolar stepper motor a power supply capable of supplying voltage for our stepper motor in my case is 12 volts DC but yours may be different and a potentiometer that we'll be using as a speed control any value above 10 we'll work well we'll start by hooking the data lines from the Arduino to the l2 98n we'll connect pin 8 from the Arduino to input one of the l2 98 n pin 9 to input 2 and tend to input 3 and pin 11 to input 4 next we'll connect their power supply to the l2 98n will also connect the ground from the l2 98n to the Arduinos ground now the next connection will vary depending on your l2 98 and module some l2 98 and modules have jumpers on the enable line which allows you to keep them high if that's the case fits place two jumpers on there if you don't have jumpers then connect both the enable a and enable B lines of the l2 98 n to the 5 volt power supply in your Arduino l2 98 n modules also have a jumper that determines whether their internal logic is powered by an external 5 volt supply or whether it's derived from the motor power supply using an on-board regulator if your jumper is in position then you don't need to make another voltage connection because your module will be powered by the motor power supply if however your jumper is not in position then you will need to connect the 5 volts from the Arduino to the l2 98 n 5 volt input now we'll connect our potentiometer to the Arduino the center tap of the potentiometer will be connected to the a 0 analog input on the arduino one side of the potentiometer will then be connected to 5 volts and the other side will be connected to the ground finally we'll connect our stepper motor one coil of the stepper motor will connect to the motor a connection on the l2 98n and the other coil will connect to motor be connected now this sketch is going to make use of the Arduino stepper library again so we'll start the sketch off by including the stepper library next we'll define a couple of Constance steps per revenue per revolution in the motor and in my case this is 200 now your motor may have a different number of steps per revolution and you can get that in the motor spec sheet and change the number accordingly speed control defines the analog port that have connected the potentiometer to and in this case it's a zero once again if you decide to use another port has change that next we're going to create an instance of the stepper class now in this case the sequence is 1 2 3 4 and this is connected to the L 298 motor driver input 1 2 3 & 4 so when we create an instance of the stepper class which I'm calling stepper NEMA 17 I have to specify the pins on the Arduino that I'm using which are 8 9 10 and 11 now once again I have nothing to do with in the setup routine and I move on to the loop now the first thing I do is I have an integer I call sensor reading which I assign to the value of the speed control using Arduinos analog read command now this is going to give me a value from 0 to 1023 because the analog to digital converter in the Arduino is a 10 bit converter I want to set that to a range from 0 to 100 so I'm going to use our delay nose map command and I'm going to set motor speed to the value that the map command arrives with a range of 0 to 1023 map to a range of 0 to 100 so this will give me a value of 0 to 100 when I turn to potentiometer then I'm going to set the motor speed now as long as the motor speed value is greater than 0 I'm going to change my motor speed I'm going to set the motor speed to that value over here using the set speed command and then I'm going to step one hundreds of a revolution and that is simply derived by taking steps per Rev and dividing it by 100 in my case this is going to step it two steps and then I'll repeat the loop over and over again and that will cause any changes in the motor speed potentiometer to be reflected in the motor speed so now that you've seen the sketch let's take a look at it in action so here's our bipolar stepper motor demo wire it up and ready to test as you can see I've got my Arduino Uno my l2 98n module here's a potentiometer I'm using to control the speed I've got 12 volts feeding in on this bus over here from my bench power supply and this bus over here is the 5 volt power supply from the Arduino now I've got my NEMA 17 motor mounted on a motor bracket over here I thought it would be easier to use it if it was mounted stationary and once again I've clipped a little clip on it so we can observe the rotation so right now it's all set up and ready to go so I'll just turn the potentiometer and the motor moves and as I turn the pot higher this is it maximum speed right now [Music] and I'll move it down I'm gonna move it to a very low speed right now one thing about steppers is that even at their lowest speed they still exhibit full torque and I don't know if you can see that but the LEDs on the l2 98n module indicate the state of the for input pins and you can sort of see them dancing through the sequence the stepper motor needs to fire off its coils so all in all another successful experiment so we've seen how we can control a bipolar stepper motor with an h-bridge and while that works very well it does actually put a lot of requirements on to our Arduino the Arduino has to actually figure out the step sequence itself and send that out to the 8th Bridge which in turn controls a stepper motor now there are other controllers that control stepper motors that are basically self-contained and that can be a lot easier to operate this is actually a good thing especially when you're trying to control a bunch of stepper motors for example if you're building a CNC machine or a 3d printer where you might have three or four stepper motors having one Arduino control all of them can take up a lot of the processing power in the Arduino and not leave you a lot of room to do anything else so I want to look at one of those controllers right now and this is one called the a 4988 and I've got one here in the workbench right now to show you now this little device over here is actually the a 4988 itself and this is a little tiny heatsink that is meant to be used with it and was meant to be placed onto the chip because this can get quite hot the a 4988 can handle 2 amperes as long as you put the heatsink on but without the heatsink it only has about half the capability now this device over here is a shield for the Arduino that actually allows you to mount up to four of these controllers and this would be something that would be really great for again a CNC machine or a 3d printer but in our experiment we're going to use the a 4988 by itself on a breadboard and you're also going to need a 100 micro farad capacitor along with this component because you require a decoupling capacitor that's mounted physically close to the device as you can see on the shield they've placed four capacitors right under the socket for the a forty nine eighty eight so now let's take a look at how we will wire this up and how much easier it is to control a stepper motor with a dedicated controller like the a forty nine eighty eight so let's take a look at the pinout for the a 4988 module the first two pins V Mott and ground are the voltage for the motor and this can be anything up to thirty volts the next four pins to be to a 1a and 1b are the connections to the motor itself the 2b and to a connections go to one coil on the motor while the 1a and 1b connection go to the other coil VDD and ground are the connections for the logic supply for the a 4988 and this can be anywhere from three to five and a half volts on the other side of the module the first pin is the enable pin this is an active low pin meaning if it is held low the module is enabled by default this pin is held low the next three pins ms one ms two and ms three control the microstepping mode of the a 4988 as shown in this chart you can step the module at full half quarter eighth or one sixteenth steps by controlling the logic levels on these three pins by default these are all held low so the a 4988 without any connections here will step the motor at a full step the next pin is the reset pin this is also an active low pin by bringing this low you will reset the module the next pin is the sleep pin also an act of open by bringing this pin low you will put the module into a low powered sleep mode by tying the reset and sleep pins together the module will always remain on the next pin is a step pin you feed pulses into this two-step the motor and finally the last pin is to control the direction of your motor now that we've seen the pin outs let's hook our module up to an Arduino in addition to the eighth 4988 and the Arduino will of course need the stepper motor a power supply for the stepper motor and the decoupling capacitor that could be physically close to the a 4988 this needs to be at least 47 micro farad's although I've used a 100 micro farad capacitor in my design first we'll connect the power from our Arduino to the a 4988 so we'll take the 5 volts from the Arduino and connect it to the VDD pin and our ground to the ground pin beside it next we'll connect the power from arm to our motor the positive to the V MOT pin and the negative to the ground pin we'll also hook our decoupling capacitor across this line make sure to observe polarity now for the logic connections pin 2 of the Arduino will be connected to the bottom pin the Direction pin on the e 4988 pin 3 will be connected to the Stepp pin will connect the reset and the sleep pins together and we are now ready to connect their motor one coil goes to the 2b and to a the other coil go to the 1a and 1b so now that we've seen our connection let's take a look at the schedule used to drive this here's the sketch we'll be using with the a 4988 now in this sketch I've chosen not to lose a library like the Arduino stepper library or the Excel stepper library but it should be noted that you can use those libraries with the a 4988 but we're going to do this without a library today so we'll start our sketch off by defining a couple of constants I've got two of them they're integers the first one is der pin and this is the pin on the Arduino that I've connected to the direction input on the a 4988 I chose to use pin two but actually any pin would work so you could change this if you need to the same for the next pin step pin goes to the step input on the a 4988 and I've assigned that to pin three the next constant we define is steps per Rev as we have in some of our previous sketches and this is the number of steps that the stepper motor will take in one revolution now in my case my stepper motor goes 200 steps per revolution if yours is different just change this number accordingly now into the Senate protein we need to set both the pins we've defined as output so we'll use the pin mode command to set both step pin and dirt pin as outputs and then we go into our loop now we're going to start our loop out by spinning our motor clockwise so we do a digital right to the dirt pin and we will send it high to drive the motor clockwise now for our first test we're going to spin the motor one rotation at a relatively slow speed so we're going to use a for loop and we're going to go from zero to the steps per Rev which in my case is 200 and that'll go one revolution and we will increment one by one and for every increment we're going to send the step pin high delay up by two thousand microseconds send it low and delay it by two thousand micro seconds and then repeat the whole thing this will cause a pulse to be emitted from the step pin and that will drive the step input on the a for 99-88 after we do that we're going to pause for one second and then we're going to reverse the motor we're going to send a counterclockwise so we'll do a digital right to the dirt pin and this time we'll send it low then we're going to go through a similar loop than before but the only thing we're going to do is we're going to go two rotations so we're going to go from zero two steps per Rev multiplied by two in my case this will be 400 and we'll increment by one every time and again we're going to send up pulses now I want to go twice the speed as before so I'm going to have the delay to 1000 microseconds so my pulses will be twice the frequency of the previous pulses then we'll pause for one more second and we repeat the loop and do it over and over again so now that you've seen the sketch let's take a look at it in action so here's our a for 99-88 set up on the breadboard and ready to test but before we use it there is one adjustment that you may need to make the a for 99-88 has a current limiting adjustment there is a tiny potentiometer that's probably difficult for you to see but it's at the very bottom of the module this needs to be adjusted to limit the maximum amount of current that it feeds a stepper motor now in order to determine what that amount is you'll need to take a look at the spec sheet for your stepper motor in the case of my motor it is 0.35 of an ampere now to make this adjustment there are two methods there is one method by using a voltage test point on the module itself and adjusting the potentiometer and then measuring that voltage in doing some mathematics the method I use however is to simply measure the actual current so I've placed an ammeter in series with one of the coils on my stepper motor and the way I'm going to adjust this is as follows right now I don't have 12 volts applied to the a 4988 however I do have five volts coming from my Arduino applied to it so what I'm going to do is temporarily take the step put remove it from the Arduino and attach it to the positive rail the five volts from the Arduino I'm then going to apply power to the a4 99-88 module now as you can see I'm measuring 0.33 of an ampere and that's absolutely fine as my motor is rated at 0.35 if this was incorrect however I would take a small screwdriver and a Justus potentiometer until I got a good reading once I've done this I will remove power from the stepper motor and then I will reconnect this to the Arduino all right now that we've reconnected to the Arduino I'm going to reset my Arduino and we can begin our demonstration I'll reapply power to the motor power supply and as you can see the demo seems to be working I do one turn clockwise at a slow speed and then two turns quickly counterclockwise another successful experiment I'd say well that about wraps it up for today's video and although it's been a very long video believe it or not we've only covered a fraction of what I could say about stepper motors there is another common module for driving stepper motors called an easy driver and we haven't talked about that today I had initially intended to do that but I felt the video was long enough as it is and as there's so much I can say about the easy driver module I decided that we will do another video in the future about driving steppers with the easy driver but even without the easy driver we've learned a lot today about steppers I've showed you a number of different ways you can drive them with an Arduino I've showed you the difference between bipolar and unipolar stepper and hopefully have inspired you to use stepper motors some of your own projects I would love to hear about the projects that you're building with stepper motors so please add some comments below the video I love getting your comments and I try to respond to them as quickly as I can now if you need the code for any of the experiments we've done today as always you can visit the drone bots workshop comm website you will find a link below the video that will send you right to the article that corresponds to this video and in the article you will find listings of all the code as well as a zip file you can download that has all of the code that you've seen in the video so please use that as a resource and I hope you find it useful now once again I would like to thank you very much for taking the time to join me today and I hope to see you again very soon in the workshop if you haven't subscribed to the channel please subscribe it would mean a great deal to me until then take care of yourself and I hope to see you soon [Music]
Info
Channel: DroneBot Workshop
Views: 1,331,921
Rating: 4.9338512 out of 5
Keywords: Stepper Motor (Engine Category), stepper, motor, Arduino, ULN2003A, L298N, A4988, NEMA 17, 28BJY-48, microstepping, motor controller, stepper motor, Accelstepper Library, Bipolar Stepper, Unipolar Stepper
Id: 0qwrnUeSpYQ
Channel Id: undefined
Length: 50min 22sec (3022 seconds)
Published: Sat Feb 10 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.