Differences

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

Link to this comparison view

products:ardx:circ-06 [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>06</center></span></td></tr></table></div>
 +<div id="CIRC-465"><table height="100px" width="465px" valign="center"><tr><td><span class="subText"><center>.:Music:.<br>.:Piezo Elements:.<br> </center></span></td></tr></table></div>
 +<div id="CIRC-100"><img src="http://www.ardx.org/src/circ/CIRC-06-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">To this point we have controlled light, motion, and electrons. Let's tackle sound next. But sound is an analog phenomena, how will our digital Arduino cope? We will once again rely on its incredible speed which will let it mimic analog behavior. To do this, we will attach a piezo element to one of the Arduino's digital pins. A piezo element makes a clicking sound each time it is pulsed with current. If we pulse it at the right frequency (for example 440 times a second to make the note middle A) these clicks will run together to produce notes. Let's get to experimenting with it and get your Arduino playing "Twinkle Twinkle Little Star". </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-06<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/PIEZ-01-60.png" width="60px" height="36px">
 +</td>
 +<td>
 +<span class="partsText">
 +Piezo Element<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/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>
 +<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-06-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/BBLS06">http://ardx.org/BBLS06</a></b><br><br><b>.:view:.</b><br>assembly video <b><br><a href="http://ardx.org/VIDE06">http://ardx.org/VIDE06</a></b></span></center>
 +            </div>
 +          </div>
 +        <div id="CIRC-circuitPicture">
 +          <center>
 +            <img src="http://www.ardx.org/src/circ/CIRC06-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/CODE06 ">http://ardx.org/CODE06 </a>)<br>(copy the text and paste it into an empty Arduino Sketch) </span><br>
 +        <span class="code">        <prew>/*&nbsp;Melody<br>
 +&nbsp;*&nbsp;(cleft)&nbsp;2005&nbsp;D.&nbsp;Cuartielles&nbsp;for&nbsp;K3<br>
 +&nbsp;*<br>
 +&nbsp;*&nbsp;This&nbsp;example&nbsp;uses&nbsp;a&nbsp;piezo&nbsp;speaker&nbsp;to&nbsp;play&nbsp;melodies.&nbsp;&nbsp;It&nbsp;sends<br>
 +&nbsp;*&nbsp;a&nbsp;square&nbsp;wave&nbsp;of&nbsp;the&nbsp;appropriate&nbsp;frequency&nbsp;to&nbsp;the&nbsp;piezo,&nbsp;generating<br>
 +&nbsp;*&nbsp;the&nbsp;corresponding&nbsp;tone.<br>
 +&nbsp;*<br>
 +&nbsp;*&nbsp;The&nbsp;calculation&nbsp;of&nbsp;the&nbsp;tones&nbsp;is&nbsp;made&nbsp;following&nbsp;the&nbsp;mathematical<br>
 +&nbsp;*&nbsp;operation:<br>
 +&nbsp;*<br>
 +&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timeHigh&nbsp;=&nbsp;period&nbsp;/&nbsp;2&nbsp;=&nbsp;1&nbsp;/&nbsp;(2&nbsp;*&nbsp;toneFrequency)<br>
 +&nbsp;*<br>
 +&nbsp;*&nbsp;where&nbsp;the&nbsp;different&nbsp;tones&nbsp;are&nbsp;described&nbsp;as&nbsp;in&nbsp;the&nbsp;table:<br>
 +&nbsp;*<br>
 +&nbsp;*&nbsp;note&nbsp; frequency&nbsp; period&nbsp; timeHigh<br>
 +&nbsp;*&nbsp;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;&nbsp;&nbsp;&nbsp;&nbsp;2028 1014 <br>
 +&nbsp;*&nbsp;C &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;523&nbsp;Hz &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1912&nbsp; 956<br>
 +&nbsp;*<br>
 +&nbsp;*&nbsp;http://www.arduino.cc/en/Tutorial/Melody<br>
 +&nbsp;*/<br>
 +&nbsp;&nbsp;<br>
 +int&nbsp;speakerPin&nbsp;=&nbsp;9;<br>
 +<br>
 +int&nbsp;length&nbsp;=&nbsp;15;&nbsp;//&nbsp;the&nbsp;number&nbsp;of&nbsp;notes<br>
 +char&nbsp;notes[]&nbsp;=&nbsp;"ccggaagffeeddc&nbsp;";&nbsp;//&nbsp;a&nbsp;space&nbsp;represents&nbsp;a&nbsp;rest<br>
 +int&nbsp;beats[]&nbsp;=&nbsp;{&nbsp;1,&nbsp;1,&nbsp;1,&nbsp;1,&nbsp;1,&nbsp;1,&nbsp;2,&nbsp;1,&nbsp;1,&nbsp;1,&nbsp;1,&nbsp;1,&nbsp;1,&nbsp;2,&nbsp;4&nbsp;};<br>
 +int&nbsp;tempo&nbsp;=&nbsp;300;<br>
 +<br>
 +void&nbsp;playTone(int&nbsp;tone,&nbsp;int&nbsp;duration)&nbsp;{<br>
 +&nbsp;&nbsp;for&nbsp;(long&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;<&nbsp;duration&nbsp;*&nbsp;1000L;&nbsp;i&nbsp;+=&nbsp;tone&nbsp;*&nbsp;2)&nbsp;{<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;digitalWrite(speakerPin,&nbsp;HIGH);<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;delayMicroseconds(tone);<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;digitalWrite(speakerPin,&nbsp;LOW);<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;delayMicroseconds(tone);<br>
 +&nbsp;&nbsp;}<br>
 +}<br>
 +<br>
 +void&nbsp;playNote(char&nbsp;note,&nbsp;int&nbsp;duration)&nbsp;{<br>
 +&nbsp;&nbsp;char&nbsp;names[]&nbsp;=&nbsp;{&nbsp;'c',&nbsp;'d',&nbsp;'e',&nbsp;'f',&nbsp;'g',&nbsp;'a',&nbsp;'b',&nbsp;'C'&nbsp;};<br>
 +&nbsp;&nbsp;int&nbsp;tones[]&nbsp;=&nbsp;{&nbsp;1915,&nbsp;1700,&nbsp;1519,&nbsp;1432,&nbsp;1275,&nbsp;1136,&nbsp;1014,&nbsp;956&nbsp;};<br>
 +&nbsp;&nbsp;<br>
 +&nbsp;&nbsp;//&nbsp;play&nbsp;the&nbsp;tone&nbsp;corresponding&nbsp;to&nbsp;the&nbsp;note&nbsp;name<br>
 +&nbsp;&nbsp;for&nbsp;(int&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;<&nbsp;8;&nbsp;i++)&nbsp;{<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(names[i]&nbsp;==&nbsp;note)&nbsp;{<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;playTone(tones[i],&nbsp;duration);<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;}<br>
 +&nbsp;&nbsp;}<br>
 +}<br>
 +<br>
 +void&nbsp;setup()&nbsp;{<br>
 +&nbsp;&nbsp;pinMode(speakerPin,&nbsp;OUTPUT);<br>
 +}<br>
 +<br>
 +void&nbsp;loop()&nbsp;{<br>
 +&nbsp;&nbsp;for&nbsp;(int&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;<&nbsp;length;&nbsp;i++)&nbsp;{<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(notes[i]&nbsp;==&nbsp;'&nbsp;')&nbsp;{<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delay(beats[i]&nbsp;*&nbsp;tempo);&nbsp;//&nbsp;rest<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;playNote(notes[i],&nbsp;beats[i]&nbsp;*&nbsp;tempo);<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;pause&nbsp;between&nbsp;notes<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;delay(tempo&nbsp;/&nbsp;2);&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>No Sound</b></span><br><span class="regularText">Given the size and shape of the piezo element it is easy to miss the right holes on the breadboard. Try double checking its placement. </span></center></div>
 +        <div id="CIRC-thepartsSideSpacer">&nbsp;</div>
 +        <div id="CIRC-nw2"><center><span class="regularText"><b>Can't Think While the Melody is Playing?</b></span><br><span class="regularText">Just pull up the piezo element whilst you think, upload your program then plug it back in.</span></center></div>
 +        <div id="CIRC-thepartsSideSpacer">&nbsp;</div>
 +        <div id="CIRC-nw3"><center><span class="regularText"><b>Tired of Twinkle Twinkle Little Star?</b></span><br><span class="regularText">The code is written so you can easily add your own songs, check out the code below to get started. </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>Playing with the speed:</b> <BR>The timing for each note is calculated based on variables, as such we can tweak the sound of each note or the timing. To change the speed of the melody you need to change only one line. <BR>int tempo = 300; ---> int tempo = (new #) <BR>Change it to a larger number to slow the melody down, or a smaller number to speed it up. <BR>&nbsp; <BR><b>Tuning the notes:</b> <BR>If you are worried about the notes being a little out of tune this can be fixed as well. The notes have been calculated based on a formula in the comment block at the top of the program. But to tune individual notes just adjust their values in the tones[] array up or down until they sound right. (each note is matched by its name in the names[] (array ie. c = 1915 ) <BR>&nbsp; <BR><span class="bigCode">char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' }; <BR>int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };</span> <BR>&nbsp; <BR><b>Composing your own melodies:</b> <BR>The program is pre-set to play 'Twinkle Twinkle Little Star' however the way it is programmed makes changing the song easy. Each song is defined in one int and two arrays, the int length defines the number of notes, the first array notes[] defines each note, and the second beats[] defines how long each note is played. Some Examples: <BR>    Twinkle Twinkle Little Star <BR><span class="bigCode">&nbsp;&nbsp;&nbsp;&nbsp;int length = 15;  <BR>&nbsp;&nbsp;&nbsp;&nbsp;char notes[] = "ccggaagffeeddc ";  <BR>&nbsp;&nbsp;&nbsp;&nbsp;int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1,    <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1, 1, 2, 4 }; <BR>&nbsp;&nbsp;&nbsp;&nbsp;Happy Birthday (first line)   <BR>&nbsp;&nbsp;&nbsp;&nbsp;int length = 13;  <BR>&nbsp;&nbsp;&nbsp;&nbsp;char notes[] = "ccdcfeccdcgf ";  <BR>&nbsp;&nbsp;&nbsp;&nbsp;int beats[] = {1,1,1,1,1,2,1,1,1,1,1,2,4};  <BR>   </span>
 +</span></html>