Differences

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

Link to this comparison view

products:ardx:circ-07 [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>07</center></span></td></tr></table></div>
 +<div id="CIRC-465"><table height="100px" width="465px" valign="center"><tr><td><span class="subText"><center>.:Button Pressing:.<br>.:Pushbuttons:. </center></span></td></tr></table></div>
 +<div id="CIRC-100"><img src="http://www.ardx.org/src/circ/CIRC-07-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">Up to this point we have focused entirely on outputs, time to get our Arduino to listen, watch and feel. We'll start with a simple pushbutton. Wiring up the pushbutton is simple. There is one component, the pull up resistor, that might seem out of place. This is included because an Arduino doesn't sense the same way we do (ie button pressed, button unpressed). Instead it looks at the voltage on the pin and decides whether it is HIGH or LOW. The button is set up to pull the Arduino's pin LOW when it is pressed, however, when the button is unpressed the voltage of the pin will float (causing occasional errors). To get the Arduino to reliably read the pin as HIGH when the button is unpressed, we add the pull up resistor. <br>(note: the first example program uses only one of the two buttons) </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-07 <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/BUTT-01-60.png" width="60px" height="36px">
 +</td>
 +<td>
 +<span class="partsText">
 +Pushbutton<br>x2
 +</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>x2
 +</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-05R-60.png" width="60px" height="36px">
 +</td>
 +<td>
 +<span class="partsText">
 +Red 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-07-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/BBLS07">http://ardx.org/BBLS07</a></b><br><br><b>.:view:.</b><br>assembly video <b><br><a href="http://ardx.org/VIDE07">http://ardx.org/VIDE07</a></b></span></center>
 +            </div>
 +          </div>
 +        <div id="CIRC-circuitPicture">
 +          <center>
 +            <img src="http://www.ardx.org/src/circ/CIRC07-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; 2.Digital &gt; Button<br>(example from the great arduino.cc site, check it out for other great ideas) </span><br>
 +        <span class="code">        <prew>/*<br>
 +&nbsp;&nbsp;Button<br>
 +&nbsp;<br>
 +&nbsp;Turns&nbsp;on&nbsp;and&nbsp;off&nbsp;a&nbsp;light&nbsp;emitting&nbsp;diode(LED)&nbsp;connected&nbsp;to&nbsp;digital&nbsp;&nbsp;<br>
 +&nbsp;pin&nbsp;13,&nbsp;when&nbsp;pressing&nbsp;a&nbsp;pushbutton&nbsp;attached&nbsp;to&nbsp;pin&nbsp;7.&nbsp;<br>
 +&nbsp;<br>
 +&nbsp;<br>
 +&nbsp;The&nbsp;circuit:<br>
 +&nbsp;*&nbsp;LED&nbsp;attached&nbsp;from&nbsp;pin&nbsp;13&nbsp;to&nbsp;ground&nbsp;<br>
 +&nbsp;*&nbsp;pushbutton&nbsp;attached&nbsp;to&nbsp;pin&nbsp;2&nbsp;from&nbsp;+5V<br>
 +&nbsp;*&nbsp;10K&nbsp;resistor&nbsp;attached&nbsp;to&nbsp;pin&nbsp;2&nbsp;from&nbsp;ground<br>
 +&nbsp;<br>
 +&nbsp;*&nbsp;Note:&nbsp;on&nbsp;most&nbsp;Arduinos&nbsp;there&nbsp;is&nbsp;already&nbsp;an&nbsp;LED&nbsp;on&nbsp;the&nbsp;board<br>
 +&nbsp;attached&nbsp;to&nbsp;pin&nbsp;13.<br>
 +&nbsp;<br>
 +&nbsp;<br>
 +&nbsp;created&nbsp;2005<br>
 +&nbsp;by&nbsp;DojoDave&nbsp;<http://www.0j0.org><br>
 +&nbsp;modified&nbsp;17&nbsp;Jun&nbsp;2009<br>
 +&nbsp;by&nbsp;Tom&nbsp;Igoe<br>
 +&nbsp;<br>
 +&nbsp;&nbsp;http://www.arduino.cc/en/Tutorial/Button<br>
 +&nbsp;*/<br>
 +<br>
 +//&nbsp;constants&nbsp;won't&nbsp;change.&nbsp;They're&nbsp;used&nbsp;here&nbsp;to&nbsp;<br>
 +//&nbsp;set&nbsp;pin&nbsp;numbers:<br>
 +const&nbsp;int&nbsp;buttonPin&nbsp;=&nbsp;2;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;the&nbsp;number&nbsp;of&nbsp;the&nbsp;pushbutton&nbsp;pin<br>
 +const&nbsp;int&nbsp;ledPin&nbsp;=&nbsp;&nbsp;13;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;the&nbsp;number&nbsp;of&nbsp;the&nbsp;LED&nbsp;pin<br>
 +<br>
 +//&nbsp;variables&nbsp;will&nbsp;change:<br>
 +int&nbsp;buttonState&nbsp;=&nbsp;0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;variable&nbsp;for&nbsp;reading&nbsp;the&nbsp;pushbutton&nbsp;status<br>
 +<br>
 +void&nbsp;setup()&nbsp;{<br>
 +&nbsp;&nbsp;//&nbsp;initialize&nbsp;the&nbsp;LED&nbsp;pin&nbsp;as&nbsp;an&nbsp;output:<br>
 +&nbsp;&nbsp;pinMode(ledPin,&nbsp;OUTPUT);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
 +&nbsp;&nbsp;//&nbsp;initialize&nbsp;the&nbsp;pushbutton&nbsp;pin&nbsp;as&nbsp;an&nbsp;input:<br>
 +&nbsp;&nbsp;pinMode(buttonPin,&nbsp;INPUT);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
 +}<br>
 +<br>
 +void&nbsp;loop(){<br>
 +&nbsp;&nbsp;//&nbsp;read&nbsp;the&nbsp;state&nbsp;of&nbsp;the&nbsp;pushbutton&nbsp;value:<br>
 +&nbsp;&nbsp;buttonState&nbsp;=&nbsp;digitalRead(buttonPin);<br>
 +<br>
 +&nbsp;&nbsp;//&nbsp;check&nbsp;if&nbsp;the&nbsp;pushbutton&nbsp;is&nbsp;pressed.<br>
 +&nbsp;&nbsp;//&nbsp;if&nbsp;it&nbsp;is,&nbsp;the&nbsp;buttonState&nbsp;is&nbsp;HIGH:<br>
 +&nbsp;&nbsp;if&nbsp;(buttonState&nbsp;==&nbsp;HIGH)&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;turn&nbsp;LED&nbsp;on:&nbsp;&nbsp;&nbsp;&nbsp;<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;digitalWrite(ledPin,&nbsp;HIGH);&nbsp;&nbsp;<br>
 +&nbsp;&nbsp;}&nbsp;<br>
 +&nbsp;&nbsp;else&nbsp;{<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;turn&nbsp;LED&nbsp;off:<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;digitalWrite(ledPin,&nbsp;LOW);&nbsp;<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>Light Not Turning On </b></span><br><span class="regularText">The pushbutton is square and because of this it is easy to put it in the wrong way. Give it a 90 degree twist and see if it starts working.</span></center></div>
 +        <div id="CIRC-thepartsSideSpacer">&nbsp;</div>
 +        <div id="CIRC-nw2"><center><span class="regularText"><b>Light Not Fading </b></span><br><span class="regularText">A bit of a silly mistake we constantly made, when you switch from simple on off to fading remember to move the LED wire from pin 13 to pin 9.</span></center></div>
 +        <div id="CIRC-thepartsSideSpacer">&nbsp;</div>
 +        <div id="CIRC-nw3"><center><span class="regularText"><b>Underwhelmed? </b></span><br><span class="regularText">No worries these circuits are all super stripped down to make playing with the components easy, but once you throw them together the sky is the limit.</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>On button off button:</b> <BR>The initial example may be a little underwhelming (ie. I don't really need an Arduino to do this), lets make it a little more complicated. One button will turn the LED on the other will turn the LED off. Change the code to. <BR><span class="bigCode"> int ledPin = 13;        // choose the pin for the LED <BR>int inputPin1 = 3;      // button 1 <BR>int inputPin2 = 2;      // button 2 <BR>&nbsp; <BR>void setup() { <BR>&nbsp;&nbsp;pinMode(ledPin, OUTPUT);   // declare LED as output <BR>&nbsp;&nbsp;pinMode(inputPin1, INPUT); // make button 1 an input <BR>&nbsp;&nbsp;pinMode(inputPin2, INPUT); // make button 2 an input <BR>} <BR>&nbsp; <BR>void loop(){ <BR>&nbsp;&nbsp;if (digitalRead(inputPin1) == LOW) {  <BR>&nbsp;&nbsp;&nbsp;&nbsp;digitalWrite(ledPin, LOW);  // turn LED OFF <BR>&nbsp;&nbsp;} else if (digitalRead(inputPin2) == LOW) {       <BR>&nbsp;&nbsp;&nbsp;&nbsp;digitalWrite(ledPin, HIGH); // turn LED ON <BR>&nbsp;&nbsp;} <BR>} <BR></span>&nbsp; <BR>Upload the program to your board, and start toggling the LED on and off. <BR>&nbsp; <BR><b>Fading up and down:</b> <BR>Lets use the buttons to control an analog signal. To do this you will need to change the wire connecting the LED from pin 13 to pin 9, also change this in code. <BR><span class="bigCode">&nbsp;&nbsp;&nbsp;&nbsp; int ledPin = 13; ----> int ledPin = 9;</span> <BR>Next change the <span class="bigCode"> loop()</span> code to read. <BR>&nbsp; <BR><span class="bigCode"> int value = 0; <BR>void loop(){ <BR>&nbsp;&nbsp;if (digitalRead(inputPin1) == LOW) { value--; }  <BR>&nbsp;&nbsp;else if (digitalRead(inputPin2) == LOW) { value++; } <BR>&nbsp;&nbsp;value = constrain(value, 0, 255); <BR>&nbsp;&nbsp;analogWrite(ledPin, value); <BR>&nbsp;&nbsp;delay(10); <BR>}</span> <BR>&nbsp; <BR><b>Changing Fade Speed:</b> <BR>If you would like the LED to fade faster or slower, there is only one line of code that needs changing; <BR>&nbsp;&nbsp;<span class="bigCode"> delay(10);  ----> delay(new #);</span> <BR>To fade faster make the number smaller, slower requires a larger number.
 +</span></html>