{"id":468,"date":"2014-07-01T18:57:17","date_gmt":"2014-07-01T22:57:17","guid":{"rendered":"https:\/\/itp.nyu.edu\/physicalcomputing\/?page_id=468"},"modified":"2022-11-06T17:28:04","modified_gmt":"2022-11-06T22:28:04","slug":"dc-motor-control-using-an-h-bridge","status":"publish","type":"page","link":"https:\/\/itp.nyu.edu\/physcomp\/labs\/motors-and-transistors\/dc-motor-control-using-an-h-bridge\/","title":{"rendered":"Lab: DC Motor Control Using 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>In this tutorial, you&#8217;ll learn how to control a DC motor&#8217;s direction using a DC Motor Driver.<\/p>\n\n\n\n<p>To reverse a DC motor, you need to be able to reverse the direction of the current in the motor. The classic way to do this is using an <a href=\"https:\/\/itp.nyu.edu\/physcomp\/lessons\/dc-motors-the-basics\/#Direction\" data-type=\"page\">H-bridge circuit<\/a>. Though most motor driver chips these days are not in fact H-bridge circuits, the term still persists. This tutorial uses a Toshiba motor driver, the TB6612FNG, which can actually drive two DC motors. Both Sparkfun, Adafruit, and Pololu make breakout boards for the motor driver, though the Sparkfun one is shown in the examples below.<\/p>\n\n\n\n<p>At the end of the lab, an alternative motor driver, the L9110H, is shown. This motor driver can only drive one motor at a time, unlike the <meta charset=\"utf-8\">TB6612FNG, but it&#8217;s more inexpensive than the <meta charset=\"utf-8\">TB6612FNG. <\/p>\n\n\n\n<p>If you simply want to turn a motor on and off, and don&#8217;t need to reverse it, for example if you&#8217;re controlling a fan, try the tutorial on <a rel=\"noopener noreferrer\" href=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/motors-and-transistors\/using-a-transistor-to-control-high-current-loads-with-an-arduino\/\" target=\"_blank\">controlling high current loads with transistors<\/a>.<\/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\/components\/\" target=\"_blank\" rel=\"noreferrer noopener\">Lab: Electronic components<\/a><\/li><li><a class=\"wikilink\" style=\"color: #37aad1;\" rel=\"noopener noreferrer\" href=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/labs-arduino-digital-and-analog\/digital-input-and-output-with-an-arduino\/\" target=\"_blank\">Lab: Digital input with Arduino<\/a><\/li><li><a rel=\"noopener noreferrer\" href=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/motors-and-transistors\/using-a-transistor-to-control-a-high-current-load\/\" target=\"_blank\">Lab: How to use transistors to control high current loads<\/a><\/li><li><a rel=\"noopener noreferrer\" href=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/motors-and-transistors\/using-a-transistor-to-control-high-current-loads-with-an-arduino\/\" target=\"_blank\">Lab: How to use transistors to control high current loads with Arduino<\/a><\/li><li><a href=\"https:\/\/vimeo.com\/380158444\">Video: H-Bridges<\/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-3 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><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-arduino-nano-33-iot.jpg\"><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\" \/><\/a><figcaption class=\"blocks-gallery-item__caption\">Arduino Nano 33 IoT<\/figcaption><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-jumper-wires.jpg\"><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\" \/><\/a><figcaption class=\"blocks-gallery-item__caption\">Flexible jumper wires.<\/figcaption><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-breadboard.jpg\"><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\" \/><\/a><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><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-motor-driver.jpg\"><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\" \/><\/a><figcaption class=\"blocks-gallery-item__caption\">Motor Driver (H-bridge), model TB6612FNG<\/figcaption><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-dc-motor.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"4640\" height=\"3480\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-dc-motor.jpg\" alt=\"Photo of a DC Gearmotor\" data-id=\"5923\" data-full-url=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-dc-motor.jpg\" data-link=\"https:\/\/itp.nyu.edu\/physcomp\/resources\/parts-needed-for-physical-computing\/pcomp-kit-f2019-dc-motor\/\" class=\"wp-image-5923\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-dc-motor.jpg 4640w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-dc-motor-768x576.jpg 768w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-dc-motor-1280x960.jpg 1280w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><figcaption class=\"blocks-gallery-item__caption\">DC Gearmotor<\/figcaption><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-10k-resistor.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"2356\" height=\"1767\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-10k-resistor.jpg\" alt=\"Photo of a handful of 10-kilohm resistors\" data-id=\"5915\" data-full-url=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-10k-resistor.jpg\" data-link=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/labs-arduino-digital-and-analog\/digital-input-and-output-with-an-arduino\/pcomp-kit-f2019-10k-resistor\/\" class=\"wp-image-5915\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-10k-resistor.jpg 2356w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-10k-resistor-768x576.jpg 768w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-10k-resistor-1280x960.jpg 1280w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><figcaption class=\"blocks-gallery-item__caption\">10-kilohm resistors. These ones are 5-band resistors<\/figcaption><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-pushbuttons.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"2194\" height=\"1646\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-pushbuttons.jpg\" alt=\"Photo of four breadboard-mounted pushbuttons\" data-id=\"5918\" data-full-url=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-pushbuttons.jpg\" data-link=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/labs-arduino-digital-and-analog\/digital-input-and-output-with-an-arduino\/pcomp-kit-f2019-pushbuttons\/\" class=\"wp-image-5918\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-pushbuttons.jpg 2194w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-pushbuttons-768x576.jpg 768w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-pushbuttons-1280x960.jpg 1280w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><figcaption class=\"blocks-gallery-item__caption\">Pushbuttons<\/figcaption><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/DC_power_jack.jpg\"><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\" \/><\/a><figcaption class=\"blocks-gallery-item__caption\">A DC Power Jack<\/figcaption><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/power_supply_01.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"560\" height=\"540\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/power_supply_01.jpg\" alt=\"Photo of a DC power supply. A rectangular block approximately 2 inches by 3 inches with plugs to plug into the wall. A wire extends from the plug to connect with your circuit.\" data-id=\"1608\" data-full-url=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/power_supply_01.jpg\" data-link=\"https:\/\/itp.nyu.edu\/physcomp\/lessons\/electronics\/understanding-dc-power-supplies\/sanyo-digital-camera-2\/\" class=\"wp-image-1608\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/power_supply_01.jpg 560w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/power_supply_01-300x289.jpg 300w\" sizes=\"(max-width: 560px) 85vw, 560px\" \/><\/a><figcaption class=\"blocks-gallery-item__caption\">DC Power Supply<\/figcaption><\/figure><\/li><\/ul><figcaption class=\"blocks-gallery-caption\"><meta charset=\"utf-8\">Figures 1-9. The parts you&#8217;ll need for this exercise. Click on any image for a larger view.<\/figcaption><\/figure>\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 10 and 11.<\/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 10. 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 10 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 11. Breadboard view of an Arduino Nano mounted on a solderless breadboard.<\/figcaption><\/figure><\/div>\n\n\n\n<p>As shown in Figure 11, 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<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><em style=\"font-size: 16px;\">Images 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=\"Add_a_Digital_Input_pushbutton_or_switch\"><\/span>Add a Digital Input (pushbutton or switch)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Connect a <meta charset=\"utf-8\">pushbutton to digital input 2 on the Arduino. Figure 12 shows the schematic, Figure 13 shows the breadboard view for the Uno, and Figure 14 the breadboard view for the Nano.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"686\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/HBridge_switch_schem-2.png\" alt=\"Schematic Diagram of a pushbutton attached to an Arduino as a digital input. The pushbutton is connected to pin 2, and to Vcc. A 10-kilohm resistor connects from the pushbutton to ground.\" class=\"wp-image-9927\"\/><figcaption>Figure 12. Schematic Diagram of a <meta charset=\"utf-8\">pushbutton attached to an Arduino as a digital input. A 10-kilohm resistor connects from the <meta charset=\"utf-8\">pushbutton to ground.<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"455\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/HBridgeUnoSwitch_bb-1.png\" alt=\"Breadboard Diagram of a pushbutton attached to an Arduino Uno as a digital input. The pushbutton is connected to pin 2, and to Vcc. A 10-kilohm resistor connects from the pushbutton to ground.\" class=\"wp-image-9928\"\/><figcaption>Figure 13. Breadboard view of a <meta charset=\"utf-8\">pushbutton attached to an Arduino Uno. The Arduino is connected to a breadboard as described in the image above. A <meta charset=\"utf-8\">pushbutton is mounted in across the center section of the breadboard. A red wire connects from the left side voltage bus to the lower right pin of the <meta charset=\"utf-8\">pushbutton. A blue wire connects the upper left pin of the <meta charset=\"utf-8\">pushbutton to digital pin 2 on the Arduino. A 10-kilohm resistor connects the upper right pin of the pushbutton to the ground bus on the left side of the board.<\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/HBridgeNanoSwitch_bb-1.png\" alt=\"Breadboard Diagram of a pushbutton attached to an Arduino Nano as a digital input. The Nano is mounted across the center of the breadboadd with the USB connector facing upward. The pushbutton also mounted  is connected to pin 2, and to Vcc. A 10-kilohm resistor connects from the pushbutton to ground.\" class=\"wp-image-9929\" width=\"450\" height=\"710\"\/><figcaption>Figure 14. <meta charset=\"utf-8\">Breadboard view of a <meta charset=\"utf-8\">pushbutton attached to an Arduino Nano 33 IoT. <\/figcaption><\/figure><\/div>\n\n\n\n<p>As shown in Figure 14, the Nano is mounted across the center divide of the breadboard with the USB connector pointing up. A pushbutton is mounted in across the center section of the breadboard. A red wire connects from the left side voltage bus to the lower right pin of the pushbutton. A blue wire connects the upper left pin of the pushbutton to digital pin 2 on the Arduino. A 10-kilohm resistor connects the upper right pin of the pushbutton to the ground bus on the left side of the board.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Find_a_motor\"><\/span>Find a motor<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Find yourself a DC motor that runs on low DC voltage within the range of 3 &#8211; 15V.&nbsp; <a href=\"https:\/\/www.servocity.com\/right-angle-gear-motor\/\">This one<\/a> works well for this, or <a href=\"https:\/\/www.sparkfun.com\/products\/13302\">this one<\/a> or <a href=\"https:\/\/www.sparkfun.com\/products\/13258\">this one<\/a>. Discarded toys and printers can be good sources of these also. The ITP free store is almost always a goldmine for discarded motors and fans. Asking classmates and second years is another good approach.<\/p>\n\n\n\n<p>Solder leads to the motor&#8217;s terminals. The motor&#8217;s direction depends on the polarity, so it&#8217;s helpful to use different colors so you know which way the motor will turn when you hook it up.<\/p>\n\n\n\n<p><strong>Optional:<\/strong> Consider testing your motor with a bench power supply from the equipment room. Ask a teacher or resident if you need help setting one up. Begin by adjusting the voltage on the bench power supply and observe its effects. Take note of its speed at different voltages without dipping to low or too high.<\/p>\n\n\n\n<p><span style=\"color: #ff0000;\"><strong>Safety Warning:<\/strong><\/span> Running a motor at a voltage much lower or much higher than what it&#8217;s rated for could potentially damage or permanently destroy your motor. When the motor doesn&#8217;t spin, the voltage is too low. When the motor runs hot, or sounds like it&#8217;s straining, the voltage is too high.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Powering_Your_Motor\"><\/span>Powering Your Motor<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>If your motor can run on 5V (if you&#8217;re using an Uno) or 3.3V (if using a Nano 33 IoT ) and less than 500mA, you can use the Arduino&#8217;s USB voltage.&nbsp;Most motors require a higher voltage and higher current draw than this, however, so you will need an external power supply. You can use any DC power supply or battery up to 15V with this motor driver as long as your motor can run at that voltage, and as long as the supply can supply as much current as your motor needs. However you choose to power this circuit, <strong>make sure the power source is compatible with your motor<\/strong>.&nbsp;For example, don&#8217;t use a 9V battery for a 3V motor.<\/p>\n\n\n\n<p>The diagrams below show how to power the motor from an external power supply. To power directly from the Arduino&#8217;s V<sub>cc<\/sub>, connect the V<sub>MOT<\/sub> pin of the motor driver to the V<sub>cc<\/sub> pin on the Arduino (5V on Uno, 3.3V on Nano)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Set_up_the_Motor_Driver\"><\/span>Set up the Motor Driver<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This tutorial uses a Toshiba motor driver, the TB6612FNG, which can actually drive two motors.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.<\/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 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. There&#8217;s also a Standby pin that you have to connect to voltage through a 10-kilohm pullup resistor to activate the motor 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.<\/p>\n\n\n\n<ul 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><\/ul>\n\n\n\n<p>Figure 15 shows the Sparkfun board, and Figures 16 and 17 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.<\/p>\n\n\n\n<div class=\"wp-block-image\"><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 15. 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\"><figure class=\"aligncenter is-resized\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-motor-driver-pololu-front.jpg\"><img 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=\"389\" 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: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><figcaption>Figure 16. 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\"><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 17. 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\"><table><tbody><tr><th>AI1<\/th><th>AI2<\/th><th>PWMA<\/th><th>Effect<\/th><\/tr><tr><td>H<\/td><td>L<\/td><td>H<\/td><td>Motor turns one direction<\/td><\/tr><tr><td>L<\/td><td>H<\/td><td>H<\/td><td>Motor turns the other direction<\/td><\/tr><tr><td>L<\/td><td>L<\/td><td>&#8211;<\/td><td>Motor stop<\/td><\/tr><tr><td>H<\/td><td>H<\/td><td>&#8211;<\/td><td>Motor stop<\/td><\/tr><tr><td>&#8211;<\/td><td>&#8211;<\/td><td>L<\/td><td>Motor stop<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>For this lab, the PWMA pin connects to a digital pin on your Arduino so you can send it either HIGH or LOW and turn the motor ON or OFF, or pulse width modulate it to control the speed. 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.\n<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Connect_the_motor_to_the_Driver\"><\/span>Connect the motor to the Driver<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Connect the motor to the driver as shown in Figures 18 &#8211; 20. Figure 18 shows the schematic, Figure 19 shows the breadboard view for an Uno, and Figure 20 shows the breadboard view for a Nano.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"525\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/TB6612HBridge_schem-1.png\" alt=\"Schematic diagram of an Arduino connected to a motor driver to control a DC motor.\" class=\"wp-image-9930\"\/><figcaption>Figure 18. Schematic diagram of an Arduino connected to a motor driver to control a DC motor. The Arduino and switch are connected as described in the drawing above. A motor driver has been added, and is connected as follows: PWMA is connected to the Arduino&#8217;s digital pin 5. AIN1 is connected to digital pin 4. AIN2 is connected to digital pin 3 on the Arduino. AO1 and AO2 are connected to the DC motor&#8217;s two connections. The ground pins are connected to ground. V<sub>MOT<\/sub> is connected to the positive terminal of a DC power source for Arduino and the motor. The power source&#8217;s negative terminal is connected to ground. The motor driver&#8217;s V<sub>cc<\/sub> pin is connected to the Arduino&#8217;s voltage output (5V or 3.3V depending on your model). The Standby pin is connected to voltage through a 10-kilohm resistor. The rest of the driver pins are unconnected.<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"551\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/TB6612HBridgeUno_bb-2.png\" alt=\"Breadboard diagram of an Arduino Uno connected to a motor driver to control a DC motor.\" class=\"wp-image-9945\"\/><figcaption>Figure 19. Breadboard drawing of an Arduino connected to a motor driver to control a DC motor. The Arduino and switch are connected as described in the breadboard drawing above. A motor driver has been added, straddling the center of the breadboard. PWMA is connected to the Arduino&#8217;s digital pin 5. AIN1 is connected to digital pin 4. AIN2 is connected to digital pin 3 on the Arduino. AO1 and AO2 are connected to the DC motor&#8217;s two connections. The ground pins are connected to ground. V<sub>MOT<\/sub> is connected to the V<sub>IN<\/sub> terminal the Arduino, and the Arduino should be powered through its DC power jack. The power source&#8217;s negative terminal is connected to ground. The motor driver&#8217;s Vcc pin is connected to the Arduino&#8217;s voltage output (5V for the Uno). The Standby pin is connected to voltage through a 10-kilohm resistor. The rest of the driver pins are unconnected. A 100-microfarad capacitor has been added connecting the voltage and ground buses close to the motor driver, to act as a decoupling capacitor.<\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"444\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/TB6612HBridgeNano_bb-2.png\" alt=\"\" class=\"wp-image-10627\"\/><figcaption>Figure 20. Breadboard drawing of an Arduino Nano connected to a motor driver to control a DC motor. The Arduino and switch are connected as described in the breadboard drawing above. A DC power jack has been added, connected to the Nano&#8217;s ground and V<sub>in<\/sub> pin (pins 14 and 15, respectively). A motor driver has been added, straddling the center of the breadboard. PWMA is connected to the Arduino&#8217;s digital pin 5. AIN1 is connected to digital pin 4. AIN2 is connected to digital pin 3 on the Arduino. AO1 and AO2 are connected to the DC motor&#8217;s two connections. The ground pins are connected to ground. V<sub>MOT<\/sub> is connected to the Nano&#8217;s V<sub>in<\/sub> pin, which is connected to the positive terminal of the DC power source for the motor. The power source&#8217;s negative terminal is connected to ground. The motor driver&#8217;s Vcc pin is connected to the Arduino&#8217;s voltage output (3.3V). The Standby pin is connected to voltage through a 10-kilohm resistor. The rest of the driver pins are unconnected. A 100-microfarad capacitor has been added connecting the voltage and ground buses close to the motor driver, to act as a decoupling capacitor.<\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Note_on_decoupling_capacitors\"><\/span>Note on decoupling capacitors<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>If you find that your microcontroller is resetting whenever the motor turns on, add a capacitor across power and ground close to the motor. The capacitor will smooth out the voltage dips that occur when the motor turns on. This use of a capacitor is called a <strong>decoupling capacitor<\/strong>. Usually a 10 &#8211; 100uF capacitor will work. The larger the cap, the more charge it can hold, but the longer it will take to release its charge.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\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>Program the microcontroller to run the motor through the driver. First set up constants for the switch pin, the two motor driver pins, and the PWM enable pin of the motor driver. Use pin 5, one of the pins that can produce a PWM signal using <code>analogWrite()<\/code>,&nbsp; for the PWM enable pin.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nconst int switchPin = 2;    \/\/ switch input\nconst int motor1Pin = 3;    \/\/ Motor driver leg 1 (pin 3, AIN1)\nconst int motor2Pin = 4;    \/\/ Motor driver leg 2 (pin 4, AIN2)\nconst int pwmPin = 5;       \/\/ Motor driver PWM pin\n<\/pre><\/div>\n\n\n<p>In the <code>setup()<\/code>, set all the pins for the motor driver as outputs, and the pin for the switch as an input. Then set the PWM enable pin high so the driver can turn the motor on.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nvoid setup() {\n    \/\/ set the switch as an input:\n    pinMode(switchPin, INPUT); \n\n    \/\/ set all the other pins you're using as outputs:\n    pinMode(motor1Pin, OUTPUT);\n    pinMode(motor2Pin, OUTPUT);\n    pinMode(pwmPin, OUTPUT);\n\n    \/\/ set PWM enable pin high so that motor can turn on:\n    digitalWrite(pwmPin, HIGH);\n  }\n<\/pre><\/div>\n\n\n<p>In the main <code>loop()<\/code> read the switch. If it&#8217;s high, turn the motor one way by taking one motor driver pin high and the other low. If the switch is low, reverse the direction by reversing the states of the two pins.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nvoid loop() {\n    \/\/ if the switch is high, motor will turn on one direction:\n    if (digitalRead(switchPin) == HIGH) {\n      digitalWrite(motor1Pin, LOW);   \/\/ set leg 1 of the motor driver low\n      digitalWrite(motor2Pin, HIGH);  \/\/ set leg 2 of the motor driver high\n    }\n    \/\/ if the switch is low, motor will turn in the other direction:\n    else {\n      digitalWrite(motor1Pin, HIGH);  \/\/ set leg 1 of the motor driver high\n      digitalWrite(motor2Pin, LOW);   \/\/ set leg 2 of the motor driver low\n    }\n  }\n<\/pre><\/div>\n\n\n<p>Once you&#8217;ve seen this code working, try modifying the speed of the motor using the <a rel=\"noopener noreferrer\" href=\"https:\/\/www.arduino.cc\/en\/Reference\/AnalogWrite\" target=\"_blank\">analogWrite()<\/a> function, as explained in the <a rel=\"noopener noreferrer\" href=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/labs-arduino-digital-and-analog\/analog-in-with-an-arduino\/\" target=\"_blank\">Analog Lab<\/a>. Use <code>analogWrite()<\/code> on the PWM enable pin of the motor, and see what happens as you change the value of the <code>analogWrite()<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"An_Alternative_Motor_Driver\"><\/span>An Alternative Motor Driver<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you don&#8217;t have a TB6612FNG motor driver, or if you want something simpler and less expensive, the <a href=\"https:\/\/www.adafruit.com\/product\/4489\">L9110H driver<\/a> will also control a DC motor&#8217;s direction and speed. It can handle and input voltage of 2.5V-12V at 800mA of current. It can drive only one motor, unlike the TB6612FNG, and it can&#8217;t control stepper motors like that driver can. But it is inexpensive. <\/p>\n\n\n\n<p>THe L9110H comes in an 8-pin DIP package. There are two inputs, labeled the A and B channels, and they are connected to two outputs, also labeled A and B. Your motor connects to the outputs and your control pins connect to the inputs. V<sub>cc<\/sub> connects to the motor supply and GND connects to ground.  Its pins, numbered from top left in a U shape as usual, are as follows:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>OA &#8211; output for the A channel<\/li><li>V<sub>cc<\/sub> &#8211; motor supply voltage<\/li><li>V<sub>cc<\/sub> &#8211; motor supply voltage<\/li><li>OB output for the B channel<\/li><li>GND &#8211; ground<\/li><li>IA &#8211; input for the A channel<\/li><li>IB &#8211; input for the B channel<\/li><li>GND &#8211; ground<\/li><\/ol>\n\n\n\n<p>Figure 21 shows the schematic, and Figures 22 and 23 show it connected to an Uno and a Nano 33 IoT, respectively. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"525\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/L9110HBridge_schem.png\" alt=\"Schematic view of an L9110H H-bridge motor driver and a pushbutton connected to an Arduino. \" class=\"wp-image-9936\"\/><figcaption>Figure 21. Schematic view of an L9110H H-bridge motor driver connected to an Arduino. A pushbutton is connected to pin 2 of the Arduino as shown in the circuits above. An external DC power supply is connected to the Arduino and the motor as shown in the circuits above as well, along with a 100-microfarad decoupling capacitor. A DC motor is connected to pins OA and OB of the H-bridge. Pins Vcc are both connected to the DC power supply and pins GND are connected to ground. Pin IA is connected to pin 5 of the Arduino, and pin IB is connected to pin 6 of the Arduino. <\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"551\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/L9110HBridgeUno_bb-1.png\" alt=\"Breadboard view of an L9110H H-bridge motor driver and a pushbutton connected to an Arduino Uno. \" class=\"wp-image-9948\"\/><figcaption>Figure 22. <meta charset=\"utf-8\">Breadboard view of an L9110H H-bridge motor driver connected to an Arduino Uno. A pushbutton is connected to pin 2 of the Arduino as shown in the circuits above. The L9110H straddles the center divide of the breadboard with pins 1 and 8 facing the top of the diagram. The Arduino should be powered through its DC power jack. The V<sub>in<\/sub> pin of the Arduino connects to the L9110H&#8217;s  Vcc pins <meta charset=\"utf-8\">(physical pins 2 and 3). The motor is connected to the L9110H&#8217;s OA and OB pins <meta charset=\"utf-8\">(physical pins 1 and 4). A 100-microfarad decoupling capacitor is connected to the voltage and ground buses on the breadboard.  Pins GND (physical pins 5 and 8) are connected to ground. Pin IA (physical pin 6) is connected to pin 5 of the Arduino, and pin IB (physical pin 6) is connected to pin 6 of the Arduino.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"444\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/L9110HBridgeNano_bb-2.png\" alt=\"\" class=\"wp-image-10613\"\/><figcaption><meta charset=\"utf-8\">Figure 23. Breadboard drawing of an Arduino Nano connected to a  L9110H H-bridge motor driver to control a DC motor. The Arduino and switch are connected as described in the breadboard drawing above. A DC power jack has been added, connected to the Nano&#8217;s ground and V<sub>in<\/sub> pin (pins 14 and 15, respectively). <meta charset=\"utf-8\">The L9110H straddles the center divide of the breadboard with pins 1 and 8 facing the top of the diagram. The V<sub>in<\/sub> pin of the Arduino connects to the L9110H&#8217;s  Vcc pins <meta charset=\"utf-8\">(physical pins 2 and 3). The motor is connected to the L9110H&#8217;s OA and OB pins <meta charset=\"utf-8\">(physical pins 1 and 4). A 100-microfarad decoupling capacitor is connected to the voltage and ground buses on the breadboard.  THe L9110H&#8217;s ins GND (physical pins 5 and 8) are connected to ground. Pin IA (physical pin 6) is connected to pin 5 of the Nano, and pin IB (physical pin 6) is connected to pin 6 of the Nano.<\/figcaption><\/figure>\n\n\n\n<p>To control the motor, you take one input high and the other low, just like with the previous motor driver. Since this driver has no PWM pin, you have to pulsewidth modulate the high input to manage speed control, though.  <\/p>\n\n\n\n<p>The program below controls the L9110H, setting the speed to about half the maximum whenever you push the button. To make a variable speed you could add a potentiometer and change the value of the <code>speed<\/code> variable using the potentiometer. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nconst int switchPin = 2;  \/\/ pushbutton input\nconst int motor1Pin = 5;  \/\/ H-bridge leg 1 (pin 6, 1A)\nconst int motor2Pin = 6;  \/\/ H-bridge leg 2 (pin 7, 2A)\n\n\/\/ speed of the motor (0-255):\nint speed = 127;\n\nvoid setup() {\n  \/\/ set the pushbutton as an input:\n  pinMode(switchPin, INPUT);\n\n  \/\/ set all the other pins you're using as outputs:\n  pinMode(motor1Pin, OUTPUT);\n  pinMode(motor2Pin, OUTPUT);\n}\n\nvoid loop() {\n  \/\/ if the pushbutton is high, motor will turn on one direction:\n  if (digitalRead(switchPin) == HIGH) {\n    \/\/ set leg 1 of the H-bridge low:\n    digitalWrite(motor1Pin, LOW);\n    \/\/ set leg 2 of the H-bridge high:\n    analogWrite(motor2Pin, speed);\n  }\n  \/\/ if the pushbutton is low, motor will turn in the other direction:\n  else {\n    \/\/ set leg 1 of the H-bridge high:\n    digitalWrite(motor1Pin, speed);\n    \/\/ set leg 2 of the H-bridge low:\n    digitalWrite(motor2Pin, LOW);\n  }\n}\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Get_creative\"><\/span>Get creative<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Motors can be used to make things move, vibrate, rise, fall, roll, creep, or whatever you can think of, in response to user input from a digital input device (switch, floor sensor, tripwire, etc). Look inside moving toys, you&#8217;ll find a number of excellent motors and gears you can re-purpose. See the innards of a cymbal monkey below as an example. Perhaps you can re-design the user interface to a toy, using the microcontroller to mediate between new sensors on the toy and the motors of the toy. <\/p>\n\n\n\n<p>If you used a motor in this lab, consider any toys you have that have a motor you could take control over.&nbsp;<a href=\"https:\/\/www.youtube.com\/watch?v=kdlYb6J_vAc&amp;ab_channel=MrToystoystoys\">Charley Chimp<\/a>&#x2122; has a motor that\u2019s easy to control from an Arduino, for example.<\/p>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"400\" height=\"601\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/cymbal_monkey_innards.jpg\" alt=\"Photo of a toy monkey. The back has been removed to reveal the inner gear mechanism that plays the cymbals. At the center of a mechanism is a DC motor. Wires have been attached to it to run the motor from an H-bridge.\" class=\"wp-image-299\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/cymbal_monkey_innards.jpg 400w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/cymbal_monkey_innards-199x300.jpg 199w\" sizes=\"(max-width: 400px) 85vw, 400px\" \/><figcaption>Figure 21. The guts of a Charley Chimp&#x2122; cymbal-playing monkey.<\/figcaption><\/figure>\n\n\n\n<p>You could also consider simple movements in the work of artists like&nbsp;<a href=\"http:\/\/www.jennifertownley.com\/\">Jennifer Townley<\/a>,&nbsp;<a href=\"https:\/\/www.instagram.com\/p\/Cdy4opyDOiW\/\">Johannes Langenkamp<\/a>&nbsp;(<a href=\"https:\/\/www.instagram.com\/johannes_langkamp\/\">instagram<\/a>),&nbsp;<a href=\"https:\/\/www.nysoundworks.org\/soundart#\/bricolo\/\">Nick Yulman<\/a>, or <a href=\"https:\/\/www.lulyu.me\/work\/engagement\">Lu Lyu<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you&#8217;ll learn how to control a DC motor&#8217;s direction using a DC Motor Driver.<\/p>\n","protected":false},"author":17,"featured_media":0,"parent":1510,"menu_order":601,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[15,8,28],"tags":[],"class_list":["post-468","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\/468"}],"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\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/comments?post=468"}],"version-history":[{"count":92,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages\/468\/revisions"}],"predecessor-version":[{"id":10698,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages\/468\/revisions\/10698"}],"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=468"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/categories?post=468"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/tags?post=468"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}