{"id":9992,"date":"2022-06-30T05:35:11","date_gmt":"2022-06-30T09:35:11","guid":{"rendered":"https:\/\/itp.nyu.edu\/physcomp\/?page_id=9992"},"modified":"2022-11-06T18:21:53","modified_gmt":"2022-11-06T23:21:53","slug":"lab-controlling-a-stepper-motor-with-a-step-and-direction-driver","status":"publish","type":"page","link":"https:\/\/itp.nyu.edu\/physcomp\/labs\/motors-and-transistors\/lab-controlling-a-stepper-motor-with-a-step-and-direction-driver\/","title":{"rendered":"Lab: Controlling a Stepper Motor With a Step and Direction Driver"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Introduction\"><\/span>Introduction<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In the <a href=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/motors-and-transistors\/lab-controlling-a-stepper-motor-with-an-h-bridge\/\">stepper motor and H-bridge<\/a> lab, you learned how to control a <a href=\"https:\/\/itp.nyu.edu\/physcomp\/lessons\/stepper-motors\/\">stepper motor<\/a> with a dual H-bridge driver, specifically the TB6612FNG. This is not the only driver for controlling a stepper. <strong>Step &amp; direction stepper drivers<\/strong> offer a simpler approach, from the microcontroller side. They have just two control pins, one for step and one for direction. They also feature configuration pins that let you set the step pin to move the motor a full step, a half step, or less. This is called <strong>microstepping<\/strong>, and you can find stepper drivers that will work as low as 1\/256th of a step. This allows finer control over the stepper motor. In this lab you&#8217;ll learn how to use a step &amp; direction controller to control a stepper motor.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_Youll_Need_to_Know\"><\/span>What You\u2019ll Need to Know<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To get the most out of this lab, you should be familiar with the following concepts. You can check how to do so in the links below:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/soldering\/\">How to solder up a connector<\/a><\/li><li><a href=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/components\/\">Electronic components<\/a><\/li><li><a href=\"https:\/\/itp.nyu.edu\/physcomp\/lessons\/dc-motors-the-basics\/\">How DC Motors work<\/a><\/li><li><a href=\"https:\/\/itp.nyu.edu\/physcomp\/lessons\/stepper-motors\/\">How Stepper Motors work<\/a><\/li><li><a rel=\"noopener\" href=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/motors-and-transistors\/using-a-transistor-to-control-high-current-loads-with-an-arduino\/\">How to use transistors to control high current loads with Arduino<\/a><\/li><li>It&#8217;s useful to know about <a href=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/motors-and-transistors\/lab-controlling-a-stepper-motor-with-an-h-bridge\/\" data-type=\"page\" data-id=\"1768\">stepper motor control using an H-bridge<\/a> for comparison as well.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Things_Youll_Need\"><\/span>Things You\u2019ll Need<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<figure class=\"wp-block-gallery columns-4 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"2224\" height=\"1668\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-arduino-nano-33-iot.jpg\" alt=\"Photo of an Arduino Nano 33 IoT module. The USB connector is at the top of the image, and the physical pins are numbered in a U-shape from top left to bottom left, then from bottom right to top right.\" data-id=\"5921\" data-full-url=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-arduino-nano-33-iot.jpg\" data-link=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/labs-arduino-digital-and-analog\/digital-input-and-output-with-an-arduino\/pcomp-kit-f2019-arduino-nano-33-iot\/\" class=\"wp-image-5921\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-arduino-nano-33-iot.jpg 2224w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-arduino-nano-33-iot-768x576.jpg 768w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-arduino-nano-33-iot-1280x960.jpg 1280w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption class=\"blocks-gallery-item__caption\">Arduino Nano 33 IoT<\/figcaption><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"3836\" height=\"2877\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-breadboard.jpg\" alt=\"Photo of a solderless breadboard. The . board is turned sideways so that the side rows are on top and bottom in this view. There are no components mounted on the board.\" data-id=\"5909\" data-full-url=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-breadboard.jpg\" data-link=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/labs-arduino-digital-and-analog\/digital-input-and-output-with-an-arduino\/pcomp-kit-f2019-breadboard\/\" class=\"wp-image-5909\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-breadboard.jpg 3836w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-breadboard-768x576.jpg 768w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-breadboard-1280x960.jpg 1280w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption class=\"blocks-gallery-item__caption\">A solderless breadboard with two rows of holes along each side.<\/figcaption><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"400\" height=\"407\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/STSPIN220_Stepper_driver.png\" alt=\"A motor driver IC on a 0.1&quot; spacing breakout board\" data-id=\"10005\" data-full-url=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/STSPIN220_Stepper_driver.png\" data-link=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/motors-and-transistors\/lab-controlling-a-stepper-motor-with-a-step-and-direction-driver\/stspin220_stepper_driver\/\" class=\"wp-image-10005\"\/><figcaption class=\"blocks-gallery-item__caption\">Stepper motor driver model STSPIN220<\/figcaption><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"4217\" height=\"3163\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-jumper-wires.jpg\" alt=\"Photo of flexible jumper wires. These wires are quick for breadboard prototyping, but can get messy when you have lots of them on a board.\" data-id=\"5908\" data-full-url=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-jumper-wires.jpg\" data-link=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/labs-arduino-digital-and-analog\/digital-input-and-output-with-an-arduino\/pcomp-kit-f2019-jumper-wires\/\" class=\"wp-image-5908\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-jumper-wires.jpg 4217w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-jumper-wires-768x576.jpg 768w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-jumper-wires-1280x960.jpg 1280w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption class=\"blocks-gallery-item__caption\">Flexible jumper wires.<\/figcaption><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"400\" height=\"308\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/ID918_MED.jpg\" alt=\"Photo of a stepper motor. This motor is approximately 2 inches (5cm) on diameter, with an off-center shaft at the top, and wires protruding from the bottom. You can tell a stepper motor from a DC motor because steppers have at least four wires, while regular DC motors have two.\" data-id=\"1772\" data-full-url=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/ID918_MED.jpg\" data-link=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/motors-and-transistors\/lab-controlling-a-stepper-motor-with-an-h-bridge\/id918_med\/\" class=\"wp-image-1772\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/ID918_MED.jpg 400w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/ID918_MED-300x231.jpg 300w\" sizes=\"(max-width: 400px) 85vw, 400px\" \/><figcaption class=\"blocks-gallery-item__caption\">a stepper motor<\/figcaption><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"1000\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/DC_power_jack.jpg\" alt=\"A DC power jack. It pairs with a plug with a 2.1mm inside diameter, 5.5mm outside diameter plug, and has screw terminals on the back so that you can attach wires to it.\" data-id=\"4696\" data-full-url=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/DC_power_jack.jpg\" data-link=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/breadboard\/dc_power_jack\/\" class=\"wp-image-4696\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/DC_power_jack.jpg 1000w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/DC_power_jack-150x150.jpg 150w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/DC_power_jack-768x768.jpg 768w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption class=\"blocks-gallery-item__caption\">A DC Power Jack<\/figcaption><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"400\" height=\"601\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/dc_power_supply.jpg\" alt=\"DC Power Supply. Shown here is a +12 Volt 1 Amp Center Positive DC power supply with a 2.1mm male jack. This size fits the Arduino Uno's female jack.\" data-id=\"300\" data-full-url=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/dc_power_supply.jpg\" data-link=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/motors-and-transistors\/using-a-transistor-to-control-a-high-current-load\/dc_power_supply\/\" class=\"wp-image-300\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/dc_power_supply.jpg 400w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/dc_power_supply-199x300.jpg 199w\" sizes=\"(max-width: 400px) 85vw, 400px\" \/><figcaption class=\"blocks-gallery-item__caption\">DC Power Supply<\/figcaption><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"425\" height=\"640\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/multimeter1.jpg\" alt=\"Multimeter tool. This tool has a dial to set the function, and three holes into which to plug the testing leads. The leads are currently plugged into the center hole and the right hand hole.\" data-id=\"1592\" data-full-url=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/multimeter1.jpg\" data-link=\"https:\/\/itp.nyu.edu\/physcomp\/resources\/parts-needed-for-physical-computing\/multimeter-2\/\" class=\"wp-image-1592\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/multimeter1.jpg 425w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/multimeter1-199x300.jpg 199w\" sizes=\"(max-width: 425px) 85vw, 425px\" \/><figcaption class=\"blocks-gallery-item__caption\">Multimeter. You&#8217;ll need this to check the coils and  set the motor driver&#8217;s current limit.<\/figcaption><\/figure><\/li><\/ul><figcaption class=\"blocks-gallery-caption\">Figures 1-8. The parts you\u2019ll need for this exercise.<\/figcaption><\/figure>\n\n\n\n<p>The motor shown in the images here is a <a href=\"https:\/\/www.adafruit.com\/product\/858\">5V Small Reduction Stepper Motor, 32-Step, with  1:16 Gearing<\/a>. This motor is a useful starter motor for steppers because it can run on the current and voltage supplied by your Arduino without an external power supply. The driver is a STMicro <a href=\"https:\/\/www.pololu.com\/file\/0J1624\/STSPIN220.pdf\">STSPIN220<\/a> on a&nbsp;<a href=\"https:\/\/www.pololu.com\/product\/2876\">Pololu breakout board<\/a>. There are a <a href=\"https:\/\/itp.nyu.edu\/physcomp\/lessons\/stepper-motors\/#Step_Direction_Stepper_Drivers\">number of other step &amp; direction motor drivers<\/a> available if the STSPIN220 doesn&#8217;t meet your needs. Control for all of them will be similar to what you see below. In fact, Pololu makes a number of carrier boards for different step &amp; direction drivers, all with the same pin layout.  The principles in this lab, and the library used, will work with other stepper motors and step &amp; direction drivers as well, though you will have to make some modifications depending in which parts you are using.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Good_Safety_Practice\"><\/span>Good Safety Practice<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>When you&#8217;re working with motors, you&#8217;re often dealing with high voltage, high current, or both. You should be extra careful never to make changes to your circuit while it is powered. If you need to make changes, unplug the power, make your changes, inspect your changes to be sure they are right, and then reconnect power.<\/p>\n\n\n\n<p>It&#8217;s also a good idea to disconnect your motor from your circuit before uploading new code to your microcontroller. Often the current draw of the motor will cause the microcontroller to reset, and cause uploading problems. To avoid this, disconnect your motor before uploading, and reconnect it after uploading. <\/p>\n\n\n\n<p>Because motors consume a lot of current when they start up, it&#8217;s common to add a decoupling capacitor of 10-100 \u00b5F near the voltage input to your driver and\/or microcontroller. You&#8217;ll see this in the figures below. It will smooth out any voltage changes that occur as a result of the motor&#8217;s changing current consumption.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Prepare_the_breadboard\"><\/span>Prepare the breadboard<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Connect power and ground on the breadboard to power and ground from the microcontroller. On the Arduino module, use the 5V or 3.3V (depending on your model) and any of the ground connections, as shown in Figures 9 and 10.<\/p>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabTemplate_bb.png\"><img loading=\"lazy\" decoding=\"async\" width=\"559\" height=\"365\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabTemplate_bb.png\" alt=\"An Arduino Uno on the left connected to a solderless breadboard, right.\" class=\"wp-image-2159\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabTemplate_bb.png 559w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabTemplate_bb-300x195.png 300w\" sizes=\"(max-width: 559px) 85vw, 559px\" \/><\/a><figcaption>Figure 9. Breadboard drawing of an Arduino Uno on the left connected to a solderless breadboard on the right<\/figcaption><\/figure>\n\n\n\n<p>Figure 9 shows an Arduino Uno on the left connected to a solderless breadboard, right. The Uno&#8217;s 5V output hole is connected to the red column of holes on the far left side of the breadboard. The Uno&#8217;s ground hole is connected to the blue column on the left of the board. The red and blue columns on the left of the breadboard are connected to the red and blue columns on the right side of the breadboard with red and black wires, respectively. These columns on the side of a breadboard are commonly called the buses. The red line is the voltage bus, and the black or blue line is the ground bus.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter is-resized\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabTemplateNanoShort_bb.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabTemplateNanoShort_bb.png\" alt=\"Arduino Nano on a breadboard.\" class=\"wp-image-5903\" width=\"228\" height=\"359\"\/><\/a><figcaption>Figure 10. Breadboard view of an Arduino Nano mounted on a solderless breadboard.<\/figcaption><\/figure><\/div>\n\n\n\n<p><em>Made with <a href=\"http:\/\/fritzing.org\/home\/\">Fritzing<\/a><\/em><\/p>\n\n\n\n<p>As shown in Figure 10, the Nano is mounted at the top of the breadboard, straddling the center divide, with its USB connector facing up. The top pins of the Nano are in row 1 of the breadboard.<\/p>\n\n\n\n<p>The Nano, like all Dual-Inline Package (DIP) modules, has its physical pins numbered in a U shape, from top left to bottom left, to bottom right to top right. The Nano&#8217;s 3.3V pin (physical pin 2) is connected to the left side red column of the breadboard. The Nano&#8217;s GND pin (physical pin 14) is connected to the left side black column. These columns on the side of a breadboard are commonly called the buses. The red line is the voltage bus, and the black or blue line is the ground bus. The blue columns (ground buses) are connected together at the bottom of the breadboard with a black wire. The red columns (voltage buses) are connected together at the bottom of the breadboard with a red wire.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_the_Stepper_Motor_Works\"><\/span>How the Stepper Motor Works<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>A stepper motor is basically two motor coils in one motor, which allows you to turn the motor in steps. For more on this, see this <a href=\"https:\/\/itp.nyu.edu\/physcomp\/lessons\/stepper-motors\/\">stepper motor page<\/a>.<\/p>\n\n\n\n<p>The motor shown in this lab, a <meta charset=\"utf-8\"><a href=\"https:\/\/www.adafruit.com\/product\/858\">5V Small Reduction Stepper Motor, 32-Step, with  1:16 Gearing<\/a>, is typical of a class of stepper motors you can find using the designation 28BYJ-48. They come in a few varieties. There are 5V and 12V models, and there are versions like the one shown here, that have a gearbox on the top to increase their torque and increase the number of steps per revolution. The un-geared models have as few as 32 steps per revolution. This model has 32 steps per revolution and a 1\/16 reduction gear box, giving it 32 * 16, or 512 steps per revolution. You can find models with an even higher reduction as well.<\/p>\n\n\n\n<p>A stepper motor like this one has two coils to control it as shown in Figure 11. Each coil has a center connection as well, and the center connections are joined together, which is what makes this a <strong>unipolar stepper<\/strong>. If you don&#8217;t connect the center connection, then the motor will work like a <strong>bipolar stepper<\/strong>, each coil operating independently. This is how you&#8217;ll use it for this exercise. Each coil will connect to one control channel of the motor driver. The pink and orange wires are connected to the first coil. They will connect to one channel of the motor driver, while the yellow and blue wires are the other coil, and will connect to the other channel of the bridge (channel B). In this case, the red wire, pin 1, will not be used.<\/p>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/stepper_motor_schem.png\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"277\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/stepper_motor_schem-300x277.png\" alt=\"Schematic drawing of a stepper motor. A circle represents the motor, and two coils to the left and bottom of the circle represent the coils. The ends of the left coil are labeled pink and orange. The ends of the bottom coil are labeled yellow and blue. The middles of both coils are connected together, and labeled red. The red connection will not be used in this example.\" class=\"wp-image-1785\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/stepper_motor_schem-300x277.png 300w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/stepper_motor_schem.png 786w\" sizes=\"(max-width: 300px) 85vw, 300px\" \/><\/a><figcaption>Figure 11. Schematic drawing of a stepper motor.<\/figcaption><\/figure><\/div>\n\n\n\n<p>A bipolar stepper motor typically omit the red wire and just have two independent coils. A bipolar model like this <a href=\"https:\/\/www.pololu.com\/product\/1204\">3.9V NEMA-8 stepper<\/a> from Pololu would also work with this lab.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Check_the_Motor_Coils_Resistance\"><\/span>Check the Motor Coils&#8217; Resistance<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The wiring pattern in Figure 11 is typical, for the 28BYJ-48 motors. Nonetheless, it&#8217;s a good idea to check the wiring   by measuring the coil resistance. The motor shown here has a coil resistance (impedance) of about 42 ohms. For a bipolar motor, each pair of coils (e.g. blue and yellow, orange and pink) would give you the motor&#8217;s rated coil resistance. Since this is a unipolar motor, you should read approximately 22-24 ohms across red and each of the other wires, and about 42-45 ohms across each pair (blue-yellow and orange-pink). <\/p>\n\n\n\n<p>The sequence of the wires on the motor&#8217;s connector may vary from one manufacturer to another, so it&#8217;s a good idea to measure the resistance, then write down the pin order for reference later on. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_The_Motor_Driver_Works\"><\/span>How The Motor Driver Works<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The STSPIN220 can handle a motor&nbsp; supply voltage from 1.8 to 10V, and&nbsp; it operates on a logic voltage of 3.3\u20135V. It can control an output current of 1.1A per coil. <\/p>\n\n\n\n<p>The motor driver has the following pins. The pin numbers shown here are for the Pololu breakout board. The pins are numbered here in a DIP fashion, in a U-shape from top left to bottom left, then bottom right to top right. The list below describes the pins in numeric order.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Enable &#8211; enables the driver when you take it LOW&nbsp; and disables it when you take it HIGH. The breakout board pulls this pin LOW by default, so if you don&#8217;t connect it, your motor should work fine. <\/li><li>Mode 1 -Configuration pin for microstepping<\/li><li>Mode 2 &#8211; Configuration pin for microstepping<\/li><li>1 &#8211; not connected by default<\/li><li>2 &#8211; not connected by default<\/li><li>Standby &#8211; Puts the the driver in a low-power standby mode and disables the motor when you take it LOW. <\/li><li>Step\/Mode 3 -When you pulse this pin HIGH then LOW, the motor moves forward one step. Also functions as  a configuration pin for microstepping.<\/li><li>Dir\/Mode 4&nbsp;&#8211; When you pulse this pin HIGH, the motor in one direction when you pulse the step pin. When you take it LOW, it moves in the other. Also functions as  a configuration pin for microstepping.<\/li><li>Ground &#8211; ground<\/li><li>V<sub>cc<\/sub> &#8211; Logic voltage. Connect this to the Vcc of your microcontroller, for example 5V for an Uno or 3.3V for a Nano 33 IoT<\/li><li>A1 &#8211; Motor output coil 1<\/li><li>A2 &#8211; Motor output coil 1<\/li><li>B2 &#8211; Motor output coil 2<\/li><li>B1 &#8211;&nbsp;Motor output coil 2<\/li><li>Ground &#8211;&nbsp;ground<\/li><li>V<sub>MOT<\/sub> &#8211;&nbsp;motor voltage supply input, 1.8-10V.<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Connect_the_Motor_Driver_and_Set_the_Current_Limit\"><\/span>Connect the Motor Driver and Set the Current Limit<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Many step and direction drivers like the STSPIN220 have an adjustable current limit built into the driver. This lets you set the maximum output current to match the current your motor needs. Pololu has a <a href=\"https:\/\/youtu.be\/89BHS9hfSUk\">video explaining this process<\/a>. <strong>This is important, because if you don&#8217;t set the current limit correctly, you risk damaging the driver and the motor.<\/strong> The details follow here. You have to know your motor&#8217;s  desired current, then you use a formula to work out the value of a current limiting resistor for the driver.  <\/p>\n\n\n\n<p>If you have the motor&#8217;s current from the datasheet (110mA for the motor listed above), then you&#8217;re all set. If you don&#8217;t, you can calculate it from the motor&#8217;s voltage and the resistance of its coils. First, measure the resistance of one coil, as explained in the <a href=\"https:\/\/itp.nyu.edu\/physcomp\/lessons\/stepper-motors\/#Bipolar_stepper_motors\">stepper motor lesson<\/a>. Remember that current, voltage, and resistance are all related using the formula<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Voltage = Current * Resistance<\/pre>\n\n\n\n<p>For example, if your motor&#8217;s coil resistance reads 45.4 ohms, and it runs on 5 volts, then the current = 5 \/ 45.4, or about 110 mA. <\/p>\n\n\n\n<p>To prepare for this, connect the STSPIN220 board as shown in Figures 12 and 13. <strong>Do not connect a motor yet. <\/strong>You&#8217;re powering the board up just so you can set the current limit. <\/p>\n\n\n\n<p>The board is mounted straddling the center row of a breadboard, and the following pins on the STSPIN220 are connected:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Pin 1, Enable &#8211; connected to the ground bus on the left side of the breadboard<\/li><li>Pin 9, Ground &#8211; connected to the ground bus on the right side of the breadboard<\/li><li>Pin 10, V<sub>cc<\/sub> &#8211; Logic voltage. Connected to the voltage bus on the right side of the breadboard<\/li><li>Pin 15, Ground &#8211;&nbsp;connected to the ground bus on the right side of the breadboard<\/li><li>Pin 16, V<sub>MOT<\/sub> &#8211;&nbsp;Connected to the voltage bus on the right side of the breadboard. If you were using an external power supply for a higher voltage stepper motor, you would connect this to the positive terminal of the external supply.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"568\" height=\"312\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabSTSPIN220CurrentLimitUno_bb.png\" alt=\"Breadboard view of an SDSPIN220 stepper motor driver on a breadboard, powered by 5V from an Arduino Uno. \" class=\"wp-image-10026\"\/><figcaption>Figure 12. Breadboard view of an SDSPIN220 stepper motor driver on a breadboard, powered by 5V from an Arduino Uno. Multimeter leads are touching the trimmer pot of the STSPIN220 and the ground pin, to read the current limiting voltage. <\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"394\" height=\"318\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabSTSPIN220CurrentLimitNano_bb.png\" alt=\"Breadboard view of an SDSPIN220 stepper motor driver on a breadboard, powered by 3.3V from an Arduino Nano 33 IoT. \" class=\"wp-image-10027\"\/><figcaption><meta charset=\"utf-8\">Figure 13. Breadboard view of an SDSPIN220 stepper motor driver on a breadboard, powered by 3.3V from an Arduino Nano 33 IoT. <meta charset=\"utf-8\">Multimeter leads are touching the trimmer pot of the STSPIN220 and the ground pin, to read the current limiting voltage. <\/figcaption><\/figure>\n\n\n\n<p>Pololu makes its step &amp; direction driver boards with a built-in trimmer potentiometer to act as a current limiting resistor. It&#8217;s usually at the bottom of the board. Calculating the value of this resistor is explained in detail in <a href=\"https:\/\/www.pololu.com\/file\/0J1624\/STSPIN220.pdf\">section 6 of the STSPIN220 data sheet<\/a>. Pololu have summarized it in a formula below. <\/p>\n\n\n\n<p>To set the current limit, you power up the driver <strong>without a motor attached<\/strong> and measure the voltage between this trimmer pot and ground. Then you turn the trimmer pot until you read the reference voltage for the current limit, or VR<sub>EF<\/sub>. In Figures 12 and 13 there are multimeter probes shown, used to measure voltage. The red probe (positive) is touching the trimmer pot on the STSPIN220 and the black probe (negative) is touching pin 9, the ground pin. Set your multimeter to read voltage in the range of your V<sub>cc<\/sub> (3.3 to 5V), then touch the leads to the trimmer pot and to ground as shown in figures 12 and 13. You should get a voltage between zero and V<sub>cc<\/sub>. Then turn the pot with a small screwdriver until you read your desired V<sub>REF<\/sub>. <\/p>\n\n\n\n<p>For the STSPIN220, the current limit formula is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Current= VRef * 5<\/pre>\n\n\n\n<p>Rearranging that to get the voltage on the trimmer pot:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">VRef = Current \/ 5<\/pre>\n\n\n\n<p>So, if your desired current is 110 mA, or 0.11 A, then V<sub>REF<\/sub> = 0.11 \/ 5, or 0.022V. Turn your pot until the voltage reads that value (or whatever you calculated it to be for your motor) and you&#8217;re ready to go.  The trimmer pot is small and difficult to turn, so try to get in the general range of your  V<sub>REF<\/sub>. You probably won&#8217;t get it exactly. If you find the motor or the driver is excessively hot while running (if you can&#8217;t touch it comfortably) then you should re-adjust the trimmer pot to get closer to your proper  <meta charset=\"utf-8\">V<sub>REF<\/sub><meta charset=\"utf-8\">.<\/p>\n\n\n\n<p>You can now disconnect from your power supply, add the motor, and reconnect to program the microcontroller. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Connect_the_Motor\"><\/span>Connect the  Motor<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This motor nominally runs on 5 volts. It will run as low as 3.3 volts if you give it enough current (about 110 mA). It can run on the current supplied to an Uno or Nano 33 IoT&#8217;s USB connection. Ideally, though, you should run it from an external power supply, as described later in the lab.<\/p>\n\n\n\n<p>To finish your stepper motor circuit, connect the motor according to Figures 14 through 16. <\/p>\n\n\n\n<p>Table 1 below describes the pin connections for the circuit.  The STSPIN220 is still connected to the breadboard as shown previously in figures 12  and 13, but now the motor&#8217;s coils are connected to pins 11 &#8211; 14 of the motor driver and the driver&#8217;s step and direction pins (pins 7 and 8 respectively) are connected to digital output pins 2 and 3 of the Arduino, respectively. The two mode pins (pins 2 and 3) are connected to ground, and the standby pin (pin 6) is connected to V<sub>cc<\/sub> through a 10-kilohm resistor.<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th>Motor Driver Physical pin number<\/th><th>Pin function<\/th><th>Circuit Connection<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Enable<\/td><td>Ground<\/td><\/tr><tr><td>2<\/td><td>Mode 1<\/td><td>Ground<\/td><\/tr><tr><td>3<\/td><td>Mode 2<\/td><td><meta charset=\"utf-8\"><meta charset=\"utf-8\">Ground<\/td><\/tr><tr><td>4<\/td><td>1<\/td><td><meta charset=\"utf-8\"><meta charset=\"utf-8\">not connected<\/td><\/tr><tr><td>5<\/td><td>2<\/td><td><meta charset=\"utf-8\"><meta charset=\"utf-8\">not connected<\/td><\/tr><tr><td>6<\/td><td>Standby<\/td><td>10-kilohm resistor to V<sub>cc<\/sub><\/td><\/tr><tr><td>7<\/td><td>Step<\/td><td>Arduino digital pin 2<\/td><\/tr><tr><td>8<\/td><td>Direction<\/td><td><meta charset=\"utf-8\">Arduino digital pin 3<\/td><\/tr><tr><td>9<\/td><td>Ground<\/td><td>Ground<\/td><\/tr><tr><td>10<\/td><td>V<sub>cc<\/sub><\/td><td>Arduino V<sub>cc<\/sub> (3.3 or 5V)<\/td><\/tr><tr><td>11<\/td><td>A1<\/td><td>Motor coil 1<\/td><\/tr><tr><td>12<\/td><td>A2<\/td><td><meta charset=\"utf-8\">Motor coil 1<\/td><\/tr><tr><td>13<\/td><td>B2<\/td><td><meta charset=\"utf-8\">Motor coil 2<\/td><\/tr><tr><td>14<\/td><td>B1<\/td><td><meta charset=\"utf-8\">Motor coil 2<\/td><\/tr><tr><td>15<\/td><td>Ground<\/td><td>Ground<\/td><\/tr><tr><td>16<\/td><td>V<sub>MOT<\/sub><\/td><td>Arduino V<sub>cc<\/sub> if using USB power.  Arduino V<sub>in<\/sub> if using an external power supply.<\/td><\/tr><\/tbody><\/table><figcaption>Table 1. STSPIN220 connections to Arduino circuit<\/figcaption><\/figure>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"830\" height=\"600\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/STSPIN220_Stepper_schem.png\" alt=\"Schematic drawing of a stepper motor and STSPIN220 motor driver connected to an Arduino. The connections are described in the body of this page.\" class=\"wp-image-10073\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/STSPIN220_Stepper_schem.png 830w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/STSPIN220_Stepper_schem-768x555.png 768w\" sizes=\"(max-width: 830px) 85vw, 830px\" \/><figcaption>Figure 14. Schematic diagram of an STSPIN220 stepper motor driver and stepper motor connected to an Arduino. <\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"962\" height=\"400\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabSTSPIN220StepperUno_bb.png\" alt=\"Breadboard drawing of a stepper motor and STSPIN220 motor driver connected to an Arduino Uno. The connections are described in the body of this page.\" class=\"wp-image-10075\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabSTSPIN220StepperUno_bb.png 962w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabSTSPIN220StepperUno_bb-768x319.png 768w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption>Figure 15. Breadboard diagram of an STSPIN220 stepper motor driver and stepper motor connected to an Arduino Uno. <\/figcaption><\/figure><\/div>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"597\" height=\"400\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabSTSPIN220StepperNano_bb.png\" alt=\"Breadboard drawing of a stepper motor and STSPIN220 motor driver connected to an Arduino Nano 33 IoT. The connections are described in the body of this page.\" class=\"wp-image-10076\"\/><figcaption>Figure 16. <meta charset=\"utf-8\">Breadboard diagram of an STSPIN220 stepper motor driver and stepper motor connected to an Arduino Nano 33 IoT.<\/figcaption><\/figure>\n\n\n\n<p><em>Made with <a href=\"http:\/\/fritzing.org\/home\/\">Fritzing<\/a><\/em><\/p>\n\n\n\n<p>Once you have the motor and the driver connected, you&#8217;re ready to program the microcontroller.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Program_the_microcontroller\"><\/span>Program the microcontroller<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You don&#8217;t need a library for a step and direction controller, though there are several out there, to do things like ramp the speed up and down, ease in and out, and so forth. All you need to do to move the motor is to set the direction pin, and to pulse the motor high then return to low. A 3-millisecond pulse will do the job reliably. If you need more speed, you can try reducing this down to 2 or even 1ms, once you know the motor&#8217;s working properly.<\/p>\n\n\n\n<p>Regardless of what motor driver you are using, the first thing you should do after wiring up a stepper motor is to write two test programs, one to test if it&#8217;s stepping, and one to test if it can rotate one revolution in both directions.<\/p>\n\n\n\n<p> For your first program, it&#8217;s a good idea to run the stepper one step at a time, to see that all the wires are connected correctly. If they are, the stepper will step one step forward at a time, every half second, using the code below. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nconst int stepPin = 2;\nconst int dirPin = 3;\n\nvoid setup() {\n  pinMode(stepPin, OUTPUT);\n  pinMode(dirPin, OUTPUT);\n}\n\nvoid loop() {\n  \/\/ motor  direction: \n  digitalWrite(dirPin, HIGH);\n  \/\/ step the motor one step:\n  digitalWrite(stepPin, HIGH);\n  delay(3);\n  digitalWrite(stepPin, LOW);\n  \/\/ wait half a second:\n  delay(500);\n}\n<\/pre><\/div>\n\n\n<p>Once you&#8217;ve got that working, try making the stepper move one whole revolution at a time using the code below:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nconst int stepPin = 2;\nconst int dirPin = 3;\nconst int stepsPerRevolution = 512;\nbool direction = HIGH;\n\nvoid setup() {\n  pinMode(stepPin, OUTPUT);\n  pinMode(dirPin, OUTPUT);\n}\n\nvoid loop() {\n  \/\/ motor  direction:\n  digitalWrite(dirPin, direction);\n  \/\/ move one revolution :\n  for (int step = 0; step &lt; stepsPerRevolution; step++) {\n    \/\/ step the motor one step:\n    digitalWrite(stepPin, HIGH);\n    delay(3);\n    digitalWrite(stepPin, LOW);\n    delay(1);\n  }\n  \/\/ wait half a second:\n  delay(500);\n  \/\/ change direction:\n    direction = !direction;\n}\n<\/pre><\/div>\n\n\n<p>When you run this code, you should see the motor turn one revolution, wait half a second, then turn one revolution in the other direction. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"My_motors_only_going_one_direction\"><\/span>My motor&#8217;s only going one direction! <span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>If you find that the motor only turns in one direction, you probably have the pin connections wrong. It could be that you got the order wrong. Try rearranging the order of the pins. Disconnect power each time you try changing your connections. First, try swapping the two pins on each coil (e.g. blue and yellow, pink and orange) and run it again. If that fails, swap one wire from one coil for one wire from the other coil. Keep trying variations until your motor goes around in one direction, then goes around in the opposite direction. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Unipolar_Stepper_Control\"><\/span>Unipolar Stepper Control<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The steps above showed you how to control your motor as a bipolar stepper, but the motor shown is actually a unipolar motor. Remember the red wire you didn&#8217;t connect? That wire connects the two coils and can act as a common power source or ground wire. To use the motor as a unipolar motor, try connecting that wire (wire 1) of the motor to the V<sub>in<\/sub> power supply from the DC power jack. You should see that there&#8217;s not a lot of difference. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Attach_Something_to_the_Stepper\"><\/span>Attach Something to the Stepper<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you want to mount an arm or pointer to the stepper motor, you need to make a hole for the pointer that fits the shaft perfectly. You could measure this with a caliper.  There are also collars and shaft couplers that you can buy for various stepper motors that will allow you to attach things to your stepper. ServoCity has <a href=\"https:\/\/www.servocity.com\/search-results-page?q=stepper%20motor%20mount\">a number of examples<\/a>, as does <a href=\"https:\/\/www.pololu.com\/search?query=motor+shaft+adapters\">Pololu<\/a>. To pick a good shaft adapter, you need to know what you&#8217;re going to do with the stepper, and what the size and shape of the shaft is. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_an_External_Power_Supply\"><\/span>Using an External Power Supply<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Although the example shown above used a motor that can run on the voltage and current supplied to the Arduino via USB, this is not the norm for stepper motors. Most of the time you need to use an external power supply. You should  match your supply to your motor. Keep in mind that if you have, say, a 12-Volt power supply and a 5-volt motor, you can add a 5-volt voltage regulator, as shown in the <a href=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/breadboard\/#Powering_A_Breadboard_Circuit_From_A_Microcontroller_Via_A_DC_Power_Supply\">breadboard lab<\/a>. Figures 17 through 19 show a few different options for powering different stepper motors.<\/p>\n\n\n\n<p>Figures 17 and 18 show how you might power a 9V stepper motor from an Uno or Nano, respectively. Figures 17 and 18 show a NEMA-17 stepper motor. Figure 19 shows how you could power a 5V stepper from a Nano, using a 9-12V DC power supply for the Nano and a 5V voltage regulator  for the motor and motor driver. <\/p>\n\n\n\n<p>The STSPIN220 can run motors from 1.8-10V. If you need to run a motor at a voltage greater than 10V, there are several other step and direction motor drivers that can do the job. For example, the <a href=\"https:\/\/www.pololu.com\/product\/2128\">A4988<\/a> is similar to the STSPI220, but has a motor voltage range of 8-35V. Many of them come with the same or similar pin arrangements as well. For a comparison, see the <a href=\"https:\/\/itp.nyu.edu\/physcomp\/lessons\/stepper-motors\/#Step_Direction_Stepper_Drivers\">Step &amp; Direction Drivers compared table<\/a> in the Controlling Stepper Motors page of this site.<\/p>\n\n\n\n<p>It&#8217;s worth noting that when the Nano 33 IoT is powered from its V<sub>in<\/sub> pin, the USB connection no longer powers the Nano. Instead, the V<sub>in<\/sub> powers the Nano. You can still get 3.3V from the 3.3V out pin (pin 2), however.<\/p>\n\n\n\n<p>The exact voltage and amperage requirements for a stepper motor circuit will depend on the motor you are using. These images show a few options that can work, but you should adapt them depending on the particular electrical characteristics of your motor. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"919\" height=\"400\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabSTSPIN220StepperUnoExtSupply_bb.png\" alt=\"Breadboard view of an STSPIN220 running a 9V stepper motor from an Arduino Uno.\" class=\"wp-image-10087\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabSTSPIN220StepperUnoExtSupply_bb.png 919w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabSTSPIN220StepperUnoExtSupply_bb-768x334.png 768w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption>Figure 17. Breadboard view of an STSPIN220 running a 9V NEMA-style stepper motor from an Arduino Uno. The circuit is similar to Figure 15 above, but in this image the STSPIN220&#8217;s V<sub>MOT<\/sub> pin (pin 16) is connected to the Uno&#8217;s V<sub>in<\/sub> pin. The whole circuit would be powered by a 9V DC power supply connected to the Uno&#8217;s power jack. <\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"693\" height=\"400\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabSTSPIN220StepperNanoExtSupply2_bb.png\" alt=\"Breadboard view of an STSPIN220 running a 9V stepper motor from an Arduino Nano 33 IoT. \" class=\"wp-image-10084\"\/><figcaption>Figure 18. Breadboard view of an STSPIN220 running a 9V <meta charset=\"utf-8\">NEMA-style stepper motor from an Arduino Nano 33 IoT. The circuit is similar to Figure 16 above, but in this image an external power jack is connected to the Nano&#8217;s V<sub>in<\/sub> pin (pin 15) and grounded to its ground pin (pin 14). The STSPIN220&#8217;s V<sub>MOT<\/sub> pin (pin 16) is connected to the Nano 33 IoT&#8217;s V<sub>in<\/sub> pin (pin 15) and the positive terminal of the power jack. The Nano would then need to be powered by a 9V DC power supply connected to the power jack. <\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"776\" height=\"400\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabSTSPIN220StepperNanoExtSupply1_bb.png\" alt=\"Breadboard view of an STSPIN220 running a 5V stepper motor from an Arduino Nano 33 IoT with an external voltage regulator\" class=\"wp-image-10089\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabSTSPIN220StepperNanoExtSupply1_bb.png 776w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabSTSPIN220StepperNanoExtSupply1_bb-768x396.png 768w\" sizes=\"(max-width: 776px) 85vw, 776px\" \/><figcaption><meta charset=\"utf-8\">Figure 19. Breadboard view of an STSPIN220 running a 5V stepper motor from an Arduino Nano 33 IoT with an external voltage regulator. The circuit is similar to Figures 16 and 18 above, but in this image an external power jack is connected to the Nano&#8217;s V<sub>in<\/sub> pin (pin 15) and grounded to its ground pin (pin 14). A 7805 5V voltage regulator has been added to the breadboard in three rows just above the STSPIN220 on the right side of the breadboard. The regulator&#8217;s input pin is closest to the top of the board, and is connected to the Nano&#8217;s V<sub>in<\/sub> pin and the positive terminal of the power jack. Its ground is in the middle, and is connected to the right side ground bus of the breadboard. Its output is closest to the bottom and is connected to the STSPIN220&#8217;s V<sub>MOT<\/sub> pin (pin 16). The whole circuit could be powered by a 9-12V DC power supply connected to the power jack. The regulator would ensure that the motor and the STSPI220 always get 5V and up to 1A.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Advanced_Features_Speed_Control_Microstepping_and_G-code\"><\/span>Advanced Features: Speed Control, Microstepping, and G-code<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This lab has covered the basics of step &amp; direction drivers. These drivers are capable of much more control, depending on how you wire them and how you program the microcontroller to control them.  <\/p>\n\n\n\n<p>Controlling the speed of a motor is managed by changing the timing between steps. You can manage this in your own code by changing the delay after each step pulse, or you can use a library like <a href=\"https:\/\/www.airspayce.com\/mikem\/arduino\/AccelStepper\/\">accelStepper<\/a> which has options for speed control.  <\/p>\n\n\n\n<p>Microstepping allows you to control a stepper in 1\/2, 1\/4, 1\/8, or as low as 1\/256 step increments. The number of microsteps depends on the driver you are using. You set the microstep increment using the mode pins.  Pololu&#8217;s <a href=\"https:\/\/www.pololu.com\/product\/2876\">documentation for the STSPIN220<\/a> covers the details of this for this board (see the section titled Step (and microstep) Size). Other step &amp; direction boards will have similar instructions. <\/p>\n\n\n\n<p>Step and direction motor controllers are often used in DNC machines like 3D printers and 3D mills. These machines have a communication format called <a href=\"https:\/\/www.thomasnet.com\/articles\/custom-manufacturing-fabricating\/introduction-gcode\/\">G-code<\/a> which describes how the machine should move to print or carve a shape. The <a href=\"https:\/\/github.com\/grbl\/grbl\">GRBL library<\/a> for Arduino translates G-code into a series of stepper motor movements. There are many sites which explain this in more depth, like the one at <a href=\"https:\/\/howtomechatronics.com\/tutorials\/how-to-setup-grbl-control-cnc-machine-with-arduino\/\">this link<\/a>. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Applications\"><\/span>Applications<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Stepper motors have lots of applications. One of the most common is to make a tw0- or three-axis gantry for CNC plotters, printers, and mills. A gantry is a structure on which you mount motors and the equipment that they are moving in order to achieve a task. Evil Mad Science&#8217;s <a href=\"https:\/\/shop.evilmadscientist.com\/productsmenu\/846\">AxiDraw<\/a> is a good two-axis example. You can also use steppers to create animation in art projects, as seen in Nuntinee Tansrisakul&#8217;s <a href=\"https:\/\/nuntinee.com\/shadow-through-time\/\">Shadow through Time<\/a>. <meta charset=\"utf-8\">Heidi Neilson&#8217;s <a href=\"https:\/\/heidineilson.com\/moon-arrow\/\">Moon Arrow<\/a> is another example that uses stepper motors and geolocation tools to make an arrow that always points at the moon. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In the stepper motor and H-bridge lab, you learned how to control a stepper motor with a dual H-bridge driver, specifically the TB6612FNG. This is not the only driver for controlling a stepper. Step &amp; direction stepper drivers offer a simpler approach, from the microcontroller side. They have just two control pins, one for &hellip; <a href=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/motors-and-transistors\/lab-controlling-a-stepper-motor-with-a-step-and-direction-driver\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Lab: Controlling a Stepper Motor With a Step and Direction Driver&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":1510,"menu_order":605,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[15,54,8],"tags":[76,73,74,72,75],"class_list":["post-9992","page","type-page","status-publish","hentry","category-lab","category-microcontrollers","category-motors","tag-a4988","tag-motor-driver","tag-step-and-direction-driver","tag-stepper-motor","tag-stspin220"],"_links":{"self":[{"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages\/9992"}],"collection":[{"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/comments?post=9992"}],"version-history":[{"count":50,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages\/9992\/revisions"}],"predecessor-version":[{"id":10751,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages\/9992\/revisions\/10751"}],"up":[{"embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages\/1510"}],"wp:attachment":[{"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/media?parent=9992"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/categories?post=9992"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/tags?post=9992"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}