{"id":405,"date":"2014-07-01T14:16:25","date_gmt":"2014-07-01T18:16:25","guid":{"rendered":"https:\/\/itp.nyu.edu\/physicalcomputing\/?page_id=405"},"modified":"2025-09-26T11:09:11","modified_gmt":"2025-09-26T15:09:11","slug":"using-a-transistor-to-control-high-current-loads-with-an-arduino","status":"publish","type":"page","link":"https:\/\/itp.nyu.edu\/physcomp\/labs\/motors-and-transistors\/using-a-transistor-to-control-high-current-loads-with-an-arduino\/","title":{"rendered":"Lab:  Using a Transistor to Control High Current Loads with an Arduino"},"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 high-current DC load such as a DC motor or an incandescent light from a microcontroller. Microcontrollers can only output a very small amount of current from their output pins. These pins are meant to send control signals, not to act as power supplies. The most common way to control another direct current device from a microcontroller is to use a transistor. Transistors allow you to control the flow of a high-current circuit from a low-current source.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Video: <a href=\"https:\/\/vimeo.com\/380347302\" target=\"_blank\" rel=\"noopener noreferrer\">Transistor Schematics<\/a><\/li>\n\n\n\n<li>Video: <a href=\"http:\/\/vimeo.com\/380174619\" target=\"_blank\" rel=\"noopener noreferrer\">Meet the motors<\/a><\/li>\n\n\n\n<li>Video: <a href=\"https:\/\/vimeo.com\/372277977\" target=\"_blank\" rel=\"noopener noreferrer\">Pulse-width modulating&nbsp;a transistor to to control a fan motor<\/a><\/li>\n\n\n\n<li>Video: <a href=\"https:\/\/vimeo.com\/380371240\" target=\"_blank\" rel=\"noopener noreferrer\">NPN Transistors<\/a><\/li>\n\n\n\n<li>Video: <a href=\"https:\/\/vimeo.com\/380371485\" target=\"_blank\" rel=\"noopener noreferrer\">Darlingtons and MOSFETs<\/a><\/li>\n<\/ul>\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 beforehand. If you\u2019re not, review the links below:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/itp.nyu.edu\/physcomp\/lessons\/microcontrollers-the-basics\/\" data-type=\"page\" data-id=\"821\" target=\"_blank\" rel=\"noreferrer noopener\">What is a microcontroller<\/a><\/li>\n\n\n\n<li>Beginning&nbsp;<a href=\"https:\/\/itp.nyu.edu\/physcomp\/lessons\/programming-terms-and-programming-environments\/\" data-type=\"page\" data-id=\"2006\" target=\"_blank\" rel=\"noreferrer noopener\">programming terms<\/a><\/li>\n\n\n\n<li><span style=\"font-style: inherit; font-weight: inherit; line-height: 1.5;\">What is a&nbsp;<\/span><a href=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/breadboard\/\" target=\"_blank\" rel=\"noreferrer noopener\">solderless breadboard<\/a><span style=\"font-style: inherit; font-weight: inherit; line-height: 1.5;\">&nbsp;and&nbsp;<\/span>how to use one<\/li>\n\n\n\n<li><a href=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/labs-arduino-digital-and-analog\/digital-input-and-output-with-an-arduino\/\" data-type=\"page\" data-id=\"957\" target=\"_blank\" rel=\"noreferrer noopener\">Digital Input and output<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/itp.nyu.edu\/physcomp\/lessons\/analog-output\/\" data-type=\"page\" data-id=\"579\" target=\"_blank\" rel=\"noreferrer noopener\">Analog Output<\/a><\/li>\n\n\n\n<li><a title=\"Electronics\" href=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/electronics\/\" target=\"_blank\" rel=\"noopener noreferrer\">Basic Electronics<\/a><\/li>\n\n\n\n<li><span style=\"color: #ff0000;\"><strong>Safety Warning:<\/strong><\/span>&nbsp;This tutorial shows you how to control high-current loads. This comes with a higher danger of injury from electricity than the earlier tutorials. Please be careful and double-check your wiring before plugging anything in, and never change your wiring while your circuit is powered.<\/li>\n<\/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 has-nested-images columns-5 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><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\" data-id=\"5921\" 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.\" 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=\"wp-element-caption\">Arduino Nano 33 IoT<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><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\" data-id=\"5908\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-jumper-wires.jpg\" alt=\"Photo of flexible 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=\"wp-element-caption\">Flexible jumper wires. These wires are quick for breadboard prototyping, but can get messy when you have lots of them on a board.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-breadboard.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"3836\" height=\"2877\" data-id=\"5909\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-breadboard.jpg\" alt=\"Photo of a solderless 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=\"wp-element-caption\">A solderless breadboard with two rows of holes along each side. 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. <\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><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\" data-id=\"5923\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-dc-motor.jpg\" alt=\"Photo of a DC Gearmotor\" 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=\"wp-element-caption\">Gearmotor. Any DC motor in the 3-15V DC range will work in with this circuit, though 4-6V is an ideal range.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/DC_power_jack.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"1000\" data-id=\"4696\" 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.\" 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=\"wp-element-caption\">A DC Power Jack<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/power_supply_01.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"560\" height=\"540\" data-id=\"1608\" 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.\" 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=\"wp-element-caption\"><meta charset=\"utf-8\"><\/meta>DC Power Supply to match your motor. If your motor is a 4-6V motor, you should use a 4-6V DC power supply.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/lamp_holder.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"400\" height=\"265\" data-id=\"321\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/lamp_holder.jpg\" alt=\"Small Incandescent lamp bulb and socket\" class=\"wp-image-321\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/lamp_holder.jpg 400w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/lamp_holder-300x198.jpg 300w\" sizes=\"(max-width: 400px) 85vw, 400px\" \/><\/a><figcaption class=\"wp-element-caption\">Small Incandescent lamp bulb and socket. You could use low-voltage DC LED lamps as well.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/diodes_400x.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"427\" data-id=\"796\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/diodes_400x.jpg\" alt=\"Diodes. Shown here are 1N400x power diodes.\" class=\"wp-image-796\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/diodes_400x.jpg 640w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/diodes_400x-300x200.jpg 300w\" sizes=\"(max-width: 640px) 85vw, 640px\" \/><\/a><figcaption class=\"wp-element-caption\">Diodes. Shown here are 1N400x power diodes.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-potentiometer.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"2882\" height=\"2162\" data-id=\"5924\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-potentiometer.jpg\" alt=\"Photo of two potentiometers\" class=\"wp-image-5924\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-potentiometer.jpg 2882w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-potentiometer-768x576.jpg 768w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-potentiometer-1280x960.jpg 1280w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><figcaption class=\"wp-element-caption\">Potentiometer<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/transistors.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"427\" height=\"640\" data-id=\"800\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/transistors.jpg\" alt=\"TIP120 transistor. The transistor here has the same physical package as the voltage regulators shown above. It has three legs and a tab at the top with a hole in it. The tab is the back of the component. If you hold the component with the tab at the top and the bulging side of the component facing you, the legs will be arranged, from left to right, base, collector, emitter. The only way to know the difference between two components of the same package is to read the label on the package, unfortunately. This one is labeled TIP120.\" class=\"wp-image-800\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/transistors.jpg 427w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/transistors-200x300.jpg 200w\" sizes=\"(max-width: 427px) 85vw, 427px\" \/><\/a><figcaption class=\"wp-element-caption\">TIP120 transistor<\/figcaption><\/figure>\n<figcaption class=\"blocks-gallery-caption wp-element-caption\"><meta charset=\"utf-8\">Figures 1-10. The parts you\u2019ll 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 11 and 12.<\/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 class=\"wp-element-caption\">Figure 11. 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 11 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 has-css-opacity\"\/>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabTemplateNanoShort_bb.png\"><img loading=\"lazy\" decoding=\"async\" width=\"455\" height=\"717\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabTemplateNanoShort_bb.png\" alt=\"Arduino Nano on a breadboard.\" class=\"wp-image-5903\" style=\"width:228px;height:359px\"\/><\/a><figcaption class=\"wp-element-caption\">Figure 12. Breadboard view of an Arduino Nano mounted on a solderless breadboard.<\/figcaption><\/figure><\/div>\n\n\n<p>As shown in Figure 12, 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 has-css-opacity\"\/>\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_potentiometer\"><\/span>Add a potentiometer<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Connect a potentiometer to analog in pin 0 of the module as shown in Figure 13 through Figure 15:<\/p>\n\n\n<div class=\"wp-block-image size-medium wp-image-3781\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"481\" height=\"552\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/potentiometer_schem1.png\" alt=\"Schematic view of a potentiometer. First leg of the potentiometer is connected to +5 volts. The second leg connected to analog in 0 of the Arduino. The third leg is connected to ground.\" class=\"wp-image-3781\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/potentiometer_schem1.png 481w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/potentiometer_schem1-261x300.png 261w\" sizes=\"(max-width: 481px) 85vw, 481px\" \/><figcaption class=\"wp-element-caption\">Figure 13. Schematic view of a potentiometer connected to analog in 0 of the Arduino<\/figcaption><\/figure><\/div>\n\n<div class=\"wp-block-image wp-image-3780 size-medium\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"372\" height=\"234\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/potentiometer_bb.png\" alt=\"Breadboard view of a potentiometer. First leg of the potentiometer is connected to +5 volts. The second leg connected to analog in 0 of the Arduino. The third leg is connected to ground.\" class=\"wp-image-3780\" style=\"width:372px;height:234px\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/potentiometer_bb.png 372w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/potentiometer_bb-300x189.png 300w\" sizes=\"(max-width: 372px) 85vw, 372px\" \/><figcaption class=\"wp-element-caption\">Figure 14. Breadboard view of a potentiometer connected to analog in 0 of an Arduino Uno. The potentiometer is mounted in three rows of the left center section of the breadboard. The two outside pins of the potentiometer are connected to the voltage and ground bus rows, respectively. The center pin is connected to analog in 0 of the Uno.<\/figcaption><\/figure><\/div>\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabPotentiometerInNano_bb.png\"><img loading=\"lazy\" decoding=\"async\" width=\"455\" height=\"719\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabPotentiometerInNano_bb.png\" alt=\"Breadboard view of a potentiometer connected to analog in 0 of an Arduino Nano. \" class=\"wp-image-6031\" style=\"width:341px;height:539px\"\/><\/a><figcaption class=\"wp-element-caption\">Figure 15. Breadboard view of a potentiometer connected to analog in 0 of an Arduino Nano. The potentiometer is mounted in three rows of the left center section of the breadboard below the Nano. The two outside pins of the potentiometer are connected to the voltage and ground bus rows, respectively. The center pin is connected to analog in 0 (physical pin 4) of the Nano.<\/figcaption><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Connect_a_Transistor_to_the_Microcontroller\"><\/span>Connect a Transistor to the Microcontroller<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The transistor allows you to control a circuit that&#8217;s carrying higher current and voltage from the microcontroller. It acts as an electronic switch. You can use a bipolar Darlington transistor like the TIP120, or you can use a MOSFET like the IRF520 or FQP30N06L for this lab. All three will work the same way and use the same circuit.  See Figures 16 through Figure 19 for the drawings and schematic symbols of the transistors. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized size-medium wp-image-1474 is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"331\" height=\"259\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/tip120_pinout1.png\" alt=\"Pinout drawing of a TIP-120 transistor. It is facing forward with the heat sink tab at the top and the bulging side of the component facing you. From left to right the legs are labelled 1. base, 2. collector, 3. emitter. \" class=\"wp-image-1474\" style=\"width:248px;height:194px\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/tip120_pinout1.png 331w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/tip120_pinout1-300x234.png 300w\" sizes=\"(max-width: 331px) 85vw, 331px\" \/><figcaption class=\"wp-element-caption\">Figure 16. Pinout drawing of a TIP-120 transistor. From left to right the legs are labelled 1. base, 2. collector, 3. emitter.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image wp-image-401 is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"82\" height=\"96\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/npntransistor.gif\" alt=\"The schematic symbol of an NPN transistor where B is the base, C is the collector, and E is the emitter. \" class=\"wp-image-401\"\/><figcaption class=\"wp-element-caption\">Figure 17. The schematic symbol of an NPN transistor. B is the base, C is the collector, and E is the emitter.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-medium wp-image-432 is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"220\" height=\"300\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/IRF520-220x300.png\" alt=\"NPN Transistor and N-Channel MOSFET side by side. The physical packages of the transistor and MOSFET are nearly identical. The pin out of the N-channel MOSFET is comparable to the transistor, where G of the MOSFET is the gate (equivalent of base of the transistor), D is the drain (equivalent of the collector) and S is the source (equivalent of the emitter).\" class=\"wp-image-432\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/IRF520-220x300.png 220w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/IRF520.png 328w\" sizes=\"(max-width: 220px) 85vw, 220px\" \/><figcaption class=\"wp-element-caption\">Figure 18. NPN Transistor and N-Channel MOSFET side by side with a schematic diagram of the MOSFET. G is the gate (equivalent of base), D is the drain (collector) and S is the source (emitter).<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image wp-image-430 is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"100\" height=\"107\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/N-channelMOSFET.png\" alt=\"Another version of the schematic symbol of an N-channel MOSFET, where G is the gate (equivalent of base), D is the drain (collector) and S is the source (emitter).\" class=\"wp-image-430\"\/><figcaption class=\"wp-element-caption\">Figure 19. Schematic symbol of an N-channel MOSFET, where G is the gate (equivalent of base), D is the drain (collector) and S is the source (emitter).<\/figcaption><\/figure>\n\n\n\n<p><meta charset=\"utf-8\"><\/p>\n\n\n\n<p>The <a style=\"font-size: revert;\" href=\"https:\/\/www.vishay.com\/docs\/91017\/irf520.pdf\">IRF520 MOSFET<\/a> has the same pin configuration as the TIP120, and performs similarly with a 5V gate voltage. The <a href=\"https:\/\/www.onsemi.com\/pub\/Collateral\/FQP30N06L-D.pdf\">FQP30N06L MOSFET<\/a> has the same pin configuration, and operates on as low as 1.0V, and works well for 3.3V applications. MOSFETs can generally handle more amperage and voltage, and switch a little faster (the difference is in microseconds, so you won&#8217;t notice), but they are more sensitive to static electricity damage. They are grouped into N-Channel and P-Channel, which are equivalent to NPN and PNP bipolar transistors. <\/p>\n\n\n\n<p>All three transistors mentioned here are designed for switching high-current loads. All of them have built-in protection diodes. Each has three connections Table 1 below details their connections.<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-regular\"><table><tbody><tr><th>Bipolar Transistor<\/th><th>MOSFET<\/th><td><strong>Connection<\/strong><\/td><\/tr><tr><td>Base<\/td><td>Gate<\/td><td>Connects to microcontroller output<\/td><\/tr><tr><td>Collector<\/td><td>Drain<\/td><td>Connects to power through load<\/td><\/tr><tr><td>Emitter<\/td><td>Source<\/td><td>Connects to ground<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">Table 1. Names of the pins on the bipolar transistor and the equivalent names on the MOSFETs<\/figcaption><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The datasheets for each of the recommended transistors can be found below:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li> <a class=\"urllink\" style=\"color: #37aad1;\" href=\"http:\/\/www.onsemi.com\/pub\/Collateral\/TIP120-D.PDF\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">TIP120 Bipolar Darlington Transistor<\/a><\/li>\n\n\n\n<li>&nbsp;<a href=\"https:\/\/www.vishay.com\/docs\/91017\/irf520.pdf\">IRF520 MOSFET<\/a> &#8211; good for 5V control<\/li>\n\n\n\n<li><a href=\"https:\/\/www.onsemi.com\/pdf\/datasheet\/fqp30n06l-d.pdf\">FQP30N06L MOSFET<\/a> &#8211; good for 3.3V control<\/li>\n<\/ul>\n\n\n\n<p>Here&#8217;s the main operating principle of using a transistor as a switch: When a small voltage and current is applied between the base (or gate) and the emitter (or source), the transistor allows a larger current to flow between the collector (or drain) and emitter (or source).<\/p>\n\n\n\n<p>Figures 20 through 22 show how to connect the transistor&#8217;s input to the microcontroller&#8217;s output. Note that this circuit isn&#8217;t complete, because the transistor isn&#8217;t controlling anything yet. <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"480\" height=\"416\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentArduinoTransistor_schem-3.png\" alt=\"Schematic view of a potentiometer and transistor connected to an Arduino. \" class=\"wp-image-9903\" style=\"width:480px;height:416px\"\/><figcaption class=\"wp-element-caption\">Figure 20. Schematic view of a potentiometer and transistor connected to an Arduino. First leg of the potentiometer is connected to +5 volts. The second leg connected to analog in 0 of the Arduino. The third leg is connected to ground. The base (or gate) of the transistor is connected to digital pin 9 of the Arduino through a 1-kilohm resistor. The emitter (or source) is connected to ground.<\/figcaption><\/figure><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentArduinoTransistor_bb.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1079\" height=\"703\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentArduinoTransistor_bb.png\" alt=\"Breadboard view of a potentiometer and transistor connected to an Arduino.\" class=\"wp-image-6156\" style=\"width:540px;height:352px\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentArduinoTransistor_bb.png 1079w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentArduinoTransistor_bb-768x500.png 768w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><figcaption class=\"wp-element-caption\">Figure 21. Breadboard view of a potentiometer and transistor connected to an Arduino. First leg of the potentiometer is connected to +5 volts. The second leg connected to analog in 0 of the Arduino. The third leg is connected to ground. The base (or gate) of the transistor is connected to digital pin 9 of the Arduino through a 1-kilohm resistor. The emitter (or drain) is connected to ground.<\/figcaption><\/figure><\/div>\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentNanoTransistor_bb.png\"><img loading=\"lazy\" decoding=\"async\" width=\"454\" height=\"717\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentNanoTransistor_bb.png\" alt=\"Breadboard view of a potentiometer and transistor connected to an Arduino Nano.\" class=\"wp-image-6159\" style=\"width:227px;height:359px\"\/><\/a><figcaption class=\"wp-element-caption\">Figure 22. Breadboard view of a potentiometer and transistor connected to an Arduino Nano. First leg of the potentiometer is connected to +3.3 volts.<meta charset=\"utf-8\"> The second leg connected to analog in 0 of the Arduino. The third leg is connected to ground. The base (or gate) of the transistor is connected to digital pin 9 of the Arduino through a 1-kilohm resistor. The emitter (or drain) is connected to ground.<\/figcaption><\/figure><\/div>\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Connect_a_Motor_and_Power_Supply\"><\/span>Connect a Motor and Power Supply<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Attach a DC motor to the collector (or drain) of the transistor as shown in Figures 23 through 25. Most motors will require more current than the microcontroller can supply, so you will need to add a separate power supply as well. If your motor runs on around 9V, you could use a 9V battery. A 5V motor might run on 4 AA batteries (6V).  You could also use a 12-volt DC wall adapter and a 5-volt regulator. A 12V battery may need a 12V DC wall adapter, or a 12V battery. The ground of the motor power supply should connect to the ground of the microcontroller on the breadboard.<\/p>\n\n\n\n<p><span style=\"color: #000000;\">Add a 1N4001 power diode in parallel with the collector and emitter of the transistor, pointing away from ground. The diode protects the transistor from back voltage generated when the motor shuts off, or if the motor is turned in the reverse direction. Used this way, the diode is called a <strong>protection diode<\/strong> or a <strong>snubber diode<\/strong>.<\/span> You can omit the diode if you don&#8217;t have one, as the transistors recommended here all have a built-in protection diode<\/p>\n\n\n<div class=\"wp-block-image is-resized\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"483\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentArduinoMotor_schem-2.png\" alt=\"Schematic view of a potentiometer connected to analog in 0 of the Arduino.\" class=\"wp-image-9904\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentArduinoMotor_schem-2.png 800w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentArduinoMotor_schem-2-768x464.png 768w\" sizes=\"(max-width: 800px) 85vw, 800px\" \/><figcaption class=\"wp-element-caption\">Figure 23. Schematic view of a potentiometer connected to analog in 0 of the Arduino. A transistor is connected to Digital Pin 9. A DC motor connects to the transistor and a DC jack. The DC jack connects its positive wire to the first wire of the DC motor. The negative wire of the DC jack connects to ground. The second wire of the DC motor connects to the collector (or drain) of the transistor. A 1N400x diode&#8217;s anode is connected to the collector (or drain), and its anode is connected to ground.<\/figcaption><\/figure><\/div>\n\n<div class=\"wp-block-image is-resized\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentArduinoMotor_bb-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1509\" height=\"703\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentArduinoMotor_bb-1.png\" alt=\"Breadboard view of an Arduino connected to a potentiometer, a transistor, a DC motor, and a DC jack. \" class=\"wp-image-6161\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentArduinoMotor_bb-1.png 1509w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentArduinoMotor_bb-1-768x358.png 768w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentArduinoMotor_bb-1-1280x596.png 1280w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><figcaption class=\"wp-element-caption\">Figure 24. Breadboard view of an Arduino connected to a potentiometer, a transistor, a DC motor, and a DC jack. A transistor is connected to Digital Pin 9. A DC motor connects to the transistor and a DC jack. The DC jack connects its positive wire to the first wire of the DC motor. The negative wire of the DC jack connects to ground. <meta charset=\"utf-8\">The second wire of the DC motor connects to the collector (or drain) of the transistor. A 1N400x diode&#8217;s anode is connected to the collector (or drain), and its anode is connected to ground.<\/figcaption><\/figure><\/div>\n\n<div class=\"wp-block-image is-resized\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentNanoMotor_bb.png\"><img loading=\"lazy\" decoding=\"async\" width=\"884\" height=\"717\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentNanoMotor_bb.png\" alt=\"Breadboard view of an Arduino Nano connected to a potentiometer, a transistor, a DC motor, and a DC jack. \" class=\"wp-image-6162\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentNanoMotor_bb.png 884w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentNanoMotor_bb-768x623.png 768w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><figcaption class=\"wp-element-caption\">Figure 25. Breadboard view of an Arduino Nano connected to a potentiometer, a transistor, a DC motor, and a DC jack. A transistor is connected to Digital Pin 9 through a 1-kilohm resistor. A DC motor connects to the transistor and a DC jack. The DC jack connects its positive wire to the first wire of the DC motor. The negative wire of the DC jack connects to ground. <meta charset=\"utf-8\">The second wire of the DC motor connects to the collector (or drain) of the transistor. A 1N400x diode&#8217;s anode is connected to the collector (or drain), and its anode is connected to ground.<\/figcaption><\/figure><\/div>\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p class=\"vspace\">Be sure to add the diode to your circuit correctly. The silver band on the diode denotes the cathode which is the tip of the arrow in the schematic, like so in Figure 26:<\/p>\n\n\n<div class=\"wp-block-image wp-image-453\">\n<figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"117\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/diode1-300x117.png\" alt=\"Schematic representation and physical representation of a diode. The schematic form shows an equilateral triangle with a line bisecting the triangle equally from one point to and through the middle of the opposing flat side. There is also a line perpendicular to the other line that also intersects the triangle at its bisected point. The cathode is represented by the side of the schematic with the line. The drawing of the physical form of the diode looks like a black resistor with only a single grey stripe on one side. The side with the stripe represents the cathode\" class=\"wp-image-453\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/diode1-300x117.png 300w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/diode1.png 459w\" sizes=\"(max-width: 300px) 85vw, 300px\" \/><figcaption class=\"wp-element-caption\">Figure 26. Schematic representation and physical representation of a diode. The silver band on the diode indicates the anode end.<\/figcaption><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Connect_a_Lamp_Instead_of_a_Motor\"><\/span>Connect a Lamp Instead of a Motor<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You could also attach a lamp using a transistor. There are many 12V incandescent lamps, designed for use in track lighting, gallery lighting, and so forth. Nowadays, there are many <a href=\"https:\/\/tigoe.github.io\/LightProjects\/led-lamps.html\">12V DC LED equivalents of the 12V AC lamps as well<\/a>.&nbsp; Here are a few examples:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.superbrightleds.com\/moreinfo\/household-bulb-sockets-adapters\/mr16-socket-mr11-bi-pin-socket-for-gu53g4gx53gy635gz4-base-bulbs\/499\/2027\/\">Bi-Pin Socket for GU5.3\/G4\/GX5.3\/GY6.35\/GZ4 Base Bulbs&nbsp;<\/a>&#8211; This socket works with the lamps below, and many others.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.superbrightleds.com\/moreinfo\/landscape-bulbs\/gy635-led-landscape-light-bulb-40-watt-equivalent-bi-pin-led-bulb-450-lumens\/4539\/10110\/\">GY6.35 LED Landscape Light Bulb &#8211; 40 Watt Equivalent &#8211; Bi-Pin LED Bulb &#8211; 450 Lumens<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.superbrightleds.com\/moreinfo\/landscape-bulbs\/gy635-led-landscape-light-bulb-40-watt-equivalent-bi-pin-led-bulb-275-lumens\/4541\/10111\/\">GY6.35 LED Landscape Light Bulb &#8211; 40 Watt Equivalent &#8211; Bi-Pin LED Bulb &#8211; 275 Lumens<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.superbrightleds.com\/moreinfo\/reflector-bulbs\/mr16-led-single-color-landscape-light-bulb-30-degree-35w-equivalent\/3665\/\">MR16 LED Single Color Landscape Light Bulb &#8211; 30 Degree &#8211; 35W Equivalent<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.ledlightinghut.com\/pvc-flexible-motorcycle-led-strip-light.html\">12V LED strip light, 19 in.<\/a><\/li>\n<\/ul>\n\n\n\n<p>The lamp circuit in Figures 27 through 29 assumes a 12V lamp. MOSFETs are generally best for switching incandescent and LED lamps, so the circuit below uses a MOSFET. In the lamp circuit, the protection diode is not needed, since there&#8217;s no way for the polarity to get reversed in this circuit.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentArduinoLamp_schem-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"976\" height=\"588\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentArduinoLamp_schem-1.png\" alt=\"Schematic view of a potentiometer, MOSFET, and lamp connected to an Arduino. \" class=\"wp-image-6166\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentArduinoLamp_schem-1.png 976w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentArduinoLamp_schem-1-768x463.png 768w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><figcaption class=\"wp-element-caption\">Figure 27. Schematic view of a potentiometer, MOSFET, and lamp connected to an Arduino. The gate of a MOSFET transistor is connected to Digital Pin 9 of the Arduino. A 12V lamp connects to the drain of the transistor and a DC jack. The DC jack connects its positive wire to the first wire of the lamp. The negative wire of the DC jack connects to ground. The second wire of the lamp connects to the drain of the transistor. The source of the transistor connects to ground.<\/figcaption><\/figure><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentArduinoLamp_bb.png\"><img loading=\"lazy\" decoding=\"async\" width=\"2420\" height=\"1363\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentArduinoLamp_bb.png\" alt=\"Breadboard view of a potentiometer, MOSFET, and lamp connected to an Arduino. \" class=\"wp-image-6165\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentArduinoLamp_bb.png 2420w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentArduinoLamp_bb-768x433.png 768w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentArduinoLamp_bb-1280x721.png 1280w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><figcaption class=\"wp-element-caption\">Figure 28. Breadboard view of a potentiometer, MOSFET, and lamp connected to an Arduino. The gate of a MOSFET transistor is connected to Digital Pin 9 of the Arduino. A 12V lamp connects to the drain of the transistor and a DC jack. The DC jack connects its positive wire to the first wire of the lamp. The negative wire of the DC jack connects to ground. The second wire of the lamp connects to the drain of the transistor. The source of the transistor connects to ground.<\/figcaption><\/figure><\/div>\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentNanoLamp_bb-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"839\" height=\"717\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentNanoLamp_bb-1.png\" alt=\"Breadboard view of a potentiometer, MOSFET, and lamp connected to an Nano. \" class=\"wp-image-6163\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentNanoLamp_bb-1.png 839w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabHighCurrentNanoLamp_bb-1-768x656.png 768w\" sizes=\"(max-width: 839px) 85vw, 839px\" \/><\/a><figcaption class=\"wp-element-caption\">Figure 29. Breadboard view of a potentiometer, MOSFET, and lamp connected to an Nano. The gate of a MOSFET transistor is connected to Digital Pin 9 of the Nano. A 12V lamp connects to the drain of the transistor and a DC jack. The DC jack connects its positive wire to the first wire of the lamp. The negative wire of the DC jack connects to ground. The second wire of the lamp connects to the drain of the transistor. The source of the transistor connects to ground.<\/figcaption><\/figure><\/div>\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>Write a program to test the circuit, whether it&#8217;s a motor or a lamp. Your program should make the transistor pin an output in the setup method. Then in the loop, it should turn the motor on and off every second, just like the&nbsp;<a class=\"urllink\" style=\"color: #37aad1;\" rel=\"nofollow noopener noreferrer\" href=\"http:\/\/arduino.cc\/en\/Tutorial\/Blink\" target=\"_blank\">blink sketch<\/a>&nbsp;does.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nconst int transistorPin = 9;    \/\/ connected to the base of the transistor\n\n void setup() {\n   \/\/ set  the transistor pin as output:\n   pinMode(transistorPin, OUTPUT);\n }\n\n void loop() {\n   digitalWrite(transistorPin, HIGH);\n   delay(1000);\n   digitalWrite(transistorPin, LOW);\n   delay(1000);\n }\n<\/pre><\/div>\n\n\n<p class=\"vspace\">Now that you see it working, try changing the speed of the motor or the intensity of the lamp using the potentiometer.<\/p>\n\n\n\n<p class=\"vspace\">To do that, read the voltage of the potentiometer using&nbsp;<code>analogRead()<\/code>. Then map the result to a range from 0 to 255 and save it in a new variable. Use that variable to set the speed of the motor or the brightness of the lamp using&nbsp;<code>analogWrite()<\/code>.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nconst int transistorPin = 9;    \/\/ connected to the base of the transistor\n\n void setup() {\n   \/\/ set  the transistor pin as output:\n   pinMode(transistorPin, OUTPUT);\n }\n\n void loop() {\n   \/\/ read the potentiometer:\n   int sensorValue = analogRead(A0);\n   \/\/ map the sensor value to a range from 0 - 255:\n   int outputValue = map(sensorValue, 0, 1023, 0, 255);\n   \/\/ use that to control the transistor:\n   analogWrite(transistorPin, outputValue);\n }\n<\/pre><\/div>\n\n\n<p><strong style=\"color: #ff0000;\">For the motor users:<\/strong> A motor controlled like this can only be turned in one direction. To be able to reverse the direction of the motor, an H-bridge circuit is required. For more on controlling DC motors with H-bridges, see the&nbsp;<a class=\"wikilink\" style=\"color: #37aad1;\" title=\"DC Motor Control Using an H-Bridge\" href=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/dc-motor-control-using-an-h-bridge\/\">DC Motor Control lab<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Come_Up_with_an_Application\"><\/span>Come Up with an Application<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Now that you&#8217;ve got motor or lamp control, come up with an application.  <\/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. <a href=\"https:\/\/www.youtube.com\/watch?v=kdlYb6J_vAc&amp;ab_channel=MrToystoystoys\">Charley Chimp<\/a>&#x2122; has a motor that&#8217;s easy to control from an Arduino, for example. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full 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 class=\"wp-element-caption\">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 <a href=\"http:\/\/www.jennifertownley.com\/\">Jennifer Townley<\/a>,  <a href=\"https:\/\/www.instagram.com\/p\/Cdy4opyDOiW\/\">Johannes Langenkamp<\/a> (<a href=\"https:\/\/www.instagram.com\/johannes_langkamp\/\">instagram<\/a>),  <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\n\n\n<p>You&#8217;ve got the beginnings of a good desk lamp or table lamp, if you chose to use a light bulb in this lab. How will you control it? How will you mount the switchor the dimmer knob? You might also want to consider a <a href=\"https:\/\/grandbrass.com\/pipe\/gooseneck-pipe\/\">gooseneck pipe<\/a> to mount your socket on, and a <a href=\"https:\/\/grandbrass.com\/1-8ips-female-by-pin-halogen-porcelain-socket-w-72in-leads-used-for-bases-g4-gx5-3-and-g6-35\/\">socket that goes with it<\/a>. Here are a few inspirations:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/store.moma.org\/for-the-home\/home\/lighting\/table-lamps\/heng-balance-lamp\/124653.html\">Heng Balance Lamp<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/lzf-lamps.com\/products\/swirl\">LZF Swirl<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/stickbulb.com\/\">Rux Designs Stickbulb<\/a><\/li>\n\n\n\n<li>Lyn Godley&#8217;s <a href=\"http:\/\/lyngodley.com\/portfolio\/crinkle-lamp\/\">Crinkle Lamp<\/a> and <a href=\"http:\/\/lyngodley.com\/portfolio\/wineglass-chandeliers\/\">wineglass chandeliers<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/www.julioleparc.org\/tablet\/lumi%C3%A8res.html\">Julio Leparc<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you&#8217;ll learn how to control a high-current DC load such as a DC motor or an incandescent light from a microcontroller.<\/p>\n","protected":false},"author":17,"featured_media":0,"parent":1510,"menu_order":602,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[15,8,29,28],"tags":[],"class_list":["post-405","page","type-page","status-publish","hentry","category-lab","category-motors","category-pwm","category-transistor"],"_links":{"self":[{"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages\/405"}],"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=405"}],"version-history":[{"count":147,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages\/405\/revisions"}],"predecessor-version":[{"id":13749,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages\/405\/revisions\/13749"}],"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=405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/categories?post=405"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/tags?post=405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}