<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Daily Duino &#187; Piezo</title>
	<atom:link href="http://dailyduino.com/archives/category/sensors/piezo/feed" rel="self" type="application/rss+xml" />
	<link>http://dailyduino.com</link>
	<description>mostly daily arduino projects and news</description>
	<lastBuildDate>Fri, 04 Dec 2009 19:46:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>More Drum Kit!</title>
		<link>http://dailyduino.com/archives/226</link>
		<comments>http://dailyduino.com/archives/226#comments</comments>
		<pubDate>Sat, 11 Oct 2008 21:01:34 +0000</pubDate>
		<dc:creator>Morgellon</dc:creator>
				<category><![CDATA[Phreaknic]]></category>
		<category><![CDATA[Piezo]]></category>

		<guid isPermaLink="false">http://dailyduino.com/?p=226</guid>
		<description><![CDATA[So here&#8217; s my little version of the drum kit.  I&#8217;ve just used sample code from arduino.cc, but it&#8217;s more than enough to get the project up and running.  Expect to see it evolve over time, and if you plan on being at Phreaknic you can play with it there! Arduino Knock Sensor Drum Kit [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;">So here&#8217; s my little version of the drum kit.  I&#8217;ve just used sample code from <a title="Arduino Tutorial" href="http://arduino.cc/en/Tutorial/HomePage" target="_blank">arduino.cc</a>, but it&#8217;s more than enough to get the project up and running.  Expect to see it evolve over time, and if you plan on being at Phreaknic you can play with it there!</p>
<p style="text-align: center;">
<object width="400" height="225"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=1940394&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=1940394&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"></embed></object><br /><a href="http://vimeo.com/1940394?pg=embed&amp;sec=1940394">Arduino Knock Sensor Drum Kit v1.01</a> from <a href="http://vimeo.com/morgellon?pg=embed&amp;sec=1940394">Morgellon</a> on <a href="http://vimeo.com?pg=embed&amp;sec=1940394">Vimeo</a>.</p>
<p style="text-align: center;">
<ul style="text-align: center;">
<li style="text-align: center;"><strong>Read how to use a piezo buzzer as a knock sensor</strong></li>
</ul>
<p style="text-align: center;"><a href="http://arduino.cc/en/Tutorial/Knock" target="_blank">http://arduino.cc/en/Tutorial/Knock</a></p>
<ul style="text-align: center;">
<li style="text-align: center;"><strong>Read how to make a piezo buzzer play various tones, instead of just one!</strong></li>
</ul>
<p style="text-align: center;"><a href="http://arduino.cc/en/Tutorial/PlayMelody">http://arduino.cc/en/Tutorial/PlayMelody</a></p>
<p style="text-align: left;"><em>Here&#8217;s the sample code I used, with a few tweaks added:</em></p>
<p style="text-align: left;">int ledPin = 13;      // led connected to control pin 13<br />
int knockSensor = 0;  // the knock sensor will be plugged at analog pin 0<br />
byte val = 0;         // variable to store the value read from the sensor pin<br />
int statePin = LOW;   // variable used to store the last LED status, to toggle the light<br />
int THRESHOLD = 100;  // threshold value to decide when the detected sound is a knock or not</p>
<p>// TONES  ==========================================<br />
// Start by defining the relationship between<br />
//       note, period, &amp;  frequency.<br />
#define  c     3830    // 261 Hz<br />
#define  d     3400    // 294 Hz<br />
#define  e     3038    // 329 Hz<br />
#define  f     2864    // 349 Hz<br />
#define  g     2550    // 392 Hz<br />
#define  a     2272    // 440 Hz<br />
#define  b     2028    // 493 Hz<br />
#define  C     1912    // 523 Hz<br />
// Define a special note, &#8216;R&#8217;, to represent a rest<br />
#define  R     0</p>
<p>// SETUP ============================================<br />
// Set up speaker on a PWM pin (digital 9, 10 or 11)<br />
int speakerOut = 9;<br />
// Do we want debugging on serial out? 1 for yes, 0 for no<br />
int DEBUG = 1;</p>
<p>void setup() {<br />
pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT<br />
pinMode(speakerOut, OUTPUT);<br />
Serial.begin(9600);       // use the serial port<br />
}</p>
<p>// MELODY and TIMING  =======================================<br />
//  melody[] is an array of notes, accompanied by beats[],<br />
//  which sets each note&#8217;s relative length (higher #, longer note)<br />
int melody[] = {  C,  b,  g,  C,  b,   e,   C,  c  };<br />
int beats[]  = { 16, 16, 16,  8,  8,  16,  16, 16  };<br />
int MAX_COUNT = sizeof(melody) / 2; // Melody length, for looping.</p>
<p>// Set overall tempo<br />
long tempo = 10000;<br />
// Set length of pause between notes<br />
int pause = 1000;<br />
// Loop variable to increase Rest length<br />
int rest_count = 100; //&lt;-BLETCHEROUS HACK; See NOTES</p>
<p>// Initialize core variables<br />
int tone = 0;<br />
int beat = 0;<br />
long duration  = 0;</p>
<p>// PLAY TONE  ==============================================<br />
// Pulse the speaker to play a tone for a particular duration<br />
void playTone() {<br />
long elapsed_time = 0;<br />
if (tone &gt; 0) { // if this isn&#8217;t a Rest beat, while the tone has<br />
//  played less long than &#8216;duration&#8217;, pulse speaker HIGH and LOW<br />
while (elapsed_time &lt; duration) {</p>
<p>digitalWrite(speakerOut,HIGH);<br />
delayMicroseconds(tone / 2);</p>
<p>// DOWN<br />
digitalWrite(speakerOut, LOW);<br />
delayMicroseconds(tone / 2);</p>
<p>// Keep track of how long we pulsed<br />
elapsed_time += (tone);<br />
}<br />
}<br />
else { // Rest beat; loop times delay<br />
for (int j = 0; j &lt; rest_count; j++) { // See NOTE on rest_count<br />
delayMicroseconds(duration);<br />
}<br />
}<br />
}</p>
<p>void loop() {<br />
val = analogRead(knockSensor);    // read the sensor and store it in the variable &#8220;val&#8221;<br />
if (val &gt;= THRESHOLD) {<br />
// statePin = !statePin;           // toggle the status of the ledPin (this trick doesn&#8217;t use time cycles)<br />
digitalWrite(ledPin, HIGH); // turn the led on or off<br />
Serial.println(&#8220;Knock!&#8221;);       // send the string &#8220;Knock!&#8221; back to the computer, followed by newline<br />
for (int i=0; i&lt;MAX_COUNT; i++) {<br />
tone = melody[i];<br />
beat = beats[i];</p>
<p>duration = beat * tempo; // Set up timing</p>
<p>playTone();<br />
// A pause between notes&#8230;<br />
delayMicroseconds(pause);<br />
}<br />
delay(10);                      // short delay to avoid overloading the serial port<br />
}<br />
digitalWrite(ledPin, LOW);<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://dailyduino.com/archives/226/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Drum Kit!</title>
		<link>http://dailyduino.com/archives/211</link>
		<comments>http://dailyduino.com/archives/211#comments</comments>
		<pubDate>Wed, 08 Oct 2008 04:48:38 +0000</pubDate>
		<dc:creator>droops</dc:creator>
				<category><![CDATA[Phreaknic]]></category>
		<category><![CDATA[Piezo]]></category>
		<category><![CDATA[drum]]></category>
		<category><![CDATA[knock]]></category>
		<category><![CDATA[led]]></category>

		<guid isPermaLink="false">http://dailyduino.com/?p=211</guid>
		<description><![CDATA[I totally ripped this off from Morgellon, but it sounded fun and I wanted to try it. He is going to build his own version of this that I am sure is going to be cooler.  I had to call him and ask some questions as he is most definitely the hardware end of our [...]]]></description>
			<content:encoded><![CDATA[<p>I totally ripped this off from Morgellon, but it sounded fun and I wanted to try it. He is going to build his own version of this that I am sure is going to be cooler.  I had to call him and ask some questions as he is most definitely the hardware end of our crazy love triangle. I want to dump the data into processing and have it animate the drums being hit, but that is for another day.</p>
<p style="text-align: center;">
<object width="400" height="300"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=1908597&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=1908597&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"></embed></object><br /><a href="http://vimeo.com/1908597?pg=embed&amp;sec=1908597">Arduino Knock Sensor Drum Kit v1</a> from <a href="http://vimeo.com/user783016?pg=embed&amp;sec=1908597">droops</a> on <a href="http://vimeo.com?pg=embed&amp;sec=1908597">Vimeo</a>.
</p>
<p>When a drum is struck, a knock sensor (backwards peizo) talks to the arduino and activates an led ot change the color of the drum (blue), after a delay the blue led goes out and the drum becomes orange again.  I used a pullup resistor between the pins of the knock sensor, but i didnt get any different results with different values, so its probably dependent on the peizo that you use.</p>

<a href='http://dailyduino.com/archives/211/dsc_0331' title='dsc_0331'><img width="150" height="150" src="http://dailyduino.com/wp-content/uploads/2008/10/dsc_0331-150x150.jpg" class="attachment-thumbnail" alt="dsc_0331" title="dsc_0331" /></a>
<a href='http://dailyduino.com/archives/211/dsc_0332' title='dsc_0332'><img width="150" height="150" src="http://dailyduino.com/wp-content/uploads/2008/10/dsc_0332-150x150.jpg" class="attachment-thumbnail" alt="dsc_0332" title="dsc_0332" /></a>
<a href='http://dailyduino.com/archives/211/dsc_0333' title='dsc_0333'><img width="150" height="150" src="http://dailyduino.com/wp-content/uploads/2008/10/dsc_0333-150x150.jpg" class="attachment-thumbnail" alt="dsc_0333" title="dsc_0333" /></a>

<pre style="text-align: left;">/*
droop's drum kit

dailyduino.com

droops - gmail

thanks for the idea josh!!
*/

int knockPin = 3; //pin for incoming knock sensor
int knockVal; //value from knock sensor
int knockLedPin = 10; //bue led
int normalLedPin = 4;  //orange led
int lightBlue = 2000; //counter for keeping blue light on
int limit = 1000; //how sensitive the knock sensor is, lower = higher sensitivity based on piezo and pull down resistor
int blueTime = 2000; //how long the blue led stays on

void setup(){
  pinMode(knockLedPin, OUTPUT);
  pinMode(normalLedPin, OUTPUT);
  pinMode(knockPin, INPUT);
  Serial.begin(9600);
  digitalWrite(knockLedPin, LOW);
  digitalWrite(normalLedPin, HIGH);
}

void loop(){

  knockVal = analogRead(knockPin); //read the knock sensor

  if (knockVal &lt; limit){
    lightBlue = 0; //drop the value to activate the led
    Serial.println(knockVal);  //dump to serial for debugging
  }

  //this keeps the blue light on after a knock is registered
  if(lightBlue &lt; blueTime){
    digitalWrite(normalLedPin, LOW);
    digitalWrite(knockLedPin, HIGH);
    lightBlue++;
  } else {
    digitalWrite(knockLedPin, LOW);
    digitalWrite(normalLedPin, HIGH);
  }  

}</pre>
]]></content:encoded>
			<wfw:commentRss>http://dailyduino.com/archives/211/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

