Differences

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

Link to this comparison view

products:ardx:circ-09 [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>09</center></span></td></tr></table></div>
 +<div id="CIRC-465"><table height="100px" width="465px" valign="center"><tr><td><span class="subText"><center>.:Light:.<br>.:Photo Resistors:. </center></span></td></tr></table></div>
 +<div id="CIRC-100"><img src="http://www.ardx.org/src/circ/CIRC-09-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">Whilst getting input from a potentiometer can be useful for human controlled experiments, what do we use when we want an environmentally controlled experiment? We use exactly the same principles but instead of a potentiometer (twist based resistance) we use a photo resistor (light based resistance). The Arduino cannot directly sense resistance (it senses voltage) so we set up a voltage divider (<a href="http://ardx.org/VODI ">http://ardx.org/VODI </a>). The exact voltage at the sensing pin is calculable, but for our purposes (just sensing relative light) we can experiment with the values and see what works for us. A low value will occur when the sensor is well lit while a high value will occur when it is in darkness. </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-09 <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-PHOTO-01-60.png" width="60px" height="36px">
 +</td>
 +<td>
 +<span class="partsText">
 +Photo-Resistor<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/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/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/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/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-09-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/BBLS09">http://ardx.org/BBLS09</a></b><br><br><b>.:view:.</b><br>assembly video <b><br><a href="http://ardx.org/VIDE09">http://ardx.org/VIDE09</a></b></span></center>
 +            </div>
 +          </div>
 +        <div id="CIRC-circuitPicture">
 +          <center>
 +            <img src="http://www.ardx.org/src/circ/CIRC09-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/CODE09 ">http://ardx.org/CODE09 </a>)<br>(copy the text and paste it into an empty Arduino Sketch) </span><br>
 +        <span class="code">        <prew>/*<br>
 +&nbsp;*&nbsp;A&nbsp;simple&nbsp;programme&nbsp;that&nbsp;will&nbsp;change&nbsp;the&nbsp;intensity&nbsp;of<br>
 +&nbsp;*&nbsp;an&nbsp;LED&nbsp;based&nbsp;&nbsp;*&nbsp;on&nbsp;the&nbsp;amount&nbsp;of&nbsp;light&nbsp;incident&nbsp;on&nbsp;<br>
 +&nbsp;*&nbsp;the&nbsp;photo&nbsp;resistor.<br>
 +&nbsp;*&nbsp;<br>
 +&nbsp;*/<br>
 +<br>
 +//PhotoResistor&nbsp;Pin<br>
 +int&nbsp;lightPin&nbsp;=&nbsp;0;&nbsp;//the&nbsp;analog&nbsp;pin&nbsp;the&nbsp;photoresistor&nbsp;is&nbsp;<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//connected&nbsp;to<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//the&nbsp;photoresistor&nbsp;is&nbsp;not&nbsp;calibrated&nbsp;to&nbsp;any&nbsp;units&nbsp;so<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//this&nbsp;is&nbsp;simply&nbsp;a&nbsp;raw&nbsp;sensor&nbsp;value&nbsp;(relative&nbsp;light)<br>
 +//LED&nbsp;Pin<br>
 +int&nbsp;ledPin&nbsp;=&nbsp;9;&nbsp;&nbsp;&nbsp;//the&nbsp;pin&nbsp;the&nbsp;LED&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;//we&nbsp;are&nbsp;controlling&nbsp;brightness&nbsp;so&nbsp;<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//we&nbsp;use&nbsp;one&nbsp;of&nbsp;the&nbsp;PWM&nbsp;(pulse&nbsp;width<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;modulation&nbsp;pins)<br>
 +void&nbsp;setup()<br>
 +{<br>
 +&nbsp;&nbsp;pinMode(ledPin,&nbsp;OUTPUT);&nbsp;//sets&nbsp;the&nbsp;led&nbsp;pin&nbsp;to&nbsp;output<br>
 +}<br>
 +&nbsp;/*<br>
 +&nbsp;*&nbsp;loop()&nbsp;&#45;&nbsp;this&nbsp;function&nbsp;will&nbsp;start&nbsp;after&nbsp;setup&nbsp;<br>
 +&nbsp;*&nbsp;finishes&nbsp;and&nbsp;then&nbsp;repeat<br>
 +&nbsp;*/<br>
 +void&nbsp;loop()<br>
 +{<br>
 +&nbsp;int&nbsp;lightLevel&nbsp;=&nbsp;analogRead(lightPin);&nbsp;//Read&nbsp;the<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;lightlevel<br>
 +&nbsp;lightLevel&nbsp;=&nbsp;map(lightLevel,&nbsp;0,&nbsp;900,&nbsp;0,&nbsp;255);&nbsp;<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//adjust&nbsp;the&nbsp;value&nbsp;0&nbsp;to&nbsp;900&nbsp;to<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//span&nbsp;0&nbsp;to&nbsp;255<br>
 +<br>
 +<br>
 +<br>
 +&nbsp;lightLevel&nbsp;=&nbsp;constrain(lightLevel,&nbsp;0,&nbsp;255);//make&nbsp;sure&nbsp;the&nbsp;<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//value&nbsp;is&nbsp;between&nbsp;<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//0&nbsp;and&nbsp;255<br>
 +&nbsp;analogWrite(ledPin,&nbsp;lightLevel);&nbsp;&nbsp;//write&nbsp;the&nbsp;value<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>LED Remains Dark</b></span><br><span class="regularText">This is a mistake we continue to make time and time again, if only they could make an LED that worked both ways. Pull it up and give it a twist.</span></center></div>
 +        <div id="CIRC-thepartsSideSpacer">&nbsp;</div>
 +        <div id="CIRC-nw2"><center><span class="regularText"><b>It Isn't Responding to Changes in Light.</b></span><br><span class="regularText">Given that the spacing of the wires on the photo-resistor is not standard, it is easy to misplace it. Double check its in the right place.</span></center></div>
 +        <div id="CIRC-thepartsSideSpacer">&nbsp;</div>
 +        <div id="CIRC-nw3"><center><span class="regularText"><b>Still not quite working?</b></span><br><span class="regularText">You may be in a room which is either too bright or dark. Try turning the lights on or off to see if this helps. Or if you have a flashlight near by give that a try.</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>Reverse the response:</b> <BR>Perhaps you would like the opposite response. Don't worry we can easily reverse this response just change: <BR><span class="bigCode">&nbsp;&nbsp;&nbsp;&nbsp;analogWrite(ledPin, lightLevel);  <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;----> analogWrite(ledPin, 255 - lightLevel);</span> <BR>&nbsp; <BR>Upload and watch the response change: <BR>&nbsp; <BR><b>Night light:</b> <BR>Rather than controlling the brightness of the LED in response to light, lets instead turn it on or off based on a threshold value. Change the <span class="bigCode"> loop()</span> code with. <BR>  <span class="bigCode"> void loop(){ <BR>&nbsp;&nbsp;int threshold = 300; <BR>&nbsp;&nbsp;if(analogRead(lightPin) &gt; threshold){ <BR>&nbsp;&nbsp;&nbsp;&nbsp;digitalWrite(ledPin, HIGH); <BR>&nbsp;&nbsp;}else{ <BR>&nbsp;&nbsp;&nbsp;&nbsp;digitalWrite(ledPin, LOW);     <BR>&nbsp;&nbsp;} <BR>}</span> <BR>&nbsp; <BR><b>Light controlled servo:</b> <BR>Lets use our newly found light sensing skills to control a servo (and at the same time engage in a little bit of Arduino code hacking). Wire up a servo connected to pin 9 (like in CIRC-04). Then open the Knob example program (the same one we used in CIRC-08) File &gt; Examples &gt; Library-Servo &gt; Knob. Upload the code to your board and watch as it works unmodified. <BR>&nbsp; <BR><b>Using the full range of your servo:</b> <BR>You'll notice that the servo will only operate over a limited portion of its range. This is because with the voltage dividing circuit we use the voltage on analog pin 0 will not range from 0 to 5 volts but instead between two lesser values (these values will change based on your setup). To  fix this play with the val = map(val, 0, 1023, 0, 179); line. For hints on what to do visit <a href="http://arduino.cc/en/Reference/Map ">http://arduino.cc/en/Reference/Map </a>.
 +</span></html>