arduino library


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 003 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 amp 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. Amp. 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 amp.

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 gon Na 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.


arduino library Video







arduino library news








arduino library Social






👋 Want to bring Tony Stark-like gesture control to your projects? Learn how with the BLE-enabled MKR WiFi 1010 and Nano 33 BLE Sense boards using the ArduinoBLE library.
safe image.php?d=AQDyi1ELcW4VGzhx&w=720&h=720& dChOhNMmeF - arduino library

Arduin-yo ho ho! A fairground favorite, the pirate ship is a fun way to explore the oscillation of a pendulum. How much fun, you ask? Access our Science Kit Physics Lab preview and see for yourself:

🔬 Now that you’ve gotten your feet wet, dive into the kit and enjoy all nine experiments. Order yours today:

70537898 550174072395145 8798850142103928832 n.jpg? nc cat=102& nc oc=AQmCfMPwMf1oPpYqFhzbxfnGdbrmsjZXrEEBy1ox5Z8EJtiYMADoFNZ5mnSNRgCCY74& nc ht=scontent - arduino library
lI1VUK  normal - arduino library
Sat May 26 09:11:15 +0000 2018

RT @arduinolibs: Adafruit BusIO (1.0.5) for #arduino by @adafruit
This is a library for abstracting away UART, I2C…
lI1VUK  normal - arduino library
Sat May 26 09:11:15 +0000 2018

RT @arduinolibs: Adafruit Circuit Playground (1.9.1) for #arduino by @adafruit
All in one library to control Adafru…

LoRa Radio Shield(433MHz)



(Visited 100 times, 1 visits today)

About The Author

You might be interested in

Comment (20)

  1. What would be considered a good reading for your A4988 driver in your last experiment. My stepper motor has a .5 A current rating

  2. Outstanding tutorial Sir! In depth description and easy to understand, even for someone like myself who has no knowledge re Stepper Motors. I am currently working on a project and was wondering if you might be able to give me a few tips regarding the type/size stepper motors & appropriate driver controller recommended for my project. Plan to use two stepper motors, both with lead screws that would need to be controlled sequentially ( the one is to operate on a horizontal path and the other on a vertical ). They would need to push & pull an estimated weight of around 10kg. Is this feasible using Stepper Motors? Would really appreciate any feedback, thank you. Kind regards, Peter

  3. GREAT VIDEO! Thank you so much for sharing your knowledge. One little thing, there is a typo in the first part of the description. You have “28YBK-48” for the motor type; unless that is a real motor type. If it is and it is intentionally I apologize. I was curious, what is your background and training? Where did you learn all this?

  4. i saw many learning videos on youtube .they all are good but you are a legend sir . you expalning very clearly and fascinating way. which produce curiosity. thanks

  5. well sir i want you to create pick and place machine with inventry managment but i have no idea how to do that. please if you can give me step by step procedure with software and hardware. thanks

  6. I am building vertical tower garden. Which consists of 5 foot lengths of 4 inch PVC with holes arranged around the pipe every 6 inches down it. In those holes I will grow my vegetables. I would like to build a system with an Arduino or Raspberry Pi to rotate it 180 degrees and back for maximum sun exposure. I would like to connect these towers with some type of chain and a stepper motor that would turn a row of them, all at the same time. Could you offer any advice on the controller, gears, chain, motor, code(slow timing) or anything else that that would be relevant. Very informative channel, with information presented in a logical way. Keep up the good work!

  7. First of all thank you very much for this video and all others! I learned a lot about stepper motors from your videos and I would like to send you congratulations about your lecture and discourse! I’m amazed how you detailed teach and have thoroughly knowledge about electronics! So, I’ve chosen you to help me if you can please; I’ve made camera slider and motorized it with Arduino UNO, 28BYJ-48 stepper motor and ULN2003 driver but it is too slow and too weak for my camera slider. Now, I bought Nema 17 JK42HS40-1304F hybrid stepper motor and A4988 driver with Keyes expansion board but I don’t know how to write Arduino code to use it. I would appreciate so much if you can help me with a code! Best regards, DrScrew 🙂

  8. Subscribed, can you help me to run 48byj-28 stepper motor to run, in my project it is vibrating only and I connected it with 12 volts once, thanks in advance

  9. I send my salutations and appreciation along the line of Mr. Charley Edwards. I’m also retired, 67, spent my life in biological/biotech research and international research management. Now, retired, searching for a past-time offering great mental activity. I’ve tried advanced math, astronomy, and – now – electronics. Thus, stumbled onto your videos and am absolutely delighted to learn from you. Your presentation, though often using acronyms or abbrev’s unknown to me, is reassuring and comprehensive. Your approach to such a complex topic as electronics (to the novice) is well structured and fun to attempt to apply principles revealed and suggested. I am avidly digging through your past presentations in order to learn about setting up and controlling stepper motors in order to control telescope mounts via a hand-held remote. So far? Not so good, have ordered more materials to attempt it again and review your coverage of specific aspects of stepper function and arduino-based control. Fingers crossed, I’m trying to move forward but for a total novice in the field, it’s sadly missing something. So glad you’re here and presenting as you do. One last thing: I am SO envious of your accumulation of gear and parts and their organization is a great model to follow. Keep up the great programming!

  10. what is the limit of motor we can connect in this application? NEMA 17 would work with that as well? Great video!!!

  11. Thank you DroneBot Wokshop for providing code and detaild vidio instructions. I made 3 stepper motors run and tinkered with the code to go clock wise and counter clockwise “second demo”.


Your email address will not be published. Required fields are marked *