{"id":1768,"date":"2014-08-23T12:20:30","date_gmt":"2014-08-23T16:20:30","guid":{"rendered":"https:\/\/itp.nyu.edu\/physicalcomputing\/?page_id=1768"},"modified":"2023-10-07T13:31:26","modified_gmt":"2023-10-07T17:31:26","slug":"lab-controlling-a-stepper-motor-with-an-h-bridge","status":"publish","type":"page","link":"https:\/\/itp.nyu.edu\/physcomp\/labs\/motors-and-transistors\/lab-controlling-a-stepper-motor-with-an-h-bridge\/","title":{"rendered":"Lab: Controlling a Stepper Motor With an H-Bridge"},"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><a href=\"https:\/\/itp.nyu.edu\/physcomp\/lessons\/stepper-motors\/\" data-type=\"page\" data-id=\"827\">Stepper motors<\/a> are motors that have multiple coils in them, so that they can be moved in small increments or steps. The common feature to all stepper motors is that they have two coils in the motor rather than one. You control the stepper by energizing one coil, then reversing its polarity, then doing the same to the other coil. To do this, you can use a dual H-bridge driver like the TB6612FNG that you used in the DC motors and H-bridge lab. This lab shows you how to set up stepper motor using an H-Bridge. <\/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><a rel=\"noopener\" href=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/motors-and-transistors\/dc-motor-control-using-an-h-bridge\/\">What is an H-Bridge and how it works<\/a><\/li><li>What is an&nbsp;<a href=\"https:\/\/www.arduino.cc\/reference\/en\/libraries\/\">Arduino Library<\/a><\/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=\"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=\"1555\" height=\"1166\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-motor-driver.jpg\" alt=\"Photo of a Motor Driver (H-bridge), model TB6612FNG\" data-id=\"5916\" data-full-url=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-motor-driver.jpg\" data-link=\"https:\/\/itp.nyu.edu\/physcomp\/resources\/parts-needed-for-physical-computing\/pcomp-kit-f2019-motor-driver\/\" class=\"wp-image-5916\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-motor-driver.jpg 1555w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-motor-driver-768x576.jpg 768w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-motor-driver-1280x960.jpg 1280w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption class=\"blocks-gallery-item__caption\">Motor Driver (H-bridge), model TB6612FNG<\/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\"><meta charset=\"utf-8\">Multimeter. You&#8217;ll need this to check the coils.<\/figcaption><\/figure><\/li><\/ul><figcaption class=\"blocks-gallery-caption\"><meta charset=\"utf-8\">Figures 1-8. The parts you\u2019ll need for this exercise.<\/figcaption><\/figure>\n\n\n\n<p><meta charset=\"utf-8\">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>. The driver is a <meta charset=\"utf-8\">Toshiba <a href=\"https:\/\/toshiba.semicon-storage.com\/us\/semiconductor\/product\/motor-driver-ics\/brushed-dc-motor-driver-ics\/detail.TB6612FNG.html\">TB6612FNG<\/a>. There&#8217;s a&nbsp;&nbsp;<a href=\"https:\/\/www.sparkfun.com\/products\/14451\">Sparkfun breakout board<\/a>, an <a href=\"https:\/\/www.adafruit.com\/product\/2448\">Adafruit breakout board<\/a>, and a&nbsp;<a href=\"https:\/\/www.pololu.com\/product\/713\">Pololu breakout board<\/a> for this part as well. The principles in this lab, and the library used, will work with other stepper motors and dual H-bridge 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>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<p><em>Made with <a href=\"http:\/\/fritzing.org\/home\/\">Fritzing<\/a><\/em><\/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 <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<h3 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><\/h3>\n\n\n\n<p>The TB6612FNG motor driver can handle a motor&nbsp; supply voltage up to 15V, and&nbsp; it operates on a logic voltage of 2.7\u20135.5V. It can control an output current of 1.2A. It has two motor driver circuits, each with two logic inputs and two motor outputs. Each motor driver has a PWM input, because they are expected to be used for speed control for the motor by pulse width modulating this pin.  You won&#8217;t be using the PWM pins for this exercise though. There&#8217;s also a Standby pin that you have to connect to voltage through a 10-kilohm pullup resistor to activate the driver circuits.<\/p>\n\n\n\n<p>The motor driver has the following pins. The pin numbers shown here are for the Sparkfun breakout board. The order of the pins will be different for the Adafruit and Pololu boards. 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>V<sub>MOT<\/sub> &#8211; motor voltage supply input, up to 15V.<\/li><li>V<sub>cc<\/sub> &#8211; logic voltage supply&nbsp; input, 2.7-5.5V<\/li><li>Gnd &#8211; ground<\/li><li>AO1 &#8211; A channel output 1. This is the first motor terminal for the first motor driver<\/li><li>AO2&nbsp;&#8211; A channel output 2.&nbsp; This is the second motor terminal for the first motor driver<\/li><li>BO2 &#8211; B channel output 2.&nbsp; This is the second motor terminal for the second motor driver<\/li><li>BO1 &#8211; B channel output 1.&nbsp; This is the first motor terminal for the second motor driver<\/li><li>Gnd &#8211; ground<\/li><li>Gnd &#8211; ground<\/li><li>PWMB &#8211; B Channel PWM Enable. This pin controls the speed for channel B, regardless of the channel&#8217;s direction<\/li><li>BI2 &#8211;&nbsp;B channel input 2.&nbsp; This controls B channel output 2. To control that pin, take this pin HIGH or LOW.<\/li><li>BI1 &#8211;&nbsp;B channel input 1.&nbsp; This controls B channel output 1. To control that pin, take this pin HIGH or LOW.<\/li><li>Stdby &#8211;&nbsp;enables both drivers when you take it HIGH&nbsp; and disables them when you take it LOW<\/li><li>AI1 &#8211; A channel input 1.&nbsp; This controls A channel output 1. To control that pin, take this pin HIGH or LOW.<\/li><li>AI2 &#8211; A channel input 2.&nbsp; This controls A channel output 2. To control that pin, take this pin HIGH or LOW.<\/li><li>PWMA &#8211; A Channel PWM Enable. This pin controls the speed for channel A, regardless of the channel&#8217;s direction<\/li><\/ol>\n\n\n\n<p>Figure 12 shows the Sparkfun board, and Figures 13 and 14 show the Pololu board front and back. The Pololu board is labeled on the back. You can see that both boards have the same pins, even though the layouts are different. Click on any of the images to see them larger.<\/p>\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\/pcomp-kit-f2019-motor-driver.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-motor-driver.jpg\" alt=\"Photo of a Motor Driver (H-bridge), model TB6612FNG\" class=\"wp-image-5916\" width=\"389\" height=\"292\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-motor-driver.jpg 1555w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-motor-driver-768x576.jpg 768w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-motor-driver-1280x960.jpg 1280w\" sizes=\"(max-width: 389px) 85vw, 389px\" \/><\/a><figcaption>Figure 12. Motor Driver (H-bridge), model TB6612FNG<\/figcaption><\/figure><\/div>\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\/pcomp-kit-f2019-motor-driver-pololu-front.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-motor-driver-pololu-front.jpg\" alt=\"Photo of a motor driver, Pololu's TB6612FNG Dual Motor Driver Carrier (front view of the board)\" class=\"wp-image-5984\" width=\"277\" height=\"208\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-motor-driver-pololu-front.jpg 2216w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-motor-driver-pololu-front-768x576.jpg 768w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-motor-driver-pololu-front-1280x960.jpg 1280w\" sizes=\"(max-width: 277px) 85vw, 277px\" \/><\/a><figcaption>Figure 13. Pololu&#8217;s TB6612FNG Dual Motor Driver Carrier (front view of the board)<\/figcaption><\/figure><\/div>\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\/pcomp-kit-f2019-motor-driver-pololu-back.jpg\"><img decoding=\"async\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-motor-driver-pololu-back.jpg\" alt=\"Photo of a motor driver, Pololu's TB6612FNG Dual Motor Driver Carrier (back of the board)\" class=\"wp-image-5983\" width=\"389\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-motor-driver-pololu-back.jpg 2595w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-motor-driver-pololu-back-768x576.jpg 768w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-motor-driver-pololu-back-1280x960.jpg 1280w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><figcaption>Figure 14. Pololu&#8217;s TB6612FNG Dual Motor Driver Carrier (back of the board)<\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>You can change the direction and speed of the motor using the motor driver.&nbsp;The truth table below shows how the motor driver works.<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><th>AI1<\/th><th>AI2<\/th><th>PWMA<\/th><td><strong>B1<\/strong><\/td><td><\/td><td><strong>B2<\/strong><\/td><td><strong>PWMB<\/strong><\/td><td><strong>Coil 1<\/strong><\/td><td><strong>Coil 2<\/strong><\/td><td><\/td><td><\/td><\/tr><tr><td>H<\/td><td>L<\/td><td>H<\/td><td>&#8211;<\/td><td><\/td><td>&#8211;<\/td><td>L<\/td><td>Direction 1<\/td><td>Off<\/td><td><\/td><td><\/td><\/tr><tr><td>L<\/td><td>H<\/td><td>H<\/td><td>&#8211;<\/td><td><\/td><td>&#8211;<\/td><td>L<\/td><td><meta charset=\"utf-8\">Direction 2<\/td><td>Off<\/td><td><\/td><td><\/td><\/tr><tr><td>L<\/td><td>L<\/td><td>&#8211;<\/td><td>&#8211;<\/td><td><\/td><td>&#8211;<\/td><td>L<\/td><td>Off<\/td><td>Off<\/td><td><\/td><td><\/td><\/tr><tr><td>H<\/td><td>H<\/td><td>&#8211;<\/td><td>&#8211;<\/td><td><\/td><td>&#8211;<\/td><td>L<\/td><td>Off<\/td><td>Off<\/td><td><\/td><td><\/td><\/tr><tr><td>&#8211;<\/td><td>&#8211;<\/td><td>L<\/td><td>H<\/td><td><\/td><td>L<\/td><td>H<\/td><td>Off<\/td><td><meta charset=\"utf-8\">Direction 1<\/td><td><\/td><td><\/td><\/tr><tr><td>&#8211;<\/td><td>&#8211;<\/td><td>L<\/td><td>L<\/td><td><\/td><td>H<\/td><td>H<\/td><td>Off<\/td><td><meta charset=\"utf-8\">Direction 2<\/td><td><\/td><td><\/td><\/tr><tr><td>&#8211;<\/td><td>&#8211;<\/td><td>L<\/td><td>H<\/td><td><\/td><td>H<\/td><td>H<\/td><td>Off<\/td><td>Off<\/td><td><\/td><td><\/td><\/tr><tr><td>&#8211;<\/td><td>&#8211;<\/td><td>L<\/td><td>L<\/td><td><\/td><td>L<\/td><td>H<\/td><td>Off<\/td><td>Off<\/td><td><\/td><td><\/td><\/tr><\/tbody><\/table><figcaption>Table 1. States of the TB6612FNG and the coil states<\/figcaption><\/figure>\n\n\n\n<p>For this lab, the PWMA and PWMB pins connect to Vcc so that the driver circuits stay fully energized. The motor logic pins are also connected to designated digital pins on your Arduino so you can set them HIGH and LOW to turn the motor in one direction, or LOW and HIGH to turn it in the other direction. The motor supply voltage connects to the voltage source for the motor, which is usually an external power supply. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Connect_the_H-bridge_and_Motor\"><\/span>Connect the H-bridge and Motor<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><meta charset=\"utf-8\">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. Table 2 below details the pin connections in the circuit. Figures 15 through 17 show how to connect the circuit.<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table class=\"has-fixed-layout\"><thead><tr><th><meta charset=\"utf-8\">Motor Driver Physical pin number<\/th><th><meta charset=\"utf-8\">Pin function<\/th><th><meta charset=\"utf-8\">Circuit Connection<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>V<sub>MOT<\/sub>, motor power<\/td><td><meta charset=\"utf-8\">Arduino V<sub>cc<\/sub> if using USB power.  Arduino V<sub>in<\/sub> if using an external power supply.<\/td><\/tr><tr><td>2<\/td><td>V<sub>cc<\/sub><\/td><td>5V (Uno) or 3.3V (Nano 33 IoT)<\/td><\/tr><tr><td>3<\/td><td>Ground<\/td><td>Ground<\/td><\/tr><tr><td>4<\/td><td>AOUT1<\/td><td>motor coil 1 pin 1<\/td><\/tr><tr><td>5<\/td><td>AOUT2<\/td><td>motor coil 1 pin 2<\/td><\/tr><tr><td>6<\/td><td>BOUT2<\/td><td>motor coil 2 pin 1<\/td><\/tr><tr><td>7<\/td><td>BOUT1<\/td><td>motor coil 2 pin 2<\/td><\/tr><tr><td>8<\/td><td>Ground<\/td><td>Ground<\/td><\/tr><tr><td>9<\/td><td>Ground<\/td><td>Ground<\/td><\/tr><tr><td>10<\/td><td>PWMB<\/td><td><meta charset=\"utf-8\">5V (Uno) or 3.3V (Nano 33 IoT)<\/td><\/tr><tr><td>11<\/td><td>BIN2<\/td><td>Arduino digital pin 8<\/td><\/tr><tr><td>12<\/td><td>BIN1<\/td><td><meta charset=\"utf-8\">Arduino digital pin 9<\/td><\/tr><tr><td>13<\/td><td>Standby<\/td><td>10-kilohm resistor to <meta charset=\"utf-8\">5V (Uno) or 3.3V (Nano 33 IoT)<\/td><\/tr><tr><td>14<\/td><td>AIN1<\/td><td><meta charset=\"utf-8\">Arduino digital pin 10<\/td><\/tr><tr><td>15<\/td><td>AIN2<\/td><td><meta charset=\"utf-8\">Arduino digital pin 11<\/td><\/tr><tr><td>16<\/td><td>PWMA<\/td><td><meta charset=\"utf-8\">5V (Uno) or 3.3V (Nano 33 IoT)<\/td><\/tr><\/tbody><\/table><figcaption>Table 2. TB6612FNG <meta charset=\"utf-8\">connections to Arduino circuit<\/figcaption><\/figure>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"541\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/TB6612HBridgeStepper_schem-1.png\" alt=\"Schematic drawing of an Arduino attached to a TB6612FNG stepper motor driver and a stepper motor.  Pin connections are detailed in Table 2.\" class=\"wp-image-10113\"\/><figcaption>Figure 15. Schematic view of an h-bridge connected to an Arduino for driving a stepper motor.<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"574\" height=\"424\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/TB6612HBridgeStepperUno_bb.png\" alt=\"Breadboard drawing of an Arduino Uno attached to a TB6612FNG stepper motor driver and a stepper motor. \" class=\"wp-image-10105\"\/><figcaption>Figure 16. Breadboard diagram of an H-bridge and an Arduino Uno wired for control of a stepper.<\/figcaption><\/figure><\/div>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"1452\" height=\"1010\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/stepperNanoTB6612FNG-1.png\" alt=\"Figure 17. Breadboard diagram of an H-bridge and an Arduino Nano 33 IoT wired for control of a stepper.\" class=\"wp-image-11120\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/stepperNanoTB6612FNG-1.png 1452w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/stepperNanoTB6612FNG-1-768x534.png 768w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/stepperNanoTB6612FNG-1-1200x835.png 1200w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption><meta charset=\"utf-8\">Figure 17. Breadboard diagram of an H-bridge and an Arduino Nano 33 IoT wired for control of a stepper.<\/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>The <a href=\"https:\/\/www.arduino.cc\/reference\/en\/libraries\/stepper\/\">Arduino Stepper library<\/a> is written to work with H-bridge and transistor array stepper motor drivers. You initialize the library by telling it how many steps per revolution your motor turns, and what the pin numbers are that are controlling the coils, as follows:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nStepper myStepper(stepsPerRevolution, coil1Pin1, coil1Pin2, coil2Pin1, coil2Pin2);\n\n<\/pre><\/div>\n\n\n<p> After that, you move it one direction or the other by calling <code>myStepper.step(steps);<\/code> If you step it a positive number, it moves one direction; a negative number moves it the opposite direction. <\/p>\n\n\n\n<p>You can install the Stepper library using the Library Manager of the Arduino IDE, if it&#8217;s not already installed. Once you&#8217;ve done so, there will be examples for it available in the File -&gt; Examples menu. <\/p>\n\n\n\n<p><meta charset=\"utf-8\">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. The Arduino Stepper library includes these two programs as examples. <\/p>\n\n\n\n<p>The first example to start with is the <a href=\"https:\/\/docs.arduino.cc\/learn\/electronics\/stepper-motors#stepperonestepatatime\">stepper_oneStepAtATime<\/a> example.  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. Make sure to change the number of steps per revolution and pin numbers if needed, to match your stepper. The number of steps per revolution will depend on your individual stepper, so check the data sheet for the number of steps per revolution:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\n#include \"Stepper.h\"\n\nconst int stepsPerRevolution = 512;\n\n\/\/ initialize the stepper library on pins 8 through 11:\nStepper myStepper(stepsPerRevolution, 8,9,10,11);            \n\nint stepCount = 0;       \/\/ number of steps the motor has taken\n\nvoid setup() {\n  \/\/ initialize the serial port:\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  \/\/ step one step:\n  myStepper.step(1);\n  Serial.print(\"steps:\" );\n  Serial.println(stepCount);\n  stepCount++;\n  delay(500);\n}\n<\/pre><\/div>\n\n\n<p>If your circuit is connected correctly, <meta charset=\"utf-8\">  the stepper will step one step forward at a time, every half second. <\/p>\n\n\n\n<p>Once you&#8217;ve got that working, try making the stepper move one whole revolution at a time using the <a href=\"https:\/\/docs.arduino.cc\/learn\/electronics\/stepper-motors#stepperonerevolution\">stepper_oneRevolution<\/a> example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\n#include \"Stepper.h\"\n\nconst int stepsPerRevolution = 512;  \n\n\/\/ initialize the stepper library on pins 8 through 11:\nStepper myStepper(stepsPerRevolution, 8,9,10,11);            \n\nvoid setup() {\n  \/\/ set the speed at 60 rpm:\n  myStepper.setSpeed(10);\n  \/\/ initialize the serial port:\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  \/\/ step one revolution  in one direction:\n   Serial.println(\"clockwise\");\n  myStepper.step(stepsPerRevolution);\n  delay(500);\n\n   \/\/ step one revolution in the other direction:\n  Serial.println(\"counterclockwise\");\n  myStepper.step(-stepsPerRevolution);\n  delay(500);\n}\n<\/pre><\/div>\n\n\n<p><meta charset=\"utf-8\">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<p>With a high-step-count stepper, you may want to change the speed using <code>myStepper.setSpeed()<\/code>. If the motor steps are run too fast, the motor coils don&#8217;t have a chance to energize and de-energize in order to step the motor. You don&#8217;t have to use the speed command; you can control the speed in your own code by changing the delay between steps and the number of steps you take per <code>step()<\/code> command. <\/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 a bipolar stepper, but the motor shown was 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 examples 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 18 through 20 show a few different options for powering different stepper motors.<\/p>\n\n\n\n<p>Figures 18 and 19 show how you might power a 9V stepper motor from an Uno or Nano, respectively. Figures 18 and 19 show a NEMA-17 stepper motor. Figure 20 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>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=\"700\" height=\"517\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/TB6612HBridgeStepperUno_Ext_power_bb.png\" alt=\"Breadboard drawing of an Arduino Uno attached to a TB6612FNG stepper motor driver and a stepper motor. The caption explains the pin connections.\" class=\"wp-image-10115\"\/><figcaption>Figure 18. Breadboard view of TP6612FNG running a 9V NEMA-style stepper motor from an Arduino Uno. The circuit is similar to Figure 16 above, but in this image the TB6612FNG&#8217;s V<sub>MOT<\/sub> pin (pin 1) 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=\"1580\" height=\"1035\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/stepperDriverNEMA_bb-2.png\" alt=\"Figure 19. Breadboard view of an TB6612FNG running a 9V NEMA-style stepper motor from an Arduino Nano 33 IoT. The circuit is similar to Figure 17 above, but in this image an external power jack is connected to the Nano's Vin pin (pin 15) and grounded to its ground pin (pin 14). The TB6612FNG's VMOT pin (pin 1) is connected to the Nano 33 IoT's Vin 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\" class=\"wp-image-11125\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/stepperDriverNEMA_bb-2.png 1580w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/stepperDriverNEMA_bb-2-768x503.png 768w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/stepperDriverNEMA_bb-2-1536x1006.png 1536w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/stepperDriverNEMA_bb-2-1200x786.png 1200w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption>Figure 19. Breadboard view of an TB6612FNG running a 9V NEMA-style stepper motor from an Arduino Nano 33 IoT. The circuit is similar to Figure 17 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 <meta charset=\"utf-8\">TB6612FNG&#8217;s V<sub>MOT<\/sub> pin (pin 1) 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=\"1452\" height=\"1010\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/stepperDriver_bb.png\" alt=\"Figure 20. Breadboard view of an TB6612FNG running a 5V stepper motor from an Arduino Nano 33 IoT with an external voltage regulator. The circuit is similar to Figures 17 and 19 above, but in this image an external power jack is connected to the Nano's Vin 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 TB6612FNG on the left side of the breadboard. The regulator's input pin is closest to the top of the board, and is connected to the Nano's Vin pin and the positive terminal of the power jack. Its ground is in the middle, and is connected to the left side ground bus of the breadboard. Its output is closest to the bottom and is connected to the TB6612FNG's VMOT pin (pin 1). 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.\" class=\"wp-image-11127\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/stepperDriver_bb.png 1452w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/stepperDriver_bb-768x534.png 768w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/stepperDriver_bb-1200x835.png 1200w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption>Figure 20. Breadboard view of an TB6612FNG running a 5V stepper motor from an Arduino Nano 33 IoT with an external voltage regulator. The circuit is similar to Figures 17 and 19 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 <meta charset=\"utf-8\">TB6612FNG on the left 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 left side ground bus of the breadboard. Its output is closest to the bottom and is connected to the <meta charset=\"utf-8\">TB6612FNG&#8217;s V<sub>MOT<\/sub> pin (pin 1). 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=\"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>. 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>This lab shows you how to set up a unipolar stepper motor using an H-Bridge.<\/p>\n","protected":false},"author":5,"featured_media":0,"parent":1510,"menu_order":604,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[15,8,28],"tags":[],"class_list":["post-1768","page","type-page","status-publish","hentry","category-lab","category-motors","category-transistor"],"_links":{"self":[{"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages\/1768"}],"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\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/comments?post=1768"}],"version-history":[{"count":64,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages\/1768\/revisions"}],"predecessor-version":[{"id":11129,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages\/1768\/revisions\/11129"}],"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=1768"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/categories?post=1768"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/tags?post=1768"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}