Wednesday, November 4, 2009
Prototype #5: Piezo film + LED
Description:
We had a mini-breakthrough and got the piezo tab to trigger a response in an LED.
One 'flick' of the tab turns the LED on, and another 'flick' turns it off, and so on.
Input:
Piezo Film Sensor
Output:
LED turning ON and OFF
Setup:
.jpg)
Result:
Code:
We had a mini-breakthrough and got the piezo tab to trigger a response in an LED.
One 'flick' of the tab turns the LED on, and another 'flick' turns it off, and so on.
Input:
Piezo Film Sensor
Output:
LED turning ON and OFF
Setup:
.jpg)
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
Post a Comment