Differences

This shows you the differences between two versions of the page.

Link to this comparison view

products:ardx:circ-03 [2012/09/07 01:10] (current)
Line 1: Line 1:
  
 +<html>
 +<div id="CIRC-head">
 +<div id="CIRC-100"><table height="100px" width="100px" valign="center"><tr><td><span class="headText"><center>CIRC<br>03</center></span></td></tr></table></div>
 +<div id="CIRC-465"><table height="100px" width="465px" valign="center"><tr><td><span class="subText"><center>.:Spin Motor Spin:.<br>.:Transistor &amp; Motor:.</center></span></td></tr></table></div>
 +<div id="CIRC-100"><img src="http://www.ardx.org/src/circ/CIRC-03-square-100.jpg" width="100" height="100"></div>
 +</div>
 +<span class="familyName"><center>(ARDX)   .:Arduino Expermentation Kit:.   (ARDX)</center></span>
 +<div id="CIRC-whitespace"></div>
 +<div id="CIRC-body">
 +<div id="CIRC-whitespace"></div><br>
 +<div id="CIRC-whatweredoing">
 +<span class="titleText">What We're Doing</span><br>
 +<span class="regularText">The Arduino's pins are great for directly controlling small electric items like LEDs. However, when dealing with larger items (like a toy motor or washing machine), an external transistor is required. A transistor is incredibly useful. It switches a lot of current using a much smaller current. A transistor has 3 pins. For a negative type (NPN) transistor, you connect your load to collector and the emitter to ground. Then when a small current flows from base to the emitter, a current will flow through the transistor and your motor will spin (this happens when we set our Arduino pin HIGH). There are literally thousands of different types of transistors, allowing every situation to be perfectly matched. We have chosen a P2N2222AG a rather common general purpose transistor. The important factors in our case are that its maximum voltage (40v) and its maximum current (200 milliamp) are both high enough for our toy motor (full details can be found on its datasheet <a href="http://ardx.org/2222 ">http://ardx.org/2222 </a>). <br>(The 1N4001 diode is acting as a flyback diode for details on why its there visit: <a href="http://ardx.org/4001 ">http://ardx.org/4001 </a>)</span>
 +</div><br>
 +<div id="CIRC-whitespace"></div><br>
 +<div id="CIRC-thecircuit">
 +<span class="titleText">The Circuit</span><br>
 +<div id="CIRC-thepartsSideSpacer">
 +</div>
 +        <div id="CIRC-theparts">
 +          <span class="smallTitleText">The Parts</span><br>
 +          <span class="regularText">
 +<table>
 +<tr>
 +<td>
 +<img src="http://www.oomlout.com/parts/CIRC-01-3dsheet-60.png" width="60px" height="36px">
 +</td>
 +<td>
 +<span class="partsText">
 +CIRC-03<br>Breadboard Sheet<br>x1
 +</span>
 +</td>
 +<td>
 +<img src="http://www.oomlout.com/parts/HEAD-02-60.png" width="60px" height="36px">
 +</td>
 +<td>
 +<span class="partsText">
 +2 Pin Header<br>x4
 +</span>
 +</td>
 +<td>
 +<img src="http://www.oomlout.com/parts/IC-2222A-60.png" width="60px" height="36px">
 +</td>
 +<td>
 +<span class="partsText">
 +Transistor<br>P2N2222AG  (TO92)<br>x1
 +</span>
 +</td>
 +<td>
 +
 +<img src="http://www.oomlout.com/parts/WIRE-01-60.png" width="60px" height="36px">
 +</td>
 +<td>
 +<span class="partsText">
 +Wire
 +</span>
 +</td>
 +</tr>
 +
 +<tr>
 +<td>
 +<img src="http://www.oomlout.com/parts/MOTOR-01-60.png" width="60px" height="36px">
 +</td>
 +<td>
 +<span class="partsText">
 +Toy Motor<br>x1
 +</span>
 +</td>
 +<td>
 +<img src="http://www.oomlout.com/parts/DIOD-01-60.png" width="60px" height="36px">
 +</td>
 +<td>
 +<span class="partsText">
 +Diode<br>(1N4001)<br>x1
 +</span>
 +</td>
 +<td>
 +<img src="http://www.oomlout.com/parts/RES-103-60.png" width="60px" height="36px">
 +</td>
 +<td>
 +<span class="partsText">
 +10k  Ohm Resistor<br>Brown-Black-Orange<br>x1
 +</span>
 +</td>
 +<td>
 +
 +<img src="http://www.oomlout.com/parts/BLANK.png" width="60px" height="36px">
 +</td>
 +<td>
 +<span class="partsText">
 +
 +</span>
 +</td>
 +</tr>
 +</table>
 +</span>
 +        </div><br>
 +        <div id="CIRC-whitespace"></div><br>
 +        <div id="CIRC-thepartsSideSpacer"></div>
 +          <div id="CIRC-circuitBox">
 +            <div id="CIRC-schematic"><center><span class="smallTitleText">Schematic</span><span class="smallTitleText"><img src="http://www.ardx.org/src/circ/ARDX-SC-03-150.png"></span></center></div>
 + <br>
 + <div id="CIRC-smallwhitespace">&nbsp;</div><br>
 +            <div id="CIRC-resources">
 + <center><span class="smallTitleText">Resources</span><br><span class="smallMediumDarkText"><b>.:download:.</b><br>breadboard layout sheet<br><b><a href="http://ardx.org/BBLS03">http://ardx.org/BBLS03</a></b><br><br><b>.:view:.</b><br>assembly video <b><br><a href="http://ardx.org/VIDE03">http://ardx.org/VIDE03</a></b></span></center>
 +            </div>
 +          </div>
 +        <div id="CIRC-circuitPicture">
 +          <center>
 +            <img src="http://www.ardx.org/src/circ/CIRC03-3dexploded-445.png" width="445">
 +          </center>
 +        </div>
 +      </div><br>
 +      <div id="CIRC-whitespace">&nbsp;</div><br>
 +<div id="CIRC-thecode">
 +        <span class="titleText">Code</span> <span class="smallDarkText">(no need to type everything in just)</span><br>
 +        <span class="mediumDarkText">Download the Code from ( <a href="http://ardx.org/CODE03 ">http://ardx.org/CODE03 </a>)<br>(and then copy the text and paste it into an empty Arduino Sketch)</span><br>
 +        <span class="code">        <prew>/*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;<br>
 +&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;Arduino&nbsp;Experimentation&nbsp;Kit&nbsp;Example&nbsp;Code&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|<br>
 +&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;CIRC&#45;03&nbsp;.:&nbsp;Spin&nbsp;Motor&nbsp;Spin&nbsp;:.&nbsp;(Transistor&nbsp;and&nbsp;Motor)&nbsp;&nbsp;&nbsp;|<br>
 +&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;<br>
 +&nbsp;*&nbsp;<br>
 +&nbsp;*&nbsp;The&nbsp;Arduinos&nbsp;pins&nbsp;are&nbsp;great&nbsp;for&nbsp;driving&nbsp;LEDs&nbsp;however&nbsp;if&nbsp;you&nbsp;hook&nbsp;<br>
 +&nbsp;*&nbsp;up&nbsp;something&nbsp;that&nbsp;requires&nbsp;more&nbsp;power&nbsp;you&nbsp;will&nbsp;quickly&nbsp;break&nbsp;them.<br>
 +&nbsp;*&nbsp;To&nbsp;control&nbsp;bigger&nbsp;items&nbsp;we&nbsp;need&nbsp;the&nbsp;help&nbsp;of&nbsp;a&nbsp;transistor.&nbsp;<br>
 +&nbsp;*&nbsp;Here&nbsp;we&nbsp;will&nbsp;use&nbsp;a&nbsp;transistor&nbsp;to&nbsp;control&nbsp;a&nbsp;small&nbsp;toy&nbsp;motor<br>
 +&nbsp;*&nbsp;<br>
 +&nbsp;*&nbsp;http://tinyurl.com/d4wht7<br>
 +&nbsp;*<br>
 +&nbsp;*/<br>
 +<br>
 +int&nbsp;motorPin&nbsp;=&nbsp;9;&nbsp;&nbsp;//&nbsp;define&nbsp;the&nbsp;pin&nbsp;the&nbsp;motor&nbsp;is&nbsp;connected&nbsp;to<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;(if&nbsp;you&nbsp;use&nbsp;pin&nbsp;9,10,11&nbsp;or&nbsp;3you&nbsp;can&nbsp;also&nbsp;control&nbsp;speed)<br>
 +<br>
 +/*<br>
 +&nbsp;*&nbsp;setup()&nbsp;&#45;&nbsp;this&nbsp;function&nbsp;runs&nbsp;once&nbsp;when&nbsp;you&nbsp;turn&nbsp;your&nbsp;Arduino&nbsp;on<br>
 +&nbsp;*&nbsp;We&nbsp;set&nbsp;the&nbsp;motors&nbsp;pin&nbsp;to&nbsp;be&nbsp;an&nbsp;output&nbsp;(turning&nbsp;the&nbsp;pin&nbsp;high&nbsp;(+5v)&nbsp;or&nbsp;low&nbsp;(ground)&nbsp;(&#45;))<br>
 +&nbsp;*&nbsp;rather&nbsp;than&nbsp;an&nbsp;input&nbsp;(checking&nbsp;whether&nbsp;a&nbsp;pin&nbsp;is&nbsp;high&nbsp;or&nbsp;low)<br>
 +&nbsp;*/<br>
 +void&nbsp;setup()<br>
 +{<br>
 +&nbsp;pinMode(motorPin,&nbsp;OUTPUT);&nbsp;<br>
 +}<br>
 +<br>
 +<br>
 +/*<br>
 +&nbsp;*&nbsp;loop()&nbsp;&#45;&nbsp;this&nbsp;function&nbsp;will&nbsp;start&nbsp;after&nbsp;setup&nbsp;finishes&nbsp;and&nbsp;then&nbsp;repeat<br>
 +&nbsp;*&nbsp;we&nbsp;call&nbsp;a&nbsp;function&nbsp;called&nbsp;motorOnThenOff()<br>
 +&nbsp;*/<br>
 +<br>
 +void&nbsp;loop()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;run&nbsp;over&nbsp;and&nbsp;over&nbsp;again<br>
 +{<br>
 +&nbsp;motorOnThenOff();<br>
 +&nbsp;//motorOnThenOffWithSpeed();<br>
 +&nbsp;//motorAcceleration();<br>
 +}<br>
 +<br>
 +/*<br>
 +&nbsp;*&nbsp;motorOnThenOff()&nbsp;&#45;&nbsp;turns&nbsp;motor&nbsp;on&nbsp;then&nbsp;off&nbsp;<br>
 +&nbsp;*&nbsp;(notice&nbsp;this&nbsp;code&nbsp;is&nbsp;identical&nbsp;to&nbsp;the&nbsp;code&nbsp;we&nbsp;used&nbsp;for<br>
 +&nbsp;*&nbsp;the&nbsp;blinking&nbsp;LED)<br>
 +&nbsp;*/<br>
 +void&nbsp;motorOnThenOff(){<br>
 +&nbsp;&nbsp;int&nbsp;onTime&nbsp;=&nbsp;2500;&nbsp;&nbsp;//the&nbsp;number&nbsp;of&nbsp;milliseconds&nbsp;for&nbsp;the&nbsp;motor&nbsp;to&nbsp;turn&nbsp;on&nbsp;for<br>
 +&nbsp;&nbsp;int&nbsp;offTime&nbsp;=&nbsp;1000;&nbsp;//the&nbsp;number&nbsp;of&nbsp;milliseconds&nbsp;for&nbsp;the&nbsp;motor&nbsp;to&nbsp;turn&nbsp;off&nbsp;for<br>
 +&nbsp;&nbsp;<br>
 +&nbsp;&nbsp;digitalWrite(motorPin,&nbsp;HIGH);&nbsp;//&nbsp;turns&nbsp;the&nbsp;motor&nbsp;On<br>
 +&nbsp;&nbsp;delay(onTime);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;waits&nbsp;for&nbsp;onTime&nbsp;milliseconds<br>
 +&nbsp;&nbsp;digitalWrite(motorPin,&nbsp;LOW);&nbsp;&nbsp;//&nbsp;turns&nbsp;the&nbsp;motor&nbsp;Off<br>
 +&nbsp;&nbsp;delay(offTime);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;waits&nbsp;for&nbsp;offTime&nbsp;milliseconds<br>
 +}<br>
 +<br>
 +/*<br>
 +&nbsp;*&nbsp;motorOnThenOffWithSpeed()&nbsp;&#45;&nbsp;turns&nbsp;motor&nbsp;on&nbsp;then&nbsp;off&nbsp;but&nbsp;uses&nbsp;speed&nbsp;values&nbsp;as&nbsp;well&nbsp;<br>
 +&nbsp;*&nbsp;(notice&nbsp;this&nbsp;code&nbsp;is&nbsp;identical&nbsp;to&nbsp;the&nbsp;code&nbsp;we&nbsp;used&nbsp;for<br>
 +&nbsp;*&nbsp;the&nbsp;blinking&nbsp;LED)<br>
 +&nbsp;*/<br>
 +void&nbsp;motorOnThenOffWithSpeed(){<br>
 +&nbsp;&nbsp;<br>
 +&nbsp;&nbsp;int&nbsp;onSpeed&nbsp;=&nbsp;200;&nbsp;&nbsp;//&nbsp;a&nbsp;number&nbsp;between&nbsp;0&nbsp;(stopped)&nbsp;and&nbsp;255&nbsp;(full&nbsp;speed)&nbsp;<br>
 +&nbsp;&nbsp;int&nbsp;onTime&nbsp;=&nbsp;2500;&nbsp;&nbsp;//the&nbsp;number&nbsp;of&nbsp;milliseconds&nbsp;for&nbsp;the&nbsp;motor&nbsp;to&nbsp;turn&nbsp;on&nbsp;for<br>
 +&nbsp;&nbsp;<br>
 +&nbsp;&nbsp;int&nbsp;offSpeed&nbsp;=&nbsp;50;&nbsp;&nbsp;//&nbsp;a&nbsp;number&nbsp;between&nbsp;0&nbsp;(stopped)&nbsp;and&nbsp;255&nbsp;(full&nbsp;speed)&nbsp;<br>
 +&nbsp;&nbsp;int&nbsp;offTime&nbsp;=&nbsp;1000;&nbsp;//the&nbsp;number&nbsp;of&nbsp;milliseconds&nbsp;for&nbsp;the&nbsp;motor&nbsp;to&nbsp;turn&nbsp;off&nbsp;for<br>
 +&nbsp;&nbsp;<br>
 +&nbsp;&nbsp;analogWrite(motorPin,&nbsp;onSpeed);&nbsp;&nbsp;&nbsp;//&nbsp;turns&nbsp;the&nbsp;motor&nbsp;On<br>
 +&nbsp;&nbsp;delay(onTime);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;waits&nbsp;for&nbsp;onTime&nbsp;milliseconds<br>
 +&nbsp;&nbsp;analogWrite(motorPin,&nbsp;offSpeed);&nbsp;&nbsp;//&nbsp;turns&nbsp;the&nbsp;motor&nbsp;Off<br>
 +&nbsp;&nbsp;delay(offTime);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;waits&nbsp;for&nbsp;offTime&nbsp;milliseconds<br>
 +}<br>
 +<br>
 +/*<br>
 +&nbsp;*&nbsp;motorAcceleration()&nbsp;&#45;&nbsp;accelerates&nbsp;the&nbsp;motor&nbsp;to&nbsp;full&nbsp;speed&nbsp;then<br>
 +&nbsp;*&nbsp;back&nbsp;down&nbsp;to&nbsp;zero<br>
 +*/<br>
 +void&nbsp;motorAcceleration(){<br>
 +&nbsp;&nbsp;int&nbsp;delayTime&nbsp;=&nbsp;50;&nbsp;//milliseconds&nbsp;between&nbsp;each&nbsp;speed&nbsp;step<br>
 +&nbsp;&nbsp;<br>
 +&nbsp;&nbsp;//Accelerates&nbsp;the&nbsp;motor<br>
 +&nbsp;&nbsp;for(int&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;<&nbsp;256;&nbsp;i++){&nbsp;//goes&nbsp;through&nbsp;each&nbsp;speed&nbsp;from&nbsp;0&nbsp;to&nbsp;255<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;analogWrite(motorPin,&nbsp;i);&nbsp;&nbsp;&nbsp;//sets&nbsp;the&nbsp;new&nbsp;speed<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;delay(delayTime);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;waits&nbsp;for&nbsp;delayTime&nbsp;milliseconds<br>
 +&nbsp;&nbsp;}<br>
 +&nbsp;&nbsp;<br>
 +&nbsp;&nbsp;//Decelerates&nbsp;the&nbsp;motor<br>
 +&nbsp;&nbsp;for(int&nbsp;i&nbsp;=&nbsp;255;&nbsp;i&nbsp;>=&nbsp;0;&nbsp;i&#45;&#45;){&nbsp;//goes&nbsp;through&nbsp;each&nbsp;speed&nbsp;from&nbsp;255&nbsp;to&nbsp;0<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;analogWrite(motorPin,&nbsp;i);&nbsp;&nbsp;&nbsp;//sets&nbsp;the&nbsp;new&nbsp;speed<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;delay(delayTime);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;waits&nbsp;for&nbsp;delayTime&nbsp;milliseconds<br>
 +&nbsp;&nbsp;}<br>
 +}<br>
 +<br>
 +        </prew></span>
 +      </div>
 +      <div id="CIRC-whitespace">&nbsp;</div><br>
 +<div id="CIRC-notWorking">
 +        <span class="titleText">Not Working?</span> <span class="smallDarkText">(3 things to try)</span>
 + <br><div id="CIRC-smallwhitespace">&nbsp;</div><br>
 + <div>
 +        <div id="CIRC-thepartsSideSpacer">&nbsp;</div>
 +        <div id="CIRC-nw1"><center><span class="regularText"><b>Motor Not Spinning? </b></span><br><span class="regularText">Motor Not Spinning? <br>If you sourced your own transistor, double check with the data sheet that the pinout is compatible with a P2N2222AG <br>(many are reversed).</span></center></div>
 +        <div id="CIRC-thepartsSideSpacer">&nbsp;</div>
 +        <div id="CIRC-nw2"><center><span class="regularText"><b>Still No Luck?</b></span><br><span class="regularText">If you sourced your own motor, double check that it will work with 5 volts and that it does not draw too much power.</span></center></div>
 +        <div id="CIRC-thepartsSideSpacer">&nbsp;</div>
 +        <div id="CIRC-nw3"><center><span class="regularText"><b>Still Not Working? </b></span><br><span class="regularText">Sometimes the Arduino board will disconnect from the computer. Try un-plugging and then re-plugging it into your USB port. </span></center></div>
 +        <div id="CIRC-thepartsSideSpacer">&nbsp;</div>
 +</div></div>
 +<div id="CIRC-whitespace">&nbsp;</div><br>
 +<div id="CIRC-makingBetter">
 +<span class="titleText">Making it Better?</span><br>&nbsp;<br>
 +<span class="regularText"><b>Controlling Speed:</b> <BR>We played with the Arduino's ability to control the brightness of an LED earlier now we will use the same feature to control the speed of our motor. The Arduino does this using something called Pulse Width Modulation (PWM). This relies on the Arduino's ability to operate really really fast. Rather than directly controlling the voltage coming from the pin the Arduino will switch the pin on and off very quickly. In the computer world this is going from 0 to 5 volts many times a second, but in the human world we see it as a voltage. For example if the Arduino is PWM'ing at 50% we see the light dimmed 50% because our eyes are not quick enough to see it flashing on and off. The same feature works with transistors. Don't believe me? Try it out. <BR>&nbsp; <BR>In the <span class="bigCode">loop()</span> section change it to this  <BR><span class="bigCode">// motorOnThenOff(); <BR>   motorOnThenOffWithSpeed(); <BR> //motorAcceleration();</span> <BR>Then upload the programme. You can change the speeds  by changing the variables onSpeed and offSpeed. <BR>&nbsp; <BR><b>Accelerating and decelerating:</b> <BR>Why stop at two speeds, why not accelerate and decelerate the motor. To do this simply change the <span class="bigCode">loop()</span> code to read <BR><span class="bigCode">// motorOnThenOff(); <BR>// motorOnThenOffWithSpeed(); <BR>   motorAcceleration();</span> <BR>&nbsp; <BR>Then upload the program and watch as your motor slowly accelerates up to full speed then slows down again. If you would like to change the speed of acceleration change the variable delayTime (larger means a longer acceleration time). <BR>
 +</span></html>