Differences

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

Link to this comparison view

products:ardx:circ-08 [2012/03/14 04:58] (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>08</center></span></td></tr></table></div>
 +<div id="CIRC-465"><table height="100px" width="465px" valign="center"><tr><td><span class="subText"><center>.:Twisting:.<br>.:Potentiometers:. </center></span></td></tr></table></div>
 +<div id="CIRC-100"><img src="http://www.ardx.org/src/circ/CIRC-08-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">Along with the digital pins, the Arduino also has 6 pins which can be used for analog input. These inputs take a voltage (from 0 to 5 volts) and convert it to a digital number between 0 (0 volts) and 1023 (5 volts) (10 bits of resolution). A very useful device that exploits these inputs is a potentiometer (also called a variable resistor). When it is connected with 5 volts across its outer pins the middle pin will read some value between 0 and 5 volts dependent on the angle to which it is turned (ie. 2.5 volts in the middle). We can then use the returned values as a variable in our program. </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-08 <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/POT-103-60.png" width="60px" height="36px">
 +</td>
 +<td>
 +<span class="partsText">
 +Potentiometer<br>10k ohm <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/LED-05G-60.png" width="60px" height="36px">
 +</td>
 +<td>
 +<span class="partsText">
 +Green LED<br>x1
 +</span>
 +</td>
 +<td>
 +<img src="http://www.oomlout.com/parts/RES-561-60.png" width="60px" height="36px">
 +</td>
 +<td>
 +<span class="partsText">
 +560 Ohm Resistor<br>Green-Blue-Brown <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>
 +<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-08-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/BBLS08">http://ardx.org/BBLS08</a></b><br><br><b>.:view:.</b><br>assembly video <b><br><a href="http://ardx.org/VIDE08">http://ardx.org/VIDE08</a></b></span></center>
 +            </div>
 +          </div>
 +        <div id="CIRC-circuitPicture">
 +          <center>
 +            <img src="http://www.ardx.org/src/circ/CIRC08-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">File &gt; Examples &gt; 3.Analog &gt; AnalogInput<br>(example from the great arduino.cc site, check it out for other great ideas) </span><br>
 +        <span class="code">        <prew>/*<br>
 +&nbsp;&nbsp;Analog&nbsp;Input<br>
 +&nbsp;Demonstrates&nbsp;analog&nbsp;input&nbsp;by&nbsp;reading&nbsp;an&nbsp;analog&nbsp;sensor&nbsp;on&nbsp;analog&nbsp;pin&nbsp;0&nbsp;and<br>
 +&nbsp;turning&nbsp;on&nbsp;and&nbsp;off&nbsp;a&nbsp;light&nbsp;emitting&nbsp;diode(LED)&nbsp;&nbsp;connected&nbsp;to&nbsp;digital&nbsp;pin&nbsp;13.&nbsp;<br>
 +&nbsp;The&nbsp;amount&nbsp;of&nbsp;time&nbsp;the&nbsp;LED&nbsp;will&nbsp;be&nbsp;on&nbsp;and&nbsp;off&nbsp;depends&nbsp;on<br>
 +&nbsp;the&nbsp;value&nbsp;obtained&nbsp;by&nbsp;analogRead().&nbsp;<br>
 +&nbsp;<br>
 +&nbsp;The&nbsp;circuit:<br>
 +&nbsp;*&nbsp;Potentiometer&nbsp;attached&nbsp;to&nbsp;analog&nbsp;input&nbsp;0<br>
 +&nbsp;*&nbsp;center&nbsp;pin&nbsp;of&nbsp;the&nbsp;potentiometer&nbsp;to&nbsp;the&nbsp;analog&nbsp;pin<br>
 +&nbsp;*&nbsp;one&nbsp;side&nbsp;pin&nbsp;(either&nbsp;one)&nbsp;to&nbsp;ground<br>
 +&nbsp;*&nbsp;the&nbsp;other&nbsp;side&nbsp;pin&nbsp;to&nbsp;+5V<br>
 +&nbsp;*&nbsp;LED&nbsp;anode&nbsp;(long&nbsp;leg)&nbsp;attached&nbsp;to&nbsp;digital&nbsp;output&nbsp;13<br>
 +&nbsp;*&nbsp;LED&nbsp;cathode&nbsp;(short&nbsp;leg)&nbsp;attached&nbsp;to&nbsp;ground<br>
 +&nbsp;<br>
 +&nbsp;*&nbsp;Note:&nbsp;because&nbsp;most&nbsp;Arduinos&nbsp;have&nbsp;a&nbsp;built&#45;in&nbsp;LED&nbsp;attached&nbsp;<br>
 +&nbsp;to&nbsp;pin&nbsp;13&nbsp;on&nbsp;the&nbsp;board,&nbsp;the&nbsp;LED&nbsp;is&nbsp;optional.<br>
 +&nbsp;<br>
 +&nbsp;<br>
 +&nbsp;Created&nbsp;by&nbsp;David&nbsp;Cuartielles<br>
 +&nbsp;Modified&nbsp;16&nbsp;Jun&nbsp;2009<br>
 +&nbsp;By&nbsp;Tom&nbsp;Igoe<br>
 +&nbsp;<br>
 +&nbsp;http://arduino.cc/en/Tutorial/AnalogInput<br>
 +&nbsp;<br>
 +&nbsp;*/<br>
 +<br>
 +int&nbsp;sensorPin&nbsp;=&nbsp;0;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;select&nbsp;the&nbsp;input&nbsp;pin&nbsp;for&nbsp;the&nbsp;potentiometer<br>
 +int&nbsp;ledPin&nbsp;=&nbsp;13;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;select&nbsp;the&nbsp;pin&nbsp;for&nbsp;the&nbsp;LED<br>
 +int&nbsp;sensorValue&nbsp;=&nbsp;0;&nbsp;&nbsp;//&nbsp;variable&nbsp;to&nbsp;store&nbsp;the&nbsp;value&nbsp;coming&nbsp;from&nbsp;the&nbsp;sensor<br>
 +<br>
 +void&nbsp;setup()&nbsp;{<br>
 +&nbsp;&nbsp;//&nbsp;declare&nbsp;the&nbsp;ledPin&nbsp;as&nbsp;an&nbsp;OUTPUT:<br>
 +&nbsp;&nbsp;pinMode(ledPin,&nbsp;OUTPUT);&nbsp;&nbsp;<br>
 +}<br>
 +<br>
 +void&nbsp;loop()&nbsp;{<br>
 +&nbsp;&nbsp;//&nbsp;read&nbsp;the&nbsp;value&nbsp;from&nbsp;the&nbsp;sensor:<br>
 +&nbsp;&nbsp;sensorValue&nbsp;=&nbsp;analogRead(sensorPin);&nbsp;&nbsp;&nbsp;&nbsp;<br>
 +&nbsp;&nbsp;//&nbsp;turn&nbsp;the&nbsp;ledPin&nbsp;on<br>
 +&nbsp;&nbsp;digitalWrite(ledPin,&nbsp;HIGH);&nbsp;&nbsp;<br>
 +&nbsp;&nbsp;//&nbsp;stop&nbsp;the&nbsp;program&nbsp;for&nbsp;<sensorValue>&nbsp;milliseconds:<br>
 +&nbsp;&nbsp;delay(sensorValue);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
 +&nbsp;&nbsp;//&nbsp;turn&nbsp;the&nbsp;ledPin&nbsp;off:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
 +&nbsp;&nbsp;digitalWrite(ledPin,&nbsp;LOW);&nbsp;&nbsp;&nbsp;<br>
 +&nbsp;&nbsp;//&nbsp;stop&nbsp;the&nbsp;program&nbsp;for&nbsp;for&nbsp;<sensorValue>&nbsp;milliseconds:<br>
 +&nbsp;&nbsp;delay(sensorValue);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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> Sporadically Working </b></span><br><span class="regularText">This is most likely due to a slightly dodgy connection with the potentiometer's pins. This can usually be conquered by taping the potentiometer down.</span></center></div>
 +        <div id="CIRC-thepartsSideSpacer">&nbsp;</div>
 +        <div id="CIRC-nw2"><center><span class="regularText"><b>Not Working</b></span><br><span class="regularText">Make sure you haven't accidentally connected the potentiometer's wiper to digital pin 2 rather than analog pin 2. (the row of pins beneath the power pins)</span></center></div>
 +        <div id="CIRC-thepartsSideSpacer">&nbsp;</div>
 +        <div id="CIRC-nw3"><center><span class="regularText"><b>Still Backward</b></span><br><span class="regularText">You can try operating the circuit upside down. Sometimes this helps.</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>Threshold Switching:</b> <BR>Sometimes you will want to switch an output when a value exceeds a certain threshold. To do this with a potentiometer change the <span class="bigCode"> loop()</span> code to. <BR>&nbsp; <BR><span class="bigCode"> void loop() { <BR>&nbsp;&nbsp;int threshold = 512; <BR>&nbsp;&nbsp;if(analogRead(potPin) &gt; threshold){ digitalWrite(ledPin, HIGH);} <BR>&nbsp;&nbsp;else{ digitalWrite(ledPin, LOW);} <BR>}</span> <BR>&nbsp; <BR>This will cause the LED to turn on when the value is above 512 (about halfway), you can adjust the sensitivity by changing the threshold value. <BR>&nbsp; <BR><b>Fading:</b> <BR>Lets control the brightness of an LED directly from the potentiometer. To do this we need to first change the pin the LED is connected to. Move the wire from pin 13 to pin 9 and change one line in the code. <BR><span class="bigCode"> &nbsp;&nbsp;int ledPin = 13; ----> int ledPin = 9;</span> <BR>Then change the loop code to. <BR>  <span class="bigCode"> void loop() { <BR>&nbsp;&nbsp;int value = analogRead(potPin) / 4; <BR>&nbsp;&nbsp;analogWrite(ledPin, value); <BR>  }</span> <BR> &nbsp; <BR>Upload the code and watch as your LED fades in relation to your potentiometer spinning. (Note: the reason we divide the value by 4 is the analogRead() function returns a value from 0 to 1024 (10 bits), and analogWrite() takes a value from 0 to 255 (8 bits) ) <BR>&nbsp; <BR><b>Controlling a Servo:</b> <BR>This is a really neat example and brings a couple of circuits together. Wire up the servo like you did in CIRC-04, then open the example program Knob (File &gt; Examples &gt; Library-Servo &gt; Knob ), then change one line of code. <BR><span class="bigCode"> &nbsp;&nbsp;int potpin = 0; ----> int potpin = 2;</span> <BR>Upload to your Arduino and then watch as the servo shaft turns as you turn the potentiometer.  
 +</span></html>