Wednesday, November 4, 2009

Prototype #6: Portable Piezo

Description:
Using a 9V battery we have transformed our prototype into a portable device!!!

With this version we are testing a different kind of piezo tab, and not achieving the same results as the previous prototype. The LED is definitely responding, but does not have a clear ON and OFF output. The code is the same as Prototype #5 to start, and we adjust the THRESHOLD int, but does not seem to help.

Input:
Piezo film, different type than Prototype #5

Output:
LED response, not as clear as Prototype #5 output

Setup:





















Result:



Code:
/* Knock Sensor
* ----------------
*
* Program using a Piezo element as if it was a knock sensor.
*
* We have to basically listen to an analog pin and detect
* if the signal goes over a certain threshold. If the Threshold
* is crossed, and toggles the LED on pin 13.
*
* Modified from one by (cleft) 2005 D. Cuartielles for K3
*/

int ledPin = 13;
int knockSensor = 2;
byte val = 0;
int statePin = LOW;
int THRESHOLD = 100; // if it's too sensitive then change this value

void setup()
{
pinMode(ledPin, OUTPUT);
}

void loop()
{
val = analogRead(knockSensor);
if (val >= THRESHOLD) { // check the piezo
statePin = !statePin; // sets the pin to the opposite state
digitalWrite(ledPin, statePin); // turn on or off the LED
}
}

http://electronics.divinechildhighschool.org/Home/Arduino-Lessons/analog-read-and-a-piezo

Labels: ,


Comments:

Post a Comment





<< Home

This page is powered by Blogger. Isn't yours?